Example 9 Move And Rotate ========================== .. image:: ../tutorial/code8.gif :alt: not found :align: center What does this code do? ----------------------- In this code the robot moves forward until abs < distance, then rotates right by 180 degrees and finally rotates left by 360 degrees. Functions Used -------------- cmpc( clear_motor_postition_counter ) abs(absolute) gmpc(get_motor_position_counter) mav(motor port, velocity) msleep( distance in ms) Function Implementation *********************** .. code-block:: python :linenos: #!/usr/bin/python3 import os, sys sys.path.append("/usr/lib") from kipr import* def drive(distance, speed): cmpc(0) while abs(gmpc(0)) < distance: mav(0, speed) mav(3, speed) mav(0, 0) mav(3, 0) msleep(20) def turn_right(distance, speed): cmpc(3) while gmpc(3) < distance: mav(0, -speed) mav(0, speed) mav(0, 0) mav(0, 0) msleep(20) def turn_left(distance, speed): cmpc(0) while gmpc(0) < distance: mav(0, -speed) mav(0, speed) mav(0, 0) mav(0, 0) msleep(20) def main(): drive(1000, 500) turn_right(2300, 750) turn_left(4300, 750) if __name__ == "__main__": main()