Skip to content

Commit a9a24b3

Browse files
authored
Merge pull request #270 from srobo/sim-docs
Update simulator docs
2 parents 224b0fe + afb4dee commit a9a24b3

File tree

4 files changed

+65
-143
lines changed

4 files changed

+65
-143
lines changed

_data/sidebar_tree.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ tree:
7070
tree:
7171
- url: /rules/archive
7272
title: Game Rules Archive
73+
- url: /simulator/
74+
title: Simulator
75+
tree:
76+
- url: /simulator/programming/
77+
title: Programming
7378
- url: /troubleshooting/
7479
title: Troubleshooting
7580
tree:

simulator/index.md

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,25 @@ title: Simulator
88

99
# Simulator
1010

11-
![]({{ site.baseurl }}/images/content/simulator/arena.png)
12-
1311
## Installation
1412

1513
### Prerequisites
1614

17-
You need to download and install [Webots](https://cyberbotics.com/#download) (the download is around 1.5GB). This is the platform we run our simulation in. Whilst we recommend version "R2021a" of Webots, and will be running competition simulations using it, "R2020b-rev1" should still work.
15+
You need to download and install [Webots](https://cyberbotics.com/#download) (the download is around 400MB). This is the platform we run our simulation in. We recommend version "R2021b" of Webots.
1816

1917
#### Python Version
2018

2119
You will also need Python installed.
2220

2321
| Platform | Supported Python Version |
2422
|----------|--------------------------|
25-
| Windows | 3.7 - 3.8 (64-bit) |
26-
| macOS | 3.7 - 3.8 |
27-
| Linux | 3.7 - 3.8 |
28-
29-
In the competition, Python 3.7 will be used.
30-
31-
There are a small number of [external libraries]({{ site.baseurl }}/programming/python/libraries)
32-
which will be available to your robot code during the competition. Note that for
33-
local development you will need to install these yourself.
34-
35-
If there are other libraries you would like included, please let us know
36-
in [`#programming-help`][programming-help] on the [Discord][discord] and include
37-
a link to the package on [PyPI](https://pypi.org/).
23+
| Windows | 3.7-3.9 (64-bit) |
24+
| macOS | 3.7-3.9 |
25+
| Linux | 3.7-3.9 |
3826

3927
### Installing the simulation
4028

41-
1. [Download the simulation](https://github.com/srobo/competition-simulator/releases/download/sr2021.10/competition-simulator-sr2021.10.zip), and unzip it somewhere on your computer.
29+
1. [Download the simulation](https://github.com/srobo/competition-simulator/releases/download/sr2022.1/competition-simulator-sr2022.1.zip), and unzip it somewhere on your computer.
4230
2. Using the Webots IDE, open the `worlds/Arena.wbt` file.
4331

4432
You may receive a warning about your computer's GPU not being good enough, which can be ignored.
@@ -60,8 +48,8 @@ have been made with each version, please see the
6048
[list of releases](https://github.com/srobo/competition-simulator/releases).
6149

6250
[discord]: {{ site.baseurl }}/team_admin/discord
63-
[programming-help]: https://discord.com/channels/775497131057741836/777582218662510612
64-
[simulator-help]: https://discord.com/channels/775497131057741836/777584209896275988
51+
[programming-help]: https://discord.com/channels/900501415548579842/900501416269971457
52+
[simulator-help]: https://discord.com/channels/900501415548579842/900501416269971458
6553

6654
## Overview
6755

@@ -77,35 +65,6 @@ Within the Webots IDE, there are a few different panels:
7765
- [Camera Controls](https://www.cyberbotics.com/doc/guide/the-3d-window#navigation-in-the-scene)
7866
- [Graphics settings](https://www.cyberbotics.com/doc/guide/preferences#opengl) (Useful if Webots is running slowly)
7967

80-
## Robot
81-
82-
![]({{ site.baseurl }}/images/content/simulator/robot-side.png)
83-
84-
This is the pre-built robot used in the simulator, with an interface [similar](./programming) to the SR API.
85-
86-
The robot has an [array of sensors](./programming/#ruggeduino) which can be [programmed](./programming), along with a [compass]({{ site.baseurl }}/programming/sr/compass/) and a [radio system]({{ site.baseurl }}/programming/sr/radio/).
87-
88-
### Other robots
89-
90-
There is another robot in the arena, in its starting zone. By default, this robot will not move.
91-
92-
To control the other robot, you will need to provide its code:
93-
94-
Create the robot code in `zone-1/robot.py`. Your code at `robot.py` will be used for zone `0`,
95-
though you are encouraged to move your code to `zone-0/robot.py` when running multiple robots.
96-
Robots which do not have any robot code in their `zone-x` directory will not do anything.
97-
98-
```
99-
.
100-
├── competition-simulator-<version>
101-
│ ├── ...
102-
│ └─ worlds
103-
│ └── Arena.wbt
104-
├── zone-1
105-
| └─ robot.py
106-
└── robot.py
107-
```
108-
10968
## Time
11069

11170
In the simulated environment, time advances only at the pace that the simulator
@@ -124,4 +83,8 @@ speeds (▶▶ and ▶▶▶).
12483

12584
These differences mean that your code will need to use a different mechanism to
12685
find the current time or to sleep within the simulation. Find out more by
127-
heading over to the [programming docs on time](./programming/time).
86+
heading over to the [simulator programming docs](./programming).
87+
88+
## Programming
89+
90+
Once you have the simulator installed you can begin [programming your robot](./programming) in the simulator.

simulator/programming/index.md

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ title: Simulator Programming
99

1010
## Developing your code
1111

12-
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:
12+
On first run, the robot will execute an example program for convenience. This program will be copied to the directory `competition-simulator-<version>` is stored in:
1313

1414
```
1515
.
@@ -27,70 +27,89 @@ Your code should be developed in `robot.py`.
2727
Only your controller code will be present in the competition environment.
2828
</div>
2929

30-
## Programming Interface
30+
## Robot
3131

32-
Unless otherwise stated, the simulator’s API is the same as the real SR API described in the [programming docs]({{ site.baseurl }}/programming/).
32+
There is a pre-built robot used in the simulator.
33+
To allow this simulated robot to move around and sense its environment a set of motors and sensors have been connected as detailed below.
34+
35+
The simulator’s API is very similar to the real SR API described in the [programming docs]({{ site.baseurl }}/programming/), with the exception of `R.time` and `R.sleep`.
3336

3437
### Motors
3538

36-
Your robot has one motor board attached, the left wheel in port `m0`, and the right wheel in `m1`.
39+
Your robot has one motor board attached, the left wheel is connected to the first port, and the right wheel to the second.
40+
41+
The motor board has the part code `srABC1`, since only a single motor board is attached it can be referenced as `R.motor_board`.
42+
43+
### Servos
44+
45+
Your robot has one servo board attached, the jaws of the robot are controlled by a pair of servos:
46+
47+
| Servo | Location |
48+
|-------|-----------|
49+
| 0 | Left Jaw |
50+
| 1 | Right Jaw |
51+
52+
Setting each servo to -1 fully opens the respective jaw.
3753

38-
The motor board does not have a part code, so it needs to be indexed using `0`.
54+
The servo board has the part code `srXYZ2`, but since only a single servo board is attached it can be referenced as `R.servo_board`.
3955

4056
### Ruggeduino
4157

42-
Your robot has two microswitches and six distance sensors, attached to the digital and analogue pins respectively. These are all attached to a single ruggeduino.
58+
Your robot has a microswitch and six distance sensors, attached to the digital and analogue pins respectively. These are all attached to a single ruggeduino.
4359

4460
Because these sensors are pre-attached to the ruggeduino, you do not need to set its `pin_mode`.
4561

4662
#### Microswitches
4763

48-
The microswitches are attached to digital pins 2 and 3:
64+
The microswitch is attached to digital pin 2:
4965

5066
| Pin | Location |
5167
|-----|----------|
52-
| 2 | Front |
53-
| 3 | Back |
68+
| 2 | Back |
5469

55-
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.
70+
This is shown as a red coloured block on the robot. Using the `digital_read` method, you'll receive a `bool` telling you whether the switch is currently actuated.
5671

5772
#### Distance Sensors
5873

59-
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:
74+
Analogous to ultrasound sensors, distance sensors allow you to retrieve the distance between your robot and an object. These are attached to analogue pins A0-A5:
6075

6176
| Pin | Location |
6277
|-----|----------|
63-
| 0 | Front Left |
64-
| 1 | Front Right |
65-
| 2 | Left |
66-
| 3 | Right |
67-
| 4 | Back Left |
68-
| 5 | Back Right |
69-
70-
These are shown as blue coloured blocks on the robot. The `analogue_read` method will return the distance in metres. They can see in a narrow cone up to a maximum of about 2m away.
78+
| A0 | Front Left |
79+
| A1 | Front Right |
80+
| A2 | Left |
81+
| A3 | Right |
82+
| A4 | Front |
83+
| A5 | Back |
84+
85+
These are shown as blue boards with silver transceivers on the robot. The `analogue_read` method will return the distance in metres. They can see in a narrow cone up to a maximum of about 2m away.
7186
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.
7287

7388
#### LEDs
7489

75-
The LEDs are attached to digital pins 4-9:
90+
The LEDs are attached to digital pins 3-4:
7691

7792
| Pin | Location |
7893
|-----|----------|
79-
| 4 | Red (right) |
80-
| 5 | Green (right) |
81-
| 6 | Blue (right) |
82-
| 7 | Blue (left) |
83-
| 8 | Green (left) |
84-
| 9 | Red (left) |
94+
| 3 | Red (Left) |
95+
| 4 | Green (right) |
8596

8697
Using the `digital_write` method, you can set these to True (On) or False (Off).
8798

88-
### Time
99+
## Simulated Time
89100

90101
In the simulated environment, time advances only at the pace that the simulator
91102
is run. As a result, using `time.time` to know how long your robot has been
92103
running for or `time.sleep` to wait for some duration will be unreliable.
93104

94105
As a result the API present in the simulator supports a slightly different
95-
approach to handling time. See the documentation about [simulated time](./time)
96-
for more details.
106+
approach to handling time.
107+
The methods `R.time` and `R.sleep` are provided as a direct replacement of `time.time` and `time.sleep` respectively and can be used anywhere the previous methods were used.
108+
109+
<div class="warning">
110+
Since the simulator does not simulate the time taken to execute your code, any loop or decision which needs an event to occur must be accompanied by a <code>R.sleep</code> even if with a small value.
111+
112+
<b>If in doubt add an <code>R.sleep</code></b>.
113+
114+
If you find that the simulator freezes then this indicates that your code is reaching a loop which does not contain any <code>R.sleep</code> and is expecting time to advance.
115+
</div>

simulator/programming/time.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)