Example 7 cmpc and gmpc

Simulation

not found

Real Life

not found

What does the code do?

This code sets the robot position to 0 (using cmpc) then goes forward until robot position is 5000 (using gmpc)

Functions Used

cmpc( clear_motor_position_counter)

gmpc ( get_motor_position_counter)

mav( motor port, velocity)

Function Implementation

 1#!/usr/bin/python3
 2import os, sys
 3sys.path.append("/usr/lib")
 4from kipr import*
 5
 6def main():
 7   cmpc(0)
 8   while gmpc(0) < 5000:
 9      mav(0, 750)
10      mav(3, 750)
11
12if __name__ == "__main__":
13   main()

Rookie Tip

By using gmpc, you can know what position your motor needs to be at, so you can further improve your code.