In [ ]:
import packages.initialization
import pioneer3dx as p3dx
p3dx.init()
The code is structured in three parts:
In [ ]:
def forward():
# copy and paste your code here
...
In [ ]:
def turn():
# copy and paste your code here
...
In [ ]:
print('Pose of the robot at the start')
p3dx.pose()
for _ in range(4):
forward()
turn()
print('Pose of the robot at the end')
p3dx.pose()
In [ ]:
def forward():
target = 2.0 # target distance
r = 0.1953 / 2 # wheel radius
initialEncoder = p3dx.rightEncoder
distance = 0
while distance < target:
p3dx.move(2.5,2.5)
angle = p3dx.rightEncoder - initialEncoder
distance = angle * r
p3dx.move(0,0)
In [ ]:
def turn():
target = 3.1416/2 # target angle in radians
r = 0.1953 / 2 # wheel radius
L = 0.33 # axis length
initialEncoder = p3dx.leftEncoder
robotAngle = 0
while robotAngle < target:
p3dx.move(1.0,-1.0)
wheelAngle = p3dx.leftEncoder - initialEncoder
robotAngle = 2 * r * wheelAngle / L
p3dx.move(0,0)
In [ ]:
print('Pose of the robot at the start')
p3dx.pose()
for _ in range(4):
forward()
turn()
print('Pose of the robot at the end')
p3dx.pose()
The trajectory is:
In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
x, y = p3dx.trajectory()
plt.plot(x,y)
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) |