Bundle and save to celebrate summer! Shop Now

View All Materials

Lesson:

Installing the Python SDK

Python

Experience Level

Intermediate

Duration

15-30 minutes

Group Size

Individual

Compatible Robots

Advanced Create 2 Robot

Root rt0 Coding Robot

Root rt1 Coding Robot

Details

Follow this guide to install the iRobot Education Python SDK. Written & submitted by Kathryn Wujciak at Tufts University

Downloads & Resources

iRobot Education Python SDK (Beta)

Configuration

This SDK is designed to communicate with robots via Bluetooth® Low Energy on Windows®, macOS®, and Linux® systems.

This tutorial is done on macOS® primarily with the Create® 3 robot. Click here to learn more about configuration settings.

Main Idea

Are you looking to advance your skills as a roboticist? Maybe you’ve played around with the Python Playground and you’re ready for the next step. The Python SDK is the perfect place to further your experience with the Create® 3 and Root® robots. There is a rich collection of examples to play around with straight from your terminal! Once you’re familiar with those, try writing your own scripts! The Python SDK puts the power in the user. Take advantage of the sensors and actuators in order to learn and apply your Python skills using the Create® 3 and Root® robots.

This SDK uses async execution and is compatible with Python® 3.9 or greater. MicroPython may work, but has not been rigorously tested.

Installation

Option 1: Using Pip

1. Open your computer's terminal interface.

2. Copy & paste the below command

pip3 install irobot_edu_sdk

*Note: If you have trouble installing using pip, you can install from source as seen below in Part B. This may be due to an outdated Python® version (<3.9) installed on your machine.

Option 2: From Source

1. Open terminal, and clone the SDK repo.

git clone https://github.com/iRobotEducation/irobot-edu-python-sdk.git

2. Next, run the install below.

pip3 install



Run Examples

Installed Examples

Now that we’ve installed the SDK, we can use some of the examples. There are many examples that can be run with the Python SDK.

*Note: The available examples mirror those included in the Python Playground.

Check out all the examples for the Create® 3 robot here.

Access all the examples for the Root® robot here.

In order to run examples from the terminal, we need to make sure we enter our SDK directory in terminal. To change directory, we use the command cd (“change directory”). If we want to see all items in that directory, we write ls. See the screenshot below.

As you can see, we’re able to enter various directories and see what’s inside. Each directory is a subdirectory of the previous one in the screenshot above. First we enter irobot-edu-python-sdk, then we see that it contains an examples folder. We can now change directories, enter the examples folder, and see what’s inside. Lastly, since we’re using the Create® 3 robot, we’ll enter the create3_robots directory within the examples folder. This process helps us understand where our files are and how to access them.

However, we don’t need to change directories one by one to get to the examples. From the home directory, we can use “/” to go straight to our desired destination. If you are using a Root® robot, change directories to the Root® examples. If you’re using a Create® 3 robot, use those examples. See below:

Root®:

cd irobot-edu-python-sdk/examples/root_robots/


Create® 3:

cd irobot-edu-python-sdk/examples/create3_robots


This tutorial will use the Create® 3 robot, but can be replicated with the Root® examples. The command should look like this in terminal:

Again, to see the available examples in the directory, we can write ls.

Now let’s choose which example we want to run. Let’s start with ir_proximity_print.py

Since we’re already in the correct directory, we can simply run:

python3 ir_proximity_print.py


Terminal will look like:

If you want to edit a file, simply run the command below to open it in terminal:

nano [filename].py


The command looks like this:

Terminal will open the file:
I added a sample comment at the top. To exit, press ctrl+X. It will ask you if you want to save. Press ‘Y.’
After you press ‘Y,’ press ‘enter’ to complete the saving process.


Write Your Own Scripts

If you want to run your own script, the process is similar. Since we’re in the correct directory, we can use the command nano to either open and edit an existing file, or create a new one. We want to create a new one. Since we want it to be a Python file, make sure to use the .py extension.

nano [filename].py


Say we want to name our example sdk_example.py. It would look like:

nano sdk_example.py


In terminal:

The file will be blank. Write your script or copy and paste it here.

For example, say I want the robot to beep if an object is too close using the central IR sensor. I may write the example below:

Exit and save the files as noted above. Now when we write ls, we can see that the new file is in this directory along with the other examples!

Simply run it the same way as the example above.

*Note: make sure you’re still in the example directory.

python3 sdk_example.py


The output will look like:

Now you have written your own working example!

*Note: the robot = Create3(Bluetooth()) line tells your computer to connect to the first Create® 3 robot it sees. If you would like to specify a particular robot, insert your namespace as seen below:


Going Further

Now that you’ve played around with one or more examples, try writing your own Python script! Use the elements from the examples to create your own project. The possibilities are endless! Take what you’ve learned and apply your Python knowledge to learn even more about robotics. Here are some project ideas to try:


To learn more about the communication backends, click here.