Programming
Programming your robot is done in Python,
specifically version 3.11
. You can learn more about Python from their
docs.
Each board has an API (Application Programming Interface) which allows its various functionality to be controlled.
Setup
The kit is automatically initialised when importing the sbot
module. The code snipped below will initialise the kit and import all submodules.
from sbot import *
You should only run this once at the start of your file: python will throw an error if sbot
is imported multiple times.
Importing sbot
will pause execution of the code until the start button is pressed.
Once this is done, the submodules can be used to access and control the robot's hardware. The other pages in these docs cover each module in detail.
Running your code
Your code needs to be put on a USB drive in a file called robot.py
. When connected to the robot, this file will be executed. The file is directly executed off your USB drive, with your drive as the working directory.
If this file is missing or incorrectly named, your robot won't do anything. No log file will be created.
To stop your code running, we recommend using the stop button on the web interface. This will also stop the motors and any other peripherals connected to the kit.
In a pinch, you can also just remove the USB drive but you will likely lose the end of your log file as it won't be able to write to the USB drive.
You can then reinsert the USB drive into the robot, and it will run your robot.py
again (from the start).
Logs
A log file is saved to your USB 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.
The latest log is always called log.txt. If the code is re-run the previous log will be renamed with an increasing number suffix.
Included Libraries
Python comes with plenty of built-in libraries to use. We install some extra ones which may be of use:
If you would like an extra library installed, go and ask a volunteer to see if we can help.