Home » DEVELOPERS » Tutorials » Move the robot

 Developers>Tutoriels>Move the robot

 

 In this tutorial you will learn to move the MRPi1 robot.
  • forward
  • back
  • turn left and right

Robot base

The MRPi1 robot is a differential wheeled robot based on two separately driven wheels and one free turning wheel.

image2-en

Forward

  • Start the python program :
$ python

img1_led

  • import the mrpi1_lib library :
$ from mrpi1_lib import *
  • move the robot :
>>> forward(20)

This function allows to move the robot with a speed of 20 %. Speed is a value between 0 and 100%. The maximum speed is 100%.

  • Stop the robot :
>>> stop()

Forward & back

Then leave python interpreter to create a script :

>>> exit() 
  • You can create a python script with the editor of your choice, for me I use Notepad++ and then I transfer the script to the Raspberry Pi via the FileZilla software.

 

  • Exemple :

Name : move1.py

#!/usr/bin/python
from mrpi1_lib import *
import time


forward(50)
time.sleep(2)
stop()
time.sleep(1)
back(50)
time.sleep(2)
stop()
    Then, you must make it executable with the command :
$ chmod +x move1.py
  • Run program :
$ ./move1.py

The robot must :

  1. Start of program
  2. Forward for 2 seconds
  3.  Stop for 1 second
  4.  Back for 2 seconds
  5. Stop
  6. End program

Turn

  • Exemple :

Name : move2.py

#!/usr/bin/python
from mrpi1_lib import *
import time


turnRight(30)
time.sleep(2)
stop()
time.sleep(0.5)
turnLeft(20)
time.sleep(1)
stop()
  • Run program :
$ ./move2.py

The robot must :

  1. Start of program
  2. Turn right for 2 seconds
  3.  Stop for 0.5 second
  4. Turn left for 1 second
  5. Stop
  6. End program