Developing your code
On first run, the robot will execute an example program for convenience. On first run, this will be copied to the directory
competition-simulator-<version> is stored in:
. ├── competition-simulator-<version> │ ├── ... │ └─ worlds │ └── Arena.wbt └── robot.py
Your code should be developed in
Unless otherwise stated, the simulator’s API is the same as the real SR API described in the programming docs.
To assist with converting your existing code from Python 2 to Python 3, you can use
There are two possible classes you can use to control your robot. You are
encouraged to use the newer
rather than the older
Robot class. This avoids unpredictable behaviour which
can result from simulator time not passing at the same rate as real time.
Your robot has two motor boards attached, each with two motors. Board
0 has the left wheel in port
m0, and the right wheel in
1 has the gripper lift motor in
m0, and the finger motors in
The motor boards do not have part codes, and so need to be indexed using
1. The motor boards will always be in this order.
Your robot has five microswitches and six distance sensors, attached to the digital and analogue pins respectively. These are all attached to a single ruggeduino.
Because these sensors are pre-attached to the ruggeduino, you do not need to set its
The microswitches are attached to digital pins 2-6:
|4||Between gripper fingers|
|5||Left gripper finger|
|6||Right gripper finger|
These are shown as red coloured blocks on the robot. Using the
digital_read method, you’ll receive a
bool telling you whether the switch is current actuated.
Analogous to ultrasound sensors, distance sensors allow you to retrieve the distance between your robot and an object. These are attached to analogue pins 0-5:
These are shown as blue coloured blocks on the robot. The
analogue_read method will return the distance in metres, however only measure up to 30cm.
The LEDs are attached to digital pins 7-12:
digital_write method, you can set these to True (On) or False (Off).
Your robot has a camera, which is attached to the top of your robot. A live preview of what the camera sees is shown in the top-left corner. The vision system uses Webots’ object recognition, rather than fiducial markers.
see method will return a list of visible markers in the arena, but doesn’t allow a resolution argument. Each token is as described in the vision docs, except:
- As well as the existing constants,
Marker.info.marker_typecan be referred to as
MarkerTypecan be imported with
from sr.robot import MarkerType
- The following attributes are not available:
In the simulated environment, time advances only at the pace that the simulator
is run. As a result, using
time.time to know how long your robot has been
running for or
time.sleep to wait for some duration will be unreliable.
As a result the API present in the simulator supports a slightly different approach to handling time. See the documentation about simulated time for more details.