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/programming/index.md
+37-26Lines changed: 37 additions & 26 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,61 +27,72 @@ 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`, 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).
0 commit comments