Motion Functions

In this notebook you will learn how use Python functions for moving the robot in your programs.

First, the initialization step needs to be executed.


In [ ]:
# click on this cell and press Shift+Enter
import packages.initialization
import pioneer3dx as p3dx
p3dx.init()

Functions

There are three functions for controlling the motion of the robot:

  • p3dx.move(ls,rs)
  • p3dx.stop()
  • p3dx.sleep(t)

The main motion function is:

p3dx.move(ls, rs)

where

   ls : left wheel speed (rad/s)
   rs : right wheel speed (rad/s)

The function sets the speeds of the wheels, and the robot moves until blocked by an obstacle, or a new speed is set, or it is stopped with the function:

p3dx.stop()

For controlling the amount of time that the robot moves, there is the function:

p3dx.sleep(t)

where t is the number of seconds. During that pause, the program sleeps but the robot keeps moving with the last speed set.

Example

Use the code below for moving the robot. Feel free to explore with different speed and time values.


In [ ]:
# Move forward
p3dx.move(2.5,2.5)
p3dx.sleep(1)
p3dx.stop()

In [ ]:
# Move backward
p3dx.move(-2.5,-2.5)
p3dx.sleep(1)
p3dx.stop()

In [ ]:
# Turn left
p3dx.move(-2.5,2.5)
p3dx.sleep(1)
p3dx.stop()

In [ ]:
# Turn Right
p3dx.move(2.5,-2.5)
p3dx.sleep(1)
p3dx.stop()

You can also copy and paste the functions several times with different values for a composition of motions:


In [ ]:
# Your own wonderful motion sequence

For a better control of the motion, we are going to introduce the first sensors in our mobile robot: the encoders.


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)