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
The `sr.robot3` library contains support for detecting fiducial markers with the provided webcam.
10
-
Markers are attached to various items in the Student Robotics arena.
11
-
Each marker encodes a number in a machine-readable way, which means that robots can identify these objects.
12
-
For information on which markers codes are which, see the [markers page](./markers).
9
+
Your robot is able to use a webcam to detect [fiducial markers](https://en.wikipedia.org/wiki/Fiducial_marker).
10
+
Specifically it can detect [AprilTags](https://april.eecs.umich.edu/software/apriltag), using the `36H11` marker set.
13
11
14
-
Using knowledge of the physical size of the different markers and the characteristics of the webcam,
15
-
your robot can calculate the position of markers in 3D space relative to the camera.
16
-
Therefore, if the robot can see a marker that is at a fixed location in the arena,
17
-
a robot can calculate its exact position in the arena.
12
+
Each marker is unique and encodes a number in a machine-readable way, which means that robots can identify these objects.
18
13
19
-
Under the hood, the vision system is based on [AprilTag](https://april.eecs.umich.edu/software/apriltag/) and [OpenCV](https://opencv.org), using the `36H11` marker set.
14
+
Using [Pose Estimation](https://en.wikipedia.org/wiki/3D_pose_estimation), it can calculate the orientation and position of the marker relative to the webcam.
15
+
Markers are attached to various items in the Student Robotics arena, in known locations.
16
+
Using the marker poses and their locations, we can either calculate the location of object relative to the robot or the position of the robot relative to the arena.
17
+
18
+
For information on markers, see the [markers page](./markers).
20
19
21
20
[Camera](#camera) {#camera}
22
21
===========================
23
22
24
23
The interface to the vision system is through the camera, accessible through `R.camera`.
25
24
26
25
see
27
-
: Take a photo through the webcam, and return a list of [`Marker`](#Marker) instances, each of which describes one of the markers that were found in the image.
26
+
: Take a photo through the webcam, and return a list of [`Marker`](#marker) instances, each of which describes one of the markers that were found in the image.
28
27
29
-
Here's an example that will repeatedly print out the distanceto each arena marker that the robot can see:
28
+
Here's an example that will repeatedly print out the distance, in meters, to each marker that the robot can see:
30
29
31
30
~~~~~python
32
31
from sr.robot3 import*
33
-
R= Robot()
32
+
robot= Robot()
34
33
35
34
whileTrue:
36
-
markers =R.camera.see()
35
+
markers =robot.camera.see()
37
36
print("I can see", len(markers), "markers:")
38
37
39
-
for m in markers:
40
-
print(" - Marker #{0} is {1} metres away".format(m.id, m.distance /1000))
41
-
~~~~~
42
-
43
-
see_ids
44
-
: Take a photo through the webcam, and return a list of marker ids (**not** full `Marker` objects). This doesn't do the same [pose estimation](https://en.wikipedia.org/wiki/3D_pose_estimation) calculations as `see`, and so is much faster to run.
45
-
46
-
~~~~~python
47
-
from sr.robot3 import*
48
-
R = Robot()
49
-
50
-
whileTrue:
51
-
marker_ids = R.camera.see_ids()
52
-
53
-
if0in marker_ids:
54
-
print("I can see marker 0!")
55
-
else:
56
-
print("I cannot see marker 0!")
38
+
for marker in markers:
39
+
print(" - Marker #{0} is {1} metres away".format(marker.id, marker.distance /1000))
57
40
~~~~~
58
41
59
-
<divclass="info"markdown="1">
60
-
The simulated camera does not have `capture` or `save` methods.
42
+
<divclass="info">
43
+
Taking images while moving will cause them to be blurry, which will cause marker detection to fail.
44
+
Try pausing movement while taking an image.
61
45
</div>
62
46
63
47
save
64
48
: Take a photo through the webcam, and save it to the provided location.
Orientation information is returned in different formats between the simulator and the physical robot kits.
196
-
One (possibly both) of them may change to resolve this.
197
-
198
-
In the simulator the `roll`, `pitch` and `yaw` properties are strict aliases for the `rot_x`, `rot_y` and `rot_z` properties.
199
-
Additionally the `rotation_matrix` and `quaternion` properties are not present.
200
-
</div>
201
-
<divclass="warning"markdown="1">
202
-
There is a bug in the simulator such that the `rot_x` and `rot_z` values are not reliable -- specifically they depend on the orientation of the robot itself within the simulated environment in addition to the orientation of the marker. This is believed to be a bug in Webots simulation software.
203
-
</div>
204
-
205
-
An `Orientation` object describes the orientation of a marker.
206
-
207
-
rot_x
208
-
: Rotation of the marker about the cartesian x-axis, in radians. This is a
209
-
pitch-like rotation.
210
-
211
-
Leaning a marker towards the camera increases the value of `rot_x`, while
212
-
leaning it away from the camera decreases it. A value of either π or -π
213
-
indicates that the marker is upright (there is a discontinuity in the value
214
-
at π and -π, as both values represent the same position).
215
-
216
-
rot_y
217
-
: Rotation of the marker about the cartesian y-axis, in radians. This is a
218
-
yaw-like rotation.
219
-
220
-
Turning a marker clockwise (as viewed from above) decreases the value of
221
-
`rot_y`, while turning it anticlockwise increases it. A value of 0 means
222
-
that the marker is perpendicular to the line of sight of the camera.
223
-
224
-
rot_z
225
-
: Rotation of the marker about the cartesian z-axis, in radians. This is a
226
-
roll-like rotation.
227
-
228
-
Turning a marker anticlockwise (as viewed from the camera) increases the
229
-
value of `rot_z`, while turning it clockwise decreases it. A value of 0
230
-
indicates that the marker is upright.
231
-
232
-
There are additional attributes for the [principal axis rotations](https://en.wikipedia.org/wiki/Aircraft_principal_axes) of the marker.
233
-
234
-
yaw
235
-
: A rotation about the about the vertical axis, in radians (an axis top to
236
-
bottom through the token). Turning a marker clockwise (as viewed from above)
237
-
increases the value of `yaw`, while turning it anticlockwise decreases it. A
238
-
value of 0 means that the marker is perpendicular to the line of sight of
239
-
the camera.
240
-
241
-
This differs from `rot_y` in the direction that increases the value.
242
-
243
-
pitch
244
-
: A rotation about the transverse axis, in radians (an axis right to left
245
-
across the token). Tilting the marker backward increases the value of
246
-
`pitch`, while tilting it forwards decreases it. A value of 0 indicates that
247
-
the marker is facing the camera square-on.
248
-
249
-
This differs from `rot_x` in the zero point and direction to increase the value.
250
-
251
-
roll
252
-
: A rotation about the longitudinal axis, in radians (an axis normal from the
253
-
apparent front to the back of the token, normal to the marker). Rotating the
254
-
marker anti-clockwise (from the perspective of the camera) increases the
255
-
value of `roll`, while rotating it clockwise decreases it. A value of 0
256
-
indicates that the marker is upright.
257
-
258
-
This differs from `rot_x` in the zero point and direction to increase the value.
259
-
260
-
Finally there are attributes which express the orientation in other forms:
261
-
262
-
rotation_matrix
263
-
: The [rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix) represented by this orientation.
264
-
This 3×3 matrix is represented by a list of 3 lists, each with 3 values, in an arrangement compatible with tools such as `numpy`.
265
-
266
-
quaternion
267
-
: The [quaternion](https://en.wikipedia.org/wiki/Quaternion) represented by this orientation.
268
-
On the physical kits this is implemented as a [`pyquaternion.Quaternion`](https://kieranwynn.github.io/pyquaternion/#quaternion-features) instance.
0 commit comments