The robotics simulator for sr-robot3 used by Student Robotics, powered by Webots. This simulator was originally developed by the Southampton Robotics Outreach society for the Smallpeice competition and has been adapted for use by Student Robotics.
The simulator is a useful development tool that allows you to become familiar with our API and test out robotics concepts even if you haven't finished building your robot yet.
The simulator is built around the Webots platform, which runs the simulation. You control the virtual robot using the sr-robot3 API, just like on the physical robots.
In order to use the simulator a few set-up steps need to be done. First you need to install Python 3.9+ and Webots R2025a.
To install Python, you can download the latest version from the Python website. If you have
already installed Python from a package manager, such as homebrew on
MacOS, apt on Ubuntu, or the Windows store on Windows, you can skip this
step.
To install Webots, you can download the latest version from the Webots website. Use the
default settings when installing Webots.
Once you have installed these, for the rest of this guide you will want to start from the folder have you extracted this simulator into.
The contents of the folder should look like this:
simulator folder contains our code to support
running your code in the simulator.zone_0 folder is where you will write your code,
and it must contain a file called robot.py.setup.py and run_simulator.py files
are used to set up the environment and run the simulator
respectively.readme.html file contains a single page guide to
using the simulator, similar to this one.zone_0
folder from the old installation to the new one.
Now that you have downloaded and extracted the simulator, you need to set up the environment to run the simulator. Since the simulator uses the sr-robot3 library, there are a series of python packages that need to be installed and Webots needs to be configured to use the correct version of Python. We have provided a script that will set up this environment for you.
Starting in the folder you extracted the simulator into, run the script called `setup.py and it will set up the environment for you. A terminal window will open and you will see the output of the script, if there are any errors displayed check the Troubleshooting section for help.
This will create a contained python installation with the required
libraries in a venv folder, this is called a virtual
environment. This also configures the Webots settings to use the correct
version of Python.
Before you can start using the simulator, you need to have followed the steps in the Setting up the Simulator section.
To open the arena, you need to start in the folder you extracted the
simulator during setup and run the run_simulator.py script.
This will open Webots with the arena loaded and ready to run your
code.
After opening the arena, you shoudl see a window similar to the one below. This is the Webots interface, which has 5 key areas:
The camera overlay shows the images from the robot's camera. This
only updates when robot.camera.see() is called in your
code.
This image is the raw image that the robot sees, and is not processed in any way. To see the processed image, you have to save the images to a file just like on the physical robot.
If the camera overlay is closed and you want to get it back, you can use the Reopening the Camera Overlay instructions.
In the simulator, time advances only at the pace that the simulator is run. The relation between this time and the real passage of time depends on a couple of factors: the speed the simulation is configured to run at and the ability of the computer running the simulation to process it fast enough.
You can configure and observe the speed the simulator is running at from the toolbar in webots:
From left to right, this has the following controls:
The console at the bottom of the screen shows all the logs produced by Webots which includes logs from your code.
Where your code logs are are printed they are prefixed with the zone number and simulation time. Lines are displayed in red if they were printed to standard error instead of standard output.
There are also some Webots error messages that you may see, such as:
Now that you have the simulator set up, you can start developing your code.
In the folder where you extracted the simulator, you should have a
folder called zone_0. In this folder, you should have a
file called robot.py. This is the code that will be run in
the simulator.
The API for the simulator is the same as the API for the physical robot, so you can use largely the same code in both environments. Check out the simulated robot section for information on where the sensors and motors are located on the robot.
As well as the logs being displayed in the console, they are also
saved to a file. This file is saved in the zone_0 folder
and has a name in the format
log-zone-<zone>-<date>.log. The date is when
that simulation was run.
To allow the simulation to be run at various speeds,
time.sleep must not be used. Instead,
robot.sleep should be used. This allows the simulator to
simulate the time your robot would be sleeping for.
While the simulator does simulate the time taken for each call to the
API, it does not simulate the time taken for general computation. This
means that if you have a loop that does not contain a
robot.sleep, the simulator will freeze as it waits for the
loop to complete. If you find the timer is not advancing, or is very
slow, you likely have a loop without a sleep. Generally, it is best
practice to have a robot.sleep in every loop, even if it is
a very short time.
The simulator contains a pre-built robot model that can be controlled using the sr-robot3 library. The robot is a differential drive robot with a camera and a variety of sensors.
The robot has a number of boards attached to it that can be interacted with using the sr-robot3 library. These boards include:
PWR)MOT)
SERVO)
Arduino1)
Camera)LED)All sensors are attached to the Arduino board and can be accessed using the Arduino API.
| Sensor | Connected Pin | Description |
|---|---|---|
| Front Ultrasound Sensor | Trigger: 2 Echo: 3 |
Measures distance from the front of the robot |
| Left Ultrasound Sensor | Trigger: 4 Echo: 5 |
Measures distance from the left of the robot |
| Right Ultrasound Sensor | Trigger: 6 Echo: 7 |
Measures distance from the right of the robot |
| Back Ultrasound Sensor | Trigger: 8 Echo: 9 |
Measures distance from the back of the robot |
| Front Left Microswitch | 10 | Detects if the front left of the robot has bumped into something |
| Front Right Microswitch | 11 | Detects if the front right of the robot has bumped into something |
| Rear Left Microswitch | 12 | Detects if the rear left of the robot has bumped into something |
| Rear Right Microswitch | 13 | Detects if the rear right of the robot has bumped into something |
| Left Reflectance Sensor | A0 | Measures the reflectance of the surface under the left side of the robot |
| Center Reflectance Sensor | A1 | Measures the reflectance of the surface under the center of the robot |
| Right Reflectance Sensor | A2 | Measures the reflectance of the surface under the right side of the robot |
These are the simulated version of ultrasound sensors.
They return the distance to the nearest object in front of the sensor in a narrow cone of view. Objects beyond 4 meters are not detected.
The robot has four ultrasound sensors attached to it, one on each side of the robot. They can all be accessed using the Arduino API's ultrasound interface.
These appear as a blue board with two silver cylinders on the robot model. The returned distance is measured from the blue board in the direction of the silver cylinders.
Across the bottom of the robot, there are three reflectance sensors that can detect differences in the colour of the surface under the robot. This is achieved by returning the relative red content of the surface directly below the sensor.
The measured values can then be read using the Analog Input interface. This is returned as a voltage between 0 and 5 volts, with lower values indicating a darker surface.
These appear as blue rectangles on the robot model.
On the front and back of the robot, there are microswitches that can detect if the robot has bumped into something. These appear as red cuboids on the robot model.
The attached pin will read True if the cuboid has
intersected with any other object in the simulation.
The three rectangles on the back of the robot can have their colours
set using the robot.leds interface.
There are a few common issues that you may encounter when setting up the simulator. You may receive a warning about your computer's GPU not being good enough, which can be ignored.
If you see a message saying that Python cannot be found that looks similar to the image below, you need to rerun the setup script and check if there are any errors displayed.
As well as the guidance above, there are a few other points to note when using the simulator. These can help you to understand what is happening and how to get the most out of the simulator.
If the arena has multiple starting zones, you can run multiple robots in the simulator. To test how your robot behaves in each starting zone of the arena, you can copy your robot's code to run in each corner.
In the folder where you extracted the simulator, alongside the
zone_0 folder, you may have other
zone_<number> folders. Such as zone_1,
zone_2, etc. Each of these folders can contain a
robot.py file that will be run in the corresponding
starting zone of the arena.
The default settings work for most users however if you are using a less powerful computer or one without a dedicated graphics card (as is the case on many laptops), you may wish to adjust the graphics settings to enable the simulation to run faster.
If you find that the simulation runs very slowly we suggest disabling Anti-Aliasing, Ambient Occlusion and Shadows. These should not affect the behaviour of the simulation, only the rendered visuals.
To do this, open Webots and go to the menu Tools → Preferences, then select the OpenGL tab. On this tab, set Ambient Occlusion to "Disabled" and check the boxes next to "Disable shadows" and "Disable anti-aliasing".
On macOS, Preferences is under the Webots menu instead of Tools.
To reopen the camera overlay if it has been closed, you can follow these steps:
This menu can be seen in the image below.
Once visible, the camera overlay can be resized by dragging the bottom right corner of the overlay. The overlay can also be moved around the screen by clicking and dragging on the window.
In addition to the camera overlay, Webots also supports displaying some of the geometric information that is used to simulate the robot's sensors. This can be useful for debugging and understanding how the robot is interacting with the world.
To view the field of view of the camera, you can enable the option by going to View → Optional Rendering → Show Camera Frustums. This will show the area that the camera can see in the 3D world.
To view the paths of the ultrasound sensors, you can enable the option by going to View → Optional Rendering → Show DistanceSensor Rays.
This menu can be seen in the image below.
Select the option again to disable the display of the sensor paths.