Example 8 using abs =================== Simulation ----------- .. image:: ../tutorial/code8.gif :alt: not found :align: center Real Life --------- .. image:: ../tutorial/code8real.gif :alt: not found :align: center What does the code do? ---------------------- In this code the robot moves forward until abs < distance, then drives back to original position. Functions Used -------------- cmpc( clear_motor_position_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 main(): drive(1000, 500) drive(1000, -300) if __name__ == "__main__": main() Rookie Tips ----------- You can make multiple define(func) in a code inorder to make your code more organised!