Skip to content

Commit 336f981

Browse files
committed
Merge branch 'refactor-simulator-docs'
2 parents 1771206 + 8e39cca commit 336f981

File tree

4 files changed

+84
-77
lines changed

4 files changed

+84
-77
lines changed

_data/sidebar_tree.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ tree:
106106
title: Setting up the Simulator
107107
- url: /simulator/using_the_simulator
108108
title: Using the Simulator
109-
- url: /simulator/simulator_programming
110-
title: Simulator Programming
109+
- url: /simulator/simulated_robot
110+
title: The Simulated Robot
111111
- url: /troubleshooting/
112112
title: Troubleshooting
113113
tree:

simulator/index.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ title: Simulator
77

88
The simulator is used for the virtual competition but can also be a useful tool for becoming more familiar with our API or planning out game strategies.
99

10-
The below pages contain guidance on how to use the simulator.
11-
Guiding you through installation, writing code and then running matches.
10+
## Programming
1211

12+
Programming for the simulator is very similar to [programming for your physical robot]({{ site.baseurl }}/programming/).
13+
14+
The simulator provides a subset of the `sr.robot3` [Robot API]({{ site.baseurl }}/programming/robot_api/) which is used on the physical robots. As a result code which is written for the simulator should largely work on your robot and vice-versa.
15+
16+
## Getting started
17+
18+
In order to use the simulator you will need to install the simulator software and download the Student Robotics simulation.
19+
This is detailed in the section on [Setting up the Simulator]({{ site.baseurl }}/simulator/setting_up_simulator).
20+
21+
Once you're set up, the page on [Using the Simulator]({{ site.baseurl }}/simulator/using_the_simulator) provides details on how to use the simulator software as well as get started on developing the code for your simulated robot.
22+
23+
Just as for programming your robot, we recommend that you use a code editor.
24+
A good code editor can provide you with features such as auto completion and syntax highlighting which will help you more easily write code.
25+
For suggestions of suitable editors, and how to set them up see the [Code Editors]({{ site.baseurl }}/tutorials/editors/) section.
26+
27+
## The Simulated Robot
28+
29+
The simulation contains a pre-built robot, constructed around a set of simulated kit components.
30+
The capabilities and limitations of this robot are detailed in the section on [The Simulated Robot]({{ site.baseurl }}/simulator/simulated_robot).

simulator/simulator_programming.md renamed to simulator/simulated_robot.md

Lines changed: 11 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,19 @@
22
redirect_from:
33
- /simulator/programming/
44
layout: page
5-
title: Simulator Programming
5+
title: The Simulated Robot
66
---
77

