You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
18
16
19
17
#### Python Version
20
18
21
19
You will also need Python installed.
22
20
23
21
| Platform | Supported Python Version |
24
22
|----------|--------------------------|
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 |
38
26
39
27
### Installing the simulation
40
28
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.
42
30
2. Using the Webots IDE, open the `worlds/Arena.wbt` file.
43
31
44
32
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
60
48
[list of releases](https://github.com/srobo/competition-simulator/releases).
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
-
109
68
## Time
110
69
111
70
In the simulated environment, time advances only at the pace that the simulator
@@ -124,4 +83,8 @@ speeds (▶▶ and ▶▶▶).
124
83
125
84
These differences mean that your code will need to use a different mechanism to
126
85
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.
Copy file name to clipboardExpand all lines: simulator/programming/index.md
+48-29Lines changed: 48 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ title: Simulator Programming
9
9
10
10
## Developing your code
11
11
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:
13
13
14
14
```
15
15
.
@@ -27,70 +27,89 @@ Your code should be developed in `robot.py`.
27
27
Only your controller code will be present in the competition environment.
28
28
</div>
29
29
30
-
## Programming Interface
30
+
## Robot
31
31
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`.
33
36
34
37
### Motors
35
38
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.
37
53
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`.
39
55
40
56
### Ruggeduino
41
57
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.
43
59
44
60
Because these sensors are pre-attached to the ruggeduino, you do not need to set its `pin_mode`.
45
61
46
62
#### Microswitches
47
63
48
-
The microswitches are attached to digital pins 2 and 3:
64
+
The microswitch is attached to digital pin 2:
49
65
50
66
| Pin | Location |
51
67
|-----|----------|
52
-
| 2 | Front |
53
-
| 3 | Back |
68
+
| 2 | Back |
54
69
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.
56
71
57
72
#### Distance Sensors
58
73
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:
60
75
61
76
| Pin | Location |
62
77
|-----|----------|
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.
71
86
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.
72
87
73
88
#### LEDs
74
89
75
-
The LEDs are attached to digital pins 4-9:
90
+
The LEDs are attached to digital pins 3-4:
76
91
77
92
| Pin | Location |
78
93
|-----|----------|
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) |
85
96
86
97
Using the `digital_write` method, you can set these to True (On) or False (Off).
87
98
88
-
###Time
99
+
##Simulated Time
89
100
90
101
In the simulated environment, time advances only at the pace that the simulator
91
102
is run. As a result, using `time.time` to know how long your robot has been
92
103
running for or `time.sleep` to wait for some duration will be unreliable.
93
104
94
105
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
+
<divclass="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.
0 commit comments