Exercise: Move the robot forward for a distance.

You are going to program the robot for moving forward from the initial position at the start of the simulation, in the center of the room.

The robot should stop after traveling a distance equal to the size of the tile, which is 2 m.

According to the specifications, the diameter of the wheels of the Pioneer 3DX robot is 195.3 mm.

1. Starting position

For a better visual understanding of the task, it is recommended that the robot starts at the center of the room.

You can easily relocate the robot there by simply restarting the simulation.

2. Initialization

After restarting the simulation, the robot needs to be initialized.


In [ ]:
import packages.initialization
import pioneer3dx as p3dx
p3dx.init()

3. Motion code

In the following program template, you must fill the gaps with the appropriate code.

The idea is to compute the turned angle of one of the encoders (no matter which one) as the difference between the current and initial values, then compute the traveled distance. The robot will move as long as this distance is lower than the target distance, then it will stop.


In [ ]:
target = ...      # target distance
r = ...           # wheel radius
initialEncoder = ...
distance = 0
while distance < target:
    p3dx.move(2.5,2.5)
    angle = ...
    distance = ...
p3dx.move(0,0)

Try-a-Bot: an open source guide for robot programming

Developed by:

Sponsored by:

[![IEEE Robotics and Automation Society](../img/logo/ras.png "IEEE Robotics and Automation Society")](http://www.ieee-ras.org) [![Cyberbotics](../img/logo/cyberbotics.png "Cyberbotics")](http://www.cyberbotics.com) [![The Construct](../img/logo/theconstruct.png "The Construct")](http://www.theconstructsim.com)

Follow us:

[![Facebook](../img/logo/facebook.png "Facebook")](https://www.facebook.com/RobotProgrammingNetwork) [![YouTube](../img/logo/youtube.png "YouTube")](https://www.youtube.com/user/robotprogrammingnet)