Exercise: Turn the robot for an angle.

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

The robot should stop after turning 90 degrees.

According to the specifications, the diameter of the wheels of the Pioneer 3DX robot is 195.3 mm and the distance between the wheels is 330 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 angle in radians
r = ...           # wheel radius
L = ...           # axis length
initialEncoder = ...
robotAngle = 0
while robotAngle < target:
    p3dx.move(1.0,-1.0)
    wheelAngle = ...
    robotAngle = ...
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)