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
This drops the idea of programming in the simulator from these docs,
since we don't really document that here. Instead that is covered
by the main programming docs when read alongside these.
That page's content moves to the docs on using the simulator and
(mostly) to a new page about the simulated robot. What was two
sections on simulated time becomes essentially one more cohesive
section.
The index page is also considerably fleshed out to provide
navigation between these new sections as well as a clearer overview.
Copy file name to clipboardExpand all lines: simulator/index.md
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,24 @@ title: Simulator
7
7
8
8
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.
9
9
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
12
11
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).
Copy file name to clipboardExpand all lines: simulator/simulated_robot.md
+11-68Lines changed: 11 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,58 +2,19 @@
2
2
redirect_from:
3
3
- /simulator/programming/
4
4
layout: page
5
-
title: Simulator Programming
5
+
title: The Simulated Robot
6
6
---
7
7
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
-
<divclass="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
+
===================
49
10
50
11
There is a pre-built robot used in the simulator.
51
12
To allow this simulated robot to move around and sense its environment a set of motors and sensors have been connected as detailed below.
52
13
53
14
The simulator’s API is very similar to the real SR API described in the [programming docs]({{ site.baseurl }}/programming/).
54
15
The main differences are:
55
16
56
-
- the way that [time is handled](#simulated-time),
17
+
- the way that [time is handled]({{ site.baseurl }}/simulator/using_the_simulator#time),
57
18
- the simulated arduino only offering the plain SR Firmware interactions, and
58
19
- the simulated robot not having the Brain Board LEDs.
59
20
@@ -63,13 +24,13 @@ The main differences are:
63
24
fluctuate slightly between measurements or operations.
64
25
</div>
65
26
66
-
###Motors
27
+
## Motors
67
28
68
29
Your robot has one motor board attached, the left wheel is connected to the first port, and the right wheel to the second.
69
30
70
31
The motor board has the part code `srABC1`, since only a single motor board is attached it can be referenced as `robot.motor_board`.
71
32
72
-
###Servos
33
+
## Servos
73
34
74
35
Your robot has one servo board attached, the jaws of the robot are controlled by a pair of servos:
75
36
@@ -85,15 +46,15 @@ Setting the lifter to -1 fully lowers the lifter, setting it to 1 fully raises i
85
46
86
47
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`.
87
48
88
-
###Arduino
49
+
## Arduino
89
50
90
51
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.
91
52
92
53
The simulated arduino behaves like one with the ordinary SR Firmware and does not offer any of the extended or custom arduino behaviours.
93
54
94
55
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.
95
56
96
-
####Microswitches
57
+
### Microswitches
97
58
98
59
The rear of the robot has a wide microswitch.
99
60
@@ -105,7 +66,7 @@ The microswitch is attached to digital pin 2:
105
66
106
67
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.
107
68
108
-
####Distance Sensors
69
+
### Distance Sensors
109
70
110
71
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:
111
72
@@ -121,7 +82,7 @@ Analogous to ultrasound sensors, distance sensors allow you to retrieve the dist
121
82
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.
122
83
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.
123
84
124
-
####LEDs
85
+
### LEDs
125
86
126
87
The LEDs are attached to digital pins 3-4:
127
88
@@ -132,7 +93,7 @@ The LEDs are attached to digital pins 3-4:
132
93
133
94
Using the `digital_write` method, you can set these to `True` (On) or `False` (Off).
134
95
135
-
###Vision
96
+
## Vision
136
97
137
98
The simulated robot has a camera which provides position and orientation
138
99
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.
141
102
The simulated vision system matches the physical robot's
142
103
[vision API]({{ site.baseurl }}/programming/vision/), with small differences as
143
104
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
-
<divclass="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.
Copy file name to clipboardExpand all lines: simulator/using_the_simulator.md
+51-5Lines changed: 51 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,10 +36,56 @@ speed multiplier shows 0.00×). You could choose to step a single time increment
36
36
run the simulator at real speed (▶), or run the simulator at various faster
37
37
speeds (▶▶ and ▶▶▶).
38
38
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
42
40
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.
44
42
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
+
<divclass="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
+
<divclass="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