The Simulated Robot
There is a pre-built robot used in the simulator. To allow this simulated robot to move around and sense its environment a set of motors and sensors have been connected as detailed below.
The simulator’s API is very similar to the real SR API described in the programming docs. The main differences are:
- the way that time is handled,
- the simulated arduino only offering the plain SR Firmware interactions, and
- the simulated robot not having the Brain Board LEDs.
Your robot has one motor board attached, the motor on the left wheel is connected to the “Motor 0” port, and the right wheel to “Motor 1”. These can be referenced with
See the motor board programming docs for how to control these.
If you want to reference the motor board by its the part code, you can use the part code
Your robot has one servo board attached, the jaws of the robot and the lifter are all controlled by servos.
Setting each servo to -1 fully opens the respective jaw, setting them to 1 fully closes them.
Setting the lifter to -1 fully lowers the lifter, setting it to 1 fully raises it.
You can access the servos with
robot.servo_board.servos[N] where N is the number of the servo from the table above. Read more at the servo board programming docs.
If you want to reference the servo board by its the part code, you can use the part code
Your robot has an arduino board, with one microswitch and six distance sensors, attached to the digital and analog pins respectively.
Make sure you have set the correct pin_mode, depending on what device you’re using.
The rear of the robot has a wide bump sensor attached to a microswitch.
The microswitch is attached to digital pin 2:
This is shown as a red coloured block on the robot. You can access the servo using
robot.arduino.pins. Make sure you set the pin mode to
digital_read method will return a
bool telling you whether the switch is currently being pressed. You can read more in the arduino programming docs page.
Analogous to ultrasound sensors, distance sensors allow you to retrieve the distance between your robot and an object. These are attached to analog pins A0-A5:
These are shown as blue boards with silver transceivers on the robot. They can see in a narrow cone up to a maximum of about 5m away. Since these sensors rely on echoes being reflected back from objects, if the angle of incidence between the sensor’s pulse and the contacted surface exceeds 22.5 degrees then the sensor will be unable to detect the object.
You can access the ultrasound sensors using
robot.arduino.pins[AX], where ‘
AX’ is between
A5. Make sure you set the pin mode to
analog_read method will return the distance in metres. You can read more in the arduino programming docs page.
Your robot has two LEDs mounted in clearly visible points on the robot. The LEDs are attached to digital pins 3-4:
You can access the LEDs using
robot.arduino.pins. For the red or green LED, respectively. Make sure you set the pin mode to
OUTPUT. You can read more in the arduino programming docs page.
digital_write method, you can set these to
True (On) or
The simulated robot has a camera which provides position and orientation information about other objects within the simulation. This simulates the system of fiducial markers which the physical robot’s camera can detect.
You can access the camera with
robot.camera. The simulated vision system matches the physical robot’s vision API, so please use the vision programming docs page as a reference. There are a few small differences between the simulator and the physical kit which are noted on that page.