@@ -22,75 +22,74 @@ from sr.robot3 import *
22
22
### Standard Initialisation
23
23
24
24
~~~~~ python
25
- R = Robot()
25
+ robot = Robot()
26
26
~~~~~
27
27
28
28
### Initialisation without waiting for the start button
29
29
30
30
~~~~~ python
31
- R = Robot(auto_start = True )
31
+ robot = Robot(wait_for_start = False )
32
32
33
33
# Code here runs before the start button is pressed
34
34
35
- R .wait_start()
35
+ robot .wait_start() # wait for the start button
36
36
~~~~~
37
37
38
38
### Initialisation with extra logging
39
39
40
- You can also tell the robot to print extra logging information, although this is quite noisy .
40
+ You can also tell the robot to print extra logging information, although this will create a lot of logs .
41
41
42
42
~~~~~ python
43
- R = Robot(verbose = True )
43
+ robot = Robot(debug = True )
44
44
~~~~~
45
45
46
46
## Selecting which board to control
47
47
48
48
If you only have one board of a given type plugged into your robot, then you can use its singular name:
49
49
50
50
~~~~~ python
51
- R .power_board.something
52
- R .motor_board.something
53
- R .servo_board.something
54
- R.ruggeduino.something
51
+ robot .power_board
52
+ robot .motor_board
53
+ robot .servo_board
54
+ robot.arduino
55
55
~~~~~
56
56
57
57
If you have multiple boards of a given type plugged into your robot, you must index them by serial number:
58
58
59
59
~~~~~ python
60
- R.motor_boards[" srABC1" ].something
61
- R.servo_boards[" srXYZ2" ].something
62
- R.ruggeduinos[" 1234567890" ].something
60
+ robot.motor_boards[" srABC1" ]
61
+ robot.arduinos[" 1234567890" ]
63
62
~~~~~
64
63
65
64
## Power Board
66
65
67
- The outputs on the power board will turn on when you initialise your robot.
66
+ The outputs on the power board will turn on when you initialise your robot and turn off when your code ends .
68
67
69
68
### Turn on and off the power outputs
70
69
71
70
~~~~~ python
72
71
# Turn all of the outputs on
73
- R .power_board.outputs.power_on()
72
+ robot .power_board.outputs.power_on()
74
73
75
74
# Turn all of the outputs off
76
- R .power_board.outputs.power_off()
75
+ robot .power_board.outputs.power_off()
77
76
78
77
# Turn a single output on
79
- R .power_board.outputs[OUT_H0 ].is_enabled = True
78
+ robot .power_board.outputs[OUT_H0 ].is_enabled = True
80
79
81
80
# Turn a single output off
82
- R .power_board.outputs[OUT_H0 ].is_enabled = False
81
+ robot .power_board.outputs[OUT_H0 ].is_enabled = False
83
82
~~~~~
84
83
85
84
### Reading voltage and current
86
85
87
86
~~~~~ python
88
87
# Read the current of an individual output
89
- current = R .power_board.outputs[OUT_H0 ].current
88
+ current = robot .power_board.outputs[OUT_H0 ].current
90
89
91
90
# Read the current and voltage from the LiPo battery
92
- voltage = R .power_board.battery_sensor.voltage
93
- current = R .power_board.battery_sensor.current
91
+ voltage = robot .power_board.battery_sensor.voltage
92
+ current = robot .power_board.battery_sensor.current
94
93
~~~~~
95
94
96
95
### Buzzer
@@ -99,10 +98,13 @@ The power board has an on-board piezoelectric buzzer.
99
98
100
99
~~~~~ python
101
100
# Play a standard note C6 -> C8 included for 0.5s
102
- R .power_board.piezo.buzz(0.5 , Note.C6 )
101
+ robot .power_board.piezo.buzz(Note.C6, 0.5 )
103
102
104
103
# Play a tone at 1047Hz for 1 second
105
- R.power_board.piezo.buzz(1 , 1047 )
104
+ robot.power_board.piezo.buzz(1047 , 1 )
105
+
106
+ # Play a tone at 500Hz tone for 2 seconds and wait for it to finish
107
+ robot.power_board.piezo.buzz(500 , 2 , blocking = True )
106
108
~~~~~
107
109
108
110
## Motors
@@ -114,34 +116,33 @@ You can set the power of each motor on the board between -1 and 1.
114
116
If you change the power of your motor too rapidly, the overcurrent protection may be triggered.
115
117
116
118
~~~~~ python
117
- R .motor_board.motors[0 ].power = 1
118
- R .motor_board.motors[1 ].power = - 1
119
+ robot .motor_board.motors[0 ].power = 1
120
+ robot .motor_board.motors[1 ].power = - 1
119
121
~~~~~
120
122
121
- Setting a motor to ` COAST ` is equivalent to power level ` 0 ` .
123
+ ### Special motor values
124
+
125
+ Setting a motor to ` BRAKE ` is equivalent to power level ` 0 ` .
122
126
123
127
~~~~~ python
124
128
# This is the same operation
125
- R .motor_board.motors[0 ].power = COAST
126
- R .motor_board.motors[0 ].power = 0
129
+ robot .motor_board.motors[0 ].power = BRAKE
130
+ robot .motor_board.motors[0 ].power = 0
127
131
~~~~~
128
132
129
- ### Braking Motors
130
-
131
- You can also brake a motor, which will quickly slow the motor.
133
+ ` COAST ` will stop applying power to the motors. This will mean they continue moving under the momentum they had before and slowly come to a stop.
132
134
133
135
~~~~~ python
134
- R.motor_board.motors[0 ].power = BRAKE
135
- R.motor_board.motors[1 ].power = - 1
136
+ robot.motor_board.motors[0 ].power = COAST
136
137
~~~~~
137
138
138
139
## Servos
139
140
140
141
You can set the position of each servo output on the board between -1 and 1.
141
142
142
143
~~~~~ python
143
- R .servo_board.servos[0 ].position = - 1
144
- R .servo_board.servos[1 ].position = 1
144
+ robot .servo_board.servos[0 ].position = - 1
145
+ robot .servo_board.servos[1 ].position = 1
145
146
~~~~~
146
147
147
148
You can also set the position to ` 0 ` , which is the approximate centre.
@@ -153,15 +154,23 @@ You can also set the position to `0`, which is the approximate centre.
153
154
It can sometimes be useful to save a photo of what markers the robot can see:
154
155
155
156
~~~~~ python
156
- R.camera.save(" my-photo.png" ) # Save my-photo.png to the USB drive
157
+ robot.camera.save(" my-photo.jpg" ) # Save my-photo.jpg to the USB drive
158
+ ~~~~~
159
+
160
+ ### Capturing an openCV array
161
+
162
+ Take a photo using the webcam, and return the image data as an OpenCV array:
163
+
164
+ ~~~~~ python
165
+ frame = robot.camera.capture()
157
166
~~~~~
158
167
159
168
### Looking for markers
160
169
161
170
You can take a photo with the camera and search for markers:
162
171
163
172
~~~~~ python
164
- markers = R .camera.see()
173
+ markers = robot .camera.see()
165
174
~~~~~
166
175
167
176
There are various bits of information available about visible markers:
@@ -172,94 +181,96 @@ for marker in markers:
172
181
marker.id # The ID of the marker
173
182
marker.size # Physical size of the marker in mm.
174
183
175
- marker.distance # Distance away from the camera in mm
176
-
177
- # Cartesian coords of the marker
178
- marker.cartesian.x
179
- marker.cartesian.y
180
- marker.cartesian.z
184
+ marker.pixel_centre # The co-ordinates of the centre of the marker
185
+ marker.pixel_corners # A list of corners of the marker
181
186
182
- # Spherical coords of the marker
183
- marker.spherical.rot_x
184
- marker.spherical.rot_y
185
- marker.spherical.dist
187
+ # Position of the marker
188
+ marker.position.distance # Distance away from the camera in mm
189
+ marker.position.horizontal_angle # angle to the marker in radians
190
+ marker.position.vertical_angle # angle to the marker in radians
186
191
187
192
# Orientation of the marker
188
- marker.orientation.rot_x
189
- marker.orientation.rot_y
190
- marker.orientation.rot_z
191
- marker.orientation.rotation_matrix
193
+ marker.orientation.yaw
194
+ marker.orientation.pitch
195
+ marker.orientation.roll
192
196
~~~~~
193
197
194
- ## Ruggeduino
198
+ ## Arduino
195
199
196
200
### Setting the mode of a pin
197
201
198
202
~~~~~ python
199
- R .ruggeduino.pins[4 ].mode = OUTPUT
200
- R .ruggeduino.pins[4 ].mode = INPUT
201
- R .ruggeduino.pins[4 ].mode = INPUT_PULLUP
203
+ robot .ruggeduino.pins[4 ].mode = OUTPUT
204
+ robot .ruggeduino.pins[4 ].mode = INPUT
205
+ robot .ruggeduino.pins[4 ].mode = INPUT_PULLUP
202
206
~~~~~
203
207
204
208
### Digital Write
205
209
206
- You can set the output for a pin of the Ruggeduino :
210
+ You can set the output for a pin of the Arduino :
207
211
208
212
~~~~~ python
209
- R .ruggeduino.pins[4 ].mode = OUTPUT
213
+ robot .ruggeduino.pins[2 ].mode = OUTPUT
210
214
211
- R .ruggeduino.pins[2 ].digital_write(True )
212
- R .ruggeduino.pins[2 ].digital_write(False )
215
+ robot .ruggeduino.pins[2 ].digital_write(True )
216
+ robot .ruggeduino.pins[2 ].digital_write(False )
213
217
~~~~~
214
218
215
219
### Digital Read
216
220
217
- You can read a digital value from the pins of the Ruggeduino :
221
+ You can read a digital value from the pins of the Arduino :
218
222
219
223
~~~~~ python
220
- R.ruggeduino.pins[3 ].mode = INPUT
224
+ robot.ruggeduino.pins[3 ].mode = INPUT
225
+ robot.ruggeduino.pins[5 ].mode = INPUT_PULLUP
221
226
222
- value = R.ruggeduino.pins[3 ].digital_read()
227
+ value = robot.ruggeduino.pins[3 ].digital_read()
228
+ value = robot.ruggeduino.pins[5 ].digital_read()
223
229
~~~~~
224
230
225
231
### Analogue Read
226
232
227
- You can read an analogue value from the analogue pins of the Ruggeduino :
233
+ You can read an analogue value from the analogue pins of the Arduino :
228
234
229
235
~~~~~ python
230
- value = R.ruggeduino.pins[A0].analogue_read()
236
+ robot.ruggeduino.pins[A0].mode = INPUT
237
+
238
+ value = robot.ruggeduino.pins[A0].analogue_read()
231
239
~~~~~
232
240
233
241
## Metadata
234
242
235
243
The API also makes some information about where your code is running
236
244
237
- ### Starting Zone for a match
245
+ ### Starting zone for a match
238
246
239
247
~~~~~ python
240
- zone = R .zone # -> 0, 1, 2, or 3
248
+ zone = robot .zone # -> 0, 1, 2, or 3
241
249
~~~~~
242
250
243
- ### Arena Information
251
+ ### Robot mode
252
+
253
+ This is set to ` COMP ` when your robot is in a match.
244
254
245
255
~~~~~ python
246
- arena = R.arena # -> 'A'
256
+ robot_mode = robot.mode # -> DEV or COMP
247
257
~~~~~
248
258
249
- ### Robot Mode
259
+ ### USB stick path
250
260
251
- This is set to ` COMP ` when your robot is in a match.
261
+ This is the path to where your USB stick is mounted.
262
+
263
+ You can use this to save files and information to the drive.
252
264
253
265
~~~~~ python
254
- robot_mode = R.mode # -> DEV or COMP
266
+ usb_key_path = robot.usbkey
255
267
~~~~~
256
268
257
- ### USB Key Path
269
+ ### Is simulated
258
270
259
- This is the path to where your USB key is mounted.
260
-
261
- You can use this to save files and information to the drive.
271
+ A boolean value indicating whether or not the code is running in the simulator.
272
+ This value is True when in the simulator and False when on the robot.
262
273
263
274
~~~~~ python
264
- usb_key_path = R.usbkey # -> pathlib.Path
275
+ value = robot.is_simulated
265
276
~~~~~
0 commit comments