3.1. Driving Around

Driving the GoPiGo3 around is only a matter of choosing the right methods from the EasyGoPiGo3 class. In all of our examples, the easygopigo3 is required and needs to be imported and a EasyGoPiGo3 object can be instantiated this way:

from easygopigo3 import EasyGoPiGo3 # importing the EasyGoPiGo3 class
gpg = EasyGoPiGo3() # instantiating a EasyGoPiGo3 object

Instantiating EasyGoPiGo3 object can fail if the GoPiGo3 is not present or there’s a firmware mismatch. Check the __init__ constructor of this class to see what exceptions can be raised.

3.1.1. Forward, R/L, Backward

The most basic commands don’t offer control over how much distance the GoPiGo3 travels. They only get called once and then it’s the responsability of the user to stop the GoPiGo3 from moving, regularly by using the stop() command.

We first need to import the easygopigo3 and the time modules and instantiate a EasyGoPiGo3 object.

# import the time library for the sleep function
import time
from easygopigo3 import EasyGoPiGo3

# create an instance of the GoPiGo3 class.
# gpg will be the GoPiGo3 object.
gpg = EasyGoPiGo3()

Next, move the robot forward for exactly one second and right after that continue to the next block of code.

print("Move the motors forward freely for 1 second.")

Stop the motors for a second.

print("Stop the motors for 1 second.")

And then move forward again, but this time for 50 centimeters and once the moving function ends, wait a second until the next block of code gets executed. Notice that drive_cm() is a blocking function in this case.

print("Drive the motors 50 cm and then stop.")
gpg.drive_cm(50, True)

Then right for a second.

print("Turn right 1 second.")

And likewise to the left.

print("Turn left 1 second.")

Finally, stop the robot.


If you want to run this by yourself, here’s the script on github.


3.1.2. Describing a Square

To make the GoPiGo3 describe a square by moving itself, you need to run the following script. To do this, drive_cm() and turn_degrees() methods are required. A square with the side length of 30cm is drawn. The square is drawn clockwise.

from easygopigo3 import EasyGoPiGo3

gpg = EasyGoPiGo3()
length = 30

for i in range(4):
  gpg.drive_cm(length) # drive forward for length cm
  gpg.turn_degrees(90) # rotate 90 degrees to the right

3.1.3. Making Circular Moves

Driving straight in one direction is one thing, but rotating around a center axis at a specific radius is something entirely different. In this example, the GoPiGo3 draws half a circle and then returns on the same track by spinning itself on the spot.

The radius of the circle is set at 50 centimeters and the robot will move for half of the circle (aka 180 degrees).

from easygopigo3 import EasyGoPiGo3

gpg = EasyGoPiGo3()

gpg.orbit(180, 50) # draw half a circle
gpg.turn_degrees(180) # rotate the GoPiGo3 around
gpg.orbit(-180, 50) # return on the initial path
gpg.turn_degrees(180) # and put it in the initial position

3.1.4. Drawing an 8 Shape

Let’s say we want to draw an 8 shape with the GoPiGo3 and at the end have the GoPiGo3 reach the same position it initially left from.

To do this, we have to use orbit() and drive_cm() methods.

from easygopigo3 import EasyGoPiGo3

gpg = EasyGoPiGo3()
radius = 30

gpg.orbit(-270, radius) # to rotate to the left
gpg.drive_cm(radius * 2) # move forward
gpg.orbit(270, radius) # to rotate to the right
gpg.drive_cm(radius * 2) # move forward

3.1.5. Going Forward at Increasing Speed

In this example, we make the GoPiGo3 go forward at an ever increasing speed. We start of with a speed of 50 and end up going at 300. forward(), set_speed() and stop() methods are used.


This example will not work with versions released before November 2018. Do an update before running it.

from easygopigo3 import EasyGoPiGo3
from time import time, sleep

gpg = EasyGoPiGo3()

# setting speed to lowest value and
# calculating the step increase in speed
current_speed = 50
end_speed = 400
step = (end_speed - current_speed) / 20

# start moving the robot at an ever increasing speed
while current_speed <= end_speed:
  current_speed += step

# and then stop it

3.1.6. Other Examples

There are also other examples you can look at, namely the projects in the GoPiGo3 repository. Also, to see all methods for moving around the GoPiGo3, check the GoPiGo3 movement API.