8-
Simulator Programming
9-
=====================
10-
11-
## Developing your code
12-
13-
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:
14-
15-
```
16-
.
17-
├── competition-simulator-<version>
18-
│ ├── ...
19-
│ └─ worlds
20-
│ └── Arena.wbt
21-
└── robot.py
22-
```
23-
24-
Your code should be developed in `robot.py`.
25-
26-
<div class="warning">
27-
Only your controller code will be present in the competition environment.
28-
</div>
29-
30-
### Running multiple robots
31-
32-
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>`:
33-
34-
```
35-
.
36-
├── competition-simulator-<version>
37-
│ ├── ...
38-
│ └─ worlds
39-
│ └── Arena.wbt
40-
├── zone-0
41-
│ └── robot.py
42-
└── zone-1
43-
└── robot.py
44-
```
45-
46-
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.
47-
48-
## Robot
8+
The Simulated Robot
9+
===================
4910

5011
There is a pre-built robot used in the simulator.
5112
To allow this simulated robot to move around and sense its environment a set of motors and sensors have been connected as detailed below.
5213

5314
The simulator’s API is very similar to the real SR API described in the [programming docs]({{ site.baseurl }}/programming/).
5415
The main differences are:
5516

56-
- the way that [time is handled](#simulated-time),
17+
- the way that [time is handled]({{ site.baseurl }}/simulator/using_the_simulator#time),
5718
- the simulated arduino only offering the plain SR Firmware interactions, and
5819
- the simulated robot not having the Brain Board LEDs.
5920

@@ -63,13 +24,13 @@ The main differences are:
6324
fluctuate slightly between measurements or operations.
6425
</div>
6526

66-
### Motors
27+
## Motors
6728

6829
Your robot has one motor board attached, the left wheel is connected to the first port, and the right wheel to the second.
6930

7031
The motor board has the part code `srABC1`, since only a single motor board is attached it can be referenced as `robot.motor_board`.
7132

72-
### Servos
33+
## Servos
7334

7435
Your robot has one servo board attached, the jaws of the robot are controlled by a pair of servos:
7536

@@ -85,15 +46,15 @@ Setting the lifter to -1 fully lowers the lifter, setting it to 1 fully raises i
8546

8647
The servo board has the part code `srXYZ2`, but since only a single servo board is attached it can be referenced as `robot.servo_board`.
8748

88-
### Arduino
49+
## Arduino
8950

9051
Your robot has a microswitch and six distance sensors, attached to the digital and analog pins respectively. These are all attached to a single arduino.
9152

9253
The simulated arduino behaves like one with the ordinary SR Firmware and does not offer any of the extended or custom arduino behaviours.
9354

9455
Make sure you have set the correct [pin_mode]({{ site.baseurl }}/programming/arduino/sr_firmware#setting-pin-modes), depending on what device you're using.
9556

96-
#### Microswitches
57+
### Microswitches
9758

9859
The rear of the robot has a wide microswitch.
9960

@@ -105,7 +66,7 @@ The microswitch is attached to digital pin 2:
10566

10667
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.
10768

108-
#### Distance Sensors
69+
### Distance Sensors
10970

11071
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:
11172

@@ -121,7 +82,7 @@ Analogous to ultrasound sensors, distance sensors allow you to retrieve the dist
12182
These are shown as blue boards with silver transceivers on the robot. The `analog_read` method will return the distance in metres. They can see in a narrow cone up to a maximum of about 2m away.
12283
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.
12384

124-
#### LEDs
85+
### LEDs
12586

12687
The LEDs are attached to digital pins 3-4:
12788

@@ -132,7 +93,7 @@ The LEDs are attached to digital pins 3-4:
13293

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

135-
### Vision
96+
## Vision
13697

13798
The simulated robot has a camera which provides position and orientation
13899
information about other objects within the simulation. This simulates the
@@ -141,21 +102,3 @@ system of fiducial markers which the physical robot's camera can detect.
141102
The simulated vision system matches the physical robot's
142103
[vision API]({{ site.baseurl }}/programming/vision/), with small differences as
143104
noted in the vision docs.
144-
145-
## Simulated Time
146-
147-
In the simulated environment, time advances only at the pace that the simulator
148-
is run. As a result, using `time.time` to know how long your robot has been
149-
running for or `time.sleep` to wait for some duration will be unreliable.
150-
151-
As a result the API present in the simulator supports a slightly different
152-
approach to handling time.
153-
The methods `robot.time` and `robot.sleep` are provided as a direct replacement of `time.time` and `time.sleep` respectively and can be used anywhere the previous methods were used.
154-
155-
<div class="warning" markdown="1">
156-
157-
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.
158-
**If in doubt add an `robot.sleep`**.
159-
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.
160-
161-
</div>

simulator/using_the_simulator.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,56 @@ speed multiplier shows 0.00×). You could choose to step a single time increment
3636
run the simulator at real speed (▶), or run the simulator at various faster
3737
speeds (▶▶ and ▶▶▶).
3838

39-
These differences mean that your code will need to use a different mechanism to
40-
find the current time or to sleep within the simulation. Find out more by
41-
heading over to the [simulator programming docs](/docs/simulator/simulator_programming).
39+
### Programming for Simulated Time
4240

43-
## Programming
41+
As time in the simulator is part of the simulation itself, your code must be careful not to block for too long.
4442

45-
Once you have the simulator installed you can begin [programming your robot](/docs/simulator/simulator_programming) in the simulator.
43+
For example, if you have used Python before and have used `time.time` to determine the current time or `time.sleep` to wait for some duration, you will find these to be unreliable in the simulator.
44+
45+
Instead you must use `robot.time` and `robot.sleep`, which are provided as direct replacements of `time.time` and `time.sleep` respectively.
46+
These methods are also available on the physical kits.
47+
48+
<div class="warning" markdown="1">
49+
50+
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 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+
</div>
55+
56+
## Developing your code
57+
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+
60+
```
61+
.
62+
├── competition-simulator-<version>
63+
│ ├── ...
64+
│ └─ worlds
65+
│ └── Arena.wbt
66+
└── robot.py
67+
```
68+
69+
Your code should be developed in `robot.py`.
70+
71+
<div class="warning">
72+
Only your controller code will be present in the competition environment.
73+
</div>
74+
75+
### Running multiple robots
76+
77+
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>`:
78+
79+
```
80+
.
81+
├── competition-simulator-<version>
82+
│ ├── ...
83+
│ └─ worlds
84+
│ └── Arena.wbt
85+
├── zone-0
86+
│ └── robot.py
87+
└── zone-1
88+
└── robot.py
89+
```
90+
91+
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.

0 commit comments

Comments
 (0)