Skip to content

Commit d77752e

Browse files
committed
Merge branch 'more-simulator-updates'
2 parents bc6316d + 3d6292b commit d77752e

File tree

7 files changed

+113
-49
lines changed

7 files changed

+113
-49
lines changed

images/content/simulator/arena.png

-76.9 KB
Binary file not shown.
-104 KB
Binary file not shown.
12.9 KB
Loading
40.3 KB
Loading

simulator/setting_up_simulator.md

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,39 @@ title: Setting up the Simulator
66
Setting up the Simulator
77
========================
88

9-
## Prerequisites
9+
There are three key components you will need in order to be able to use the simulator:
1010

11+
- [Webots](#webots), the platform which runs the simulation
12+
- [Python](#python), the interpreter for the your robot code
13+
- The [world simulation](#world-simulation), which includes the SR API for use in the simulator
1114

12-
### Webots
1315

14-
Our simulator runs in a program called Webots.
15-
In order to run the simulation you first need to install Webots.
16+
## Webots
17+
18+
Webots is a free open-source robot simulator. It is the program which runs the simulation.
19+
1620
You need to download [Webots from here](https://cyberbotics.com/#download) and install it.
1721

18-
The current supported version is "R2023b".
22+
The current supported version is **R2023b**.
23+
24+
### Troubleshooting: performance
25+
26+
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.
1927

28+
If you find that the simulation runs very slowly we suggest disabling both Ambient Occlusion and Shadows.
29+
These should not affect the behaviour of the simulation, only the rendered visuals.
2030

21-
### Python
31+
To do this on Windows, open webots and go to the menu **Tools** → **Preferences** → **OpenGL**, then set **Ambient Occlusion** to "none" and check the box next to "Disable shadows".
32+
33+
To do this on Mac, open webots and go to the menu **Webots** → **Preferences** → **OpenGL**, then set **Ambient Occlusion** to "none" and check the box next to "Disable shadows".
34+
35+
## Python
2236

2337
You will also need Python installed.
24-
If it is not already installed this can be downloaded and installed from the [Python website](https://www.python.org/).
38+
If it is not already installed this can be downloaded and installed from the [Python website](https://www.python.org/downloads/).
39+
40+
We recommend using **Python 3.11** as it is the newest supported version and is the version which is used on your physical robot.
41+
The most recent version of Python (3.12), which is the default download, is not yet supported by Webots.
2542

2643
| Platform | Supported Python Version |
2744
|----------|--------------------------|
@@ -42,7 +59,33 @@ pip install -r competition-simulator-<version>/libraries.txt
4259
~~~~~
4360

4461

45-
## Installing the simulation
62+
### Troubleshooting: setting your version of Python
63+
64+
Sometimes Webots will not automatically detect your installed Python in which case it will need to be set manually.
65+
When this happens Webots will print errors to its console and your robot will not move.
66+
67+
You will need the full path to the version of Python that you want to use.
68+
This will vary based on the system you have.
69+
One way to find the path is by launching Python and running the following code:
70+
71+
~~~~~ python
72+
import sys
73+
print(sys.executable)
74+
~~~~~
75+
76+
Once you have the path you need to enter this into the Webots settings.
77+
78+
To do this on Windows, open webots and go to the menu **Tools** &rarr; **Preferences** &rarr; **General** &rarr; **Python command** and enter the path in that box.
79+
Your Python path is likely similar to `C:\Users\<USERNAME>\AppData\Local\Programs\Python\Python311\python.exe` when using Python 3.11, where `<USERNAME>` is your login.
80+
81+
On Mac you can set the path to the Python version to use via **Webots** &rarr; **Preferences** <kbd>⌘</kbd><kbd>,</kbd>.
82+
Your Python path is likely similar to `/Library/Frameworks/Python.framework/Versions/3.11/bin/python3` when using Python 3.11.
83+
If you installed Python using Homebrew, it will be in `/opt/homebrew/bin/python3.11` (or `/usr/local/bin/python3.11` on an Intel-based Mac)
84+
85+
If you're still having problems, ask for help in [Discord][discord].
86+
87+
88+
## The world simulation {#world-simulation}
4689

4790
1. Create a directory, perhaps called `simulation` where you will store your robot code.
4891
2. [Download the simulation](https://github.com/srobo/competition-simulator/releases/download/sr2024.1/competition-simulator-sr2024.1.zip), the latest version is sr2024.1, released on 2023-10-21.
@@ -67,31 +110,6 @@ On recent versions of macOS you may need to give Webots permission to access the
67110
</div>
68111
69112
70-
### Changing your version of Python
71-
72-
Sometimes Webots will not automatically detect your installed Python so we need to change it.
73-
When this happens Webots will print errors to its console and your robot will not move.
74-
75-
You will need the full path to the version of Python that you want to use.
76-
This will vary based on the system you have.
77-
One way to find the path is by launching Python and running the following code:
78-
79-
~~~~~ python
80-
import sys
81-
print(sys.executable)
82-
~~~~~
83-
84-
Once you have the path you need to enter this into the Webots settings.
85-
86-
To do this on Windows, open webots and go to the menu **Tools** &rarr; **Preferences** &rarr; **General** &rarr; **Python command** and enter the path in that box.
87-
Your Python path is likely similar to `C:\Users\<USERNAME>\AppData\Local\Programs\Python\Python311\python.exe` when using Python 3.11, where `<USERNAME>` is your login.
88-
89-
On Mac you can set the path to the Python version to use via **Webots** &rarr; **Preferences** <kbd>⌘</kbd><kbd>,</kbd>.
90-
Your Python path is likely similar to `/Library/Frameworks/Python.framework/Versions/3.11/bin/python3` when using Python 3.11.
91-
92-
If you're still having problems, ask for help in [Discord][discord].
93-
94-
95113
## Updates
96114
97115
Occasionally, we may release an update to the simulation.

simulator/simulated_robot.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ title: The Simulated Robot
88
The Simulated Robot
99
===================
1010

11+
<img class="right" style="width: 320px" src="{{ site.baseurl }}/images/content/simulator/sr2024-robot.png" alt="Image of the simulated robot">
12+
1113
There is a pre-built robot used in the simulator.
1214
To allow this simulated robot to move around and sense its environment a set of motors and sensors have been connected as detailed below.
1315

@@ -71,6 +73,8 @@ This is shown as a red coloured block on the robot. You can access the servo usi
7173

7274
### Distance Sensors
7375

76+
<!-- Changing this? Consider updating the "Simulated robot inputs" section in `simulator/using_the_simulator.md` -->
77+
7478
Analogous to [ultrasound sensors](https://robocraze.com/blogs/post/what-is-ultrasonic-sensor), distance sensors allow you to retrieve the distance between your robot and an object. These are attached to analog pins A0-A5:
7579

7680
| Pin | Location | Required Mode |
@@ -102,10 +106,12 @@ Using the `digital_write` method, you can set these to `True` (On) or `False` (O
102106

103107
## Vision
104108

109+
<!-- Changing this? Consider updating the "Simulated robot inputs" section in `simulator/using_the_simulator.md` -->
110+
105111
The simulated robot has a camera which provides position and orientation
106112
information about other objects within the simulation. This simulates the
107113
system of fiducial markers which the physical robot's camera can detect.
108114

109-
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]({{ site.baseurl }}/programming/vision/) as a reference. There are a few small differences between the simulator and the physical kit which are noted on that page.
115+
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]({{ site.baseurl }}/programming/vision/) as a reference. There are a few small differences between the simulator and the physical kit which are noted on that page.
110116

111-
[arduino-programming]: {{ site.baseurl }}/programming/arduino/sr_firmware
117+
[arduino-programming]: {{ site.baseurl }}/programming/arduino/sr_firmware

simulator/using_the_simulator.md

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ Using the Simulator
1010

1111
Within the Webots IDE, there are a few different panels:
1212

13-
- In the centre of your screen is the 3D simulated view of the arena
14-
- On the left is a tree hierarchy of all elements in this "world"
15-
- At the bottom is the console, where output from your robot code will be displayed
13+
- In the centre of your screen is the 3D simulated view of the arena.
14+
It can be useful to change your view into the world using the [camera controls][camera-controls].
15+
- On the left is a tree hierarchy of all elements in this "world".
16+
- On the right is a text editor which you can use to develop your code, however we recommend using a dedicated [code editor]({{ site.baseurl }}/tutorials/editors/) if you can.
17+
- At the bottom is the console, where output from your robot code will be displayed.
1618
- At the top are your general controls which include the time controls. Press the centre play button to run the simulation at normal speed.
1719

18-
### Useful links
20+
![Webots overview screenshot]({{ site.baseurl }}/images/content/simulator/webots-overview.png)
1921

20-
- [Camera Controls](https://www.cyberbotics.com/doc/guide/the-3d-window#navigation-in-the-scene)
21-
- [Graphics settings](https://www.cyberbotics.com/doc/guide/preferences#opengl) (Useful if Webots is running slowly)
22+
[camera-controls]: https://www.cyberbotics.com/doc/guide/the-3d-window#navigation-in-the-scene
2223

2324
## Time
2425

@@ -48,40 +49,79 @@ These methods are also available on the physical kits.
4849
<div class="warning" markdown="1">
4950

5051
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 `robot.sleep` even if with a small value.
51-
**If in doubt add an `robot.sleep`**.
52+
**If in doubt add a `robot.sleep`**.
5253
If you find that the simulator freezes then this indicates that your code is reaching a loop which does not contain any `robot.sleep` and is expecting time to advance.
5354

5455
</div>
5556

5657
## Developing your code
5758

58-
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:
59+
You should develop your code outside the folder which contains the world simulation, in a file called `robot.py`.
60+
This should be within the parent directory you created when [setting up the world simulation]({{ site.baseurl }}/simulator/setting_up_simulator#world-simulation).
5961

6062
```
6163
.
6264
├── competition-simulator-<version>
6365
│ ├── ...
64-
│ └─ worlds
66+
│ └─ worlds
6567
│ └── Arena.wbt
6668
└── robot.py
6769
```
6870

69-
Your code should be developed in `robot.py`.
71+
If you run the simulation without a `robot.py` file in place, the simulation will copy an example there and run it.
72+
73+
### Making changes
74+
75+
In order for your simulated robot to pick up changes to your code you need to save the files you are working on and then reload the simulation.
76+
This will also reset the state of the simulated world, allowing your robot to start afresh.
7077

7178
### Running multiple robots
7279

73-
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. Code can be placed in a `zone-<zone>` directory to run in starting zone `<zone>`:
80+
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.
81+
Rather than having a single `robot.py`, code can be placed in a number of `zone-<zone>` folders to run in starting zone `<zone>`:
7482

7583
```
7684
.
7785
├── competition-simulator-<version>
7886
│ ├── ...
79-
│ └─ worlds
87+
│ └─ worlds
8088
│ └── Arena.wbt
8189
├── zone-0
8290
│ └── robot.py
8391
└── zone-1
84-
└── robot.py
92+
└── robot.py
8593
```
8694

87-
This will run two robots in the arena, each with different `robot.py`s. You can run as many or as few zones as you like, in any combination.
95+
This will run two robots in the arena, each with different `robot.py` files. You can run as many or as few zones as you like, in any combination.
96+
97+
## Robot logs
98+
99+
When your program runs in the simulator, the output of `print(...)` statements and any errors which occur are written to a log file next to your code as `log-zone-<zone>-<date-time>.txt`.
100+
101+
These logs are also available to view live via the console at bottom of the simulator.
102+
103+
In the simulator, all logs are prefixed with the zone that the robot code is running in. For example, a robot running in zone 2 might have logs like:
104+
105+
~~~~~ not-code
106+
2| Using /home/srobo/my-robot/robot.py for Zone 2
107+
2| Robot Initialized. Zone: 2, Mode: RobotMode.DEV.
108+
2| Waiting for start signal.
109+
2| Starting
110+
2| I saw a marker!
111+
2| I turned left!
112+
~~~~~
113+
114+
This makes it possible to distinguish which logs are from which robot when they are viewed in Webots console panel.
115+
116+
## Simulated robot inputs
117+
118+
By default Webots will show an overlay of what the robot's [camera]({{ site.baseurl }}/simulator/simulated_robot#vision) can see in the top right of the simulation window.
119+
This can be useful to understand how the robot sees its world.
120+
Double-clicking this overlay will move the overlay to its own window.
121+
122+
Note that the view provided by Webots may include highlights of simulated markers which a real camera would not be able to see.
123+
These are filtered out for you by the simulated SR API.
124+
125+
The robot also features [distance sensors]({{ site.baseurl }}/simulator/simulated_robot#distance-sensors).
126+
To better understand how these sensors perceive the world it is possible to turn on a display of their interactions with the simulated world.
127+
Go to the menu **View** &rarr; **Optional Rendering** and select the option **Show DistanceSensor Rays**.

0 commit comments

Comments
 (0)