Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (47 sloc) 2.58 KB
title weight
Python API

Programming your robot is done in Python, specifically version {{% python_patch_version %}}. You can learn more about Python from their [docs]({{% python_minor_version %}}/), and our whirlwind tour.


The following two lines are required to complete initialisation of the kit:

from robot import Robot

r = Robot()

Once this has been done, this Robot object can be used to control the robot's functions.

The remainder of the tutorials pages will assume your Robot object is defined as r.

Running your code

Your code needs to be put on a USB drive in a file called On insertion into the robot, this file will be executed. The file is directly executed off your USB drive, with your drive as the working directory.

To stop your code running, you can just remove the USB drive. This will also stop the motors and any other peripherals connected to the kit.

You can then reinsert the USB drive into the robot and it will run your again (from the start). This allows you to make changes and test them quickly.

{{% notice info %}} If this file is missing or incorrectly named, your robot won't do anything. No log file will be created. {{% /notice %}}

Start Button

After the robot has finished starting up, it will wait for the Start Button on the power board to be pressed before continuing with your code, so that you can control when it starts moving. There is a green LED next to the start button which flashes when the robot is finished setting up and the start button can be pressed.

Running Code before pressing the start button

If you want to do things before the start button press, such as setting up servos or motors, you can pass wait_for_start_button. You will then need to wait for the start button manually.

r = Robot(wait_for_start_button=False)

# Do your setup here



A log file is saved on the USB drive so you can see what your robot did, what it didn't do, and any errors it raised. The file is saved to log.txt in the top-level directory of the USB drive.

{{% notice warning %}} The previous log file is deleted at the start of each run, so copy it elsewhere if you need to keep hold of it! {{% /notice %}}

Serial number

All kit boards have a serial number, unique to that specific board, which can be read using the serial property:

>>> 'P1'
>>> 'S1'
>>> 'M1'
You can’t perform that action at this time.