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
Copy file name to clipboardExpand all lines: simulator/setting_up_simulator.md
+51-33Lines changed: 51 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,22 +6,39 @@ title: Setting up the Simulator
6
6
Setting up the Simulator
7
7
========================
8
8
9
-
## Prerequisites
9
+
There are three key components you will need in order to be able to use the simulator:
10
10
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
11
14
12
-
### Webots
13
15
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
+
16
20
You need to download [Webots from here](https://cyberbotics.com/#download) and install it.
17
21
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.
19
27
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.
20
30
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
22
36
23
37
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.
### 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**→**Preferences**→**General**→**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**→**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}
46
89
47
90
1. Create a directory, perhaps called `simulation` where you will store your robot code.
48
91
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
67
110
</div>
68
111
69
112
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** → **Preferences** → **General** → **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** → **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
-
95
113
## Updates
96
114
97
115
Occasionally, we may release an update to the simulation.
Copy file name to clipboardExpand all lines: simulator/simulated_robot.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,8 @@ title: The Simulated Robot
8
8
The Simulated Robot
9
9
===================
10
10
11
+
<imgclass="right"style="width: 320px"src="{{ site.baseurl }}/images/content/simulator/sr2024-robot.png"alt="Image of the simulated robot">
12
+
11
13
There is a pre-built robot used in the simulator.
12
14
To allow this simulated robot to move around and sense its environment a set of motors and sensors have been connected as detailed below.
13
15
@@ -71,6 +73,8 @@ This is shown as a red coloured block on the robot. You can access the servo usi
71
73
72
74
### Distance Sensors
73
75
76
+
<!-- Changing this? Consider updating the "Simulated robot inputs" section in `simulator/using_the_simulator.md` -->
77
+
74
78
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:
75
79
76
80
| Pin | Location | Required Mode |
@@ -102,10 +106,12 @@ Using the `digital_write` method, you can set these to `True` (On) or `False` (O
102
106
103
107
## Vision
104
108
109
+
<!-- Changing this? Consider updating the "Simulated robot inputs" section in `simulator/using_the_simulator.md` -->
110
+
105
111
The simulated robot has a camera which provides position and orientation
106
112
information about other objects within the simulation. This simulates the
107
113
system of fiducial markers which the physical robot's camera can detect.
108
114
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.
Copy file name to clipboardExpand all lines: simulator/using_the_simulator.md
+54-14Lines changed: 54 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,16 @@ Using the Simulator
10
10
11
11
Within the Webots IDE, there are a few different panels:
12
12
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.
16
18
- At the top are your general controls which include the time controls. Press the centre play button to run the simulation at normal speed.
@@ -48,40 +49,79 @@ These methods are also available on the physical kits.
48
49
<divclass="warning"markdown="1">
49
50
50
51
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`**.
52
53
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.
53
54
54
55
</div>
55
56
56
57
## Developing your code
57
58
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).
59
61
60
62
```
61
63
.
62
64
├── competition-simulator-<version>
63
65
│ ├── ...
64
-
│ └─ worlds
66
+
│ └── worlds
65
67
│ └── Arena.wbt
66
68
└── robot.py
67
69
```
68
70
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.
70
77
71
78
### Running multiple robots
72
79
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>`:
74
82
75
83
```
76
84
.
77
85
├── competition-simulator-<version>
78
86
│ ├── ...
79
-
│ └─ worlds
87
+
│ └── worlds
80
88
│ └── Arena.wbt
81
89
├── zone-0
82
90
│ └── robot.py
83
91
└── zone-1
84
-
└── robot.py
92
+
└── robot.py
85
93
```
86
94
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:
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**→**Optional Rendering** and select the option **Show DistanceSensor Rays**.
0 commit comments