Robot Vision & Markers
Computer Vision allows your robot to understand its environment. In competition, this is primarily used to detect AprilTag markers placed around the arena. From these markers, your robot can determine distance, angle, and marker type.
Vision Overview
Vision is accessed through the robot API using the see() method.
This returns a list of detected markers currently visible to the robot’s camera.
Seeing Markers
import robot
R = robot.Robot()
markers = R.see()
print(markers)
markers is a Python list of marker objects. Each object represents
a single detected marker and contains information such as distance, bearing,
and classification.
Useful Properties
| Property | Description |
|---|---|
marker.dist | Distance to the marker in metres |
marker.bearing.y | Angle the robot must turn to face the marker (degrees) |
marker.info.id | Numeric ID of the marker |
marker.info.type | ARENA or TARGET |
marker.info.target_type | Supply crate, supply drop, or NONE |
You generally do not need to use raw marker IDs in your logic. Instead,
rely on marker.info.type and marker.info.target_type
to determine how your robot should react.
Marker Codes
| Marker Type | Code Range |
|---|---|
| Supply crates | 0 – 23 |
| Supply drops | 24 – 31 |
| Trees | 76 – 91 |
| Arena wall markers | 100 – 123 |
Worked Example
The following example shows a simple strategy: look for markers, turn to face them, and drive towards them. If no marker is visible, the robot rotates slightly and checks again.
import robot
R = robot.Robot()
def move(distance):
"""Drive the robot forwards by `distance` metres"""
print("PUT YOUR MOVE CODE HERE")
def turn(rotation):
"""Turn the robot by `rotation` degrees"""
print("PUT YOUR TURN CODE HERE")
while True:
for marker in R.see():
turn(marker.bearing.y)
move(marker.dist)
else:
turn(20)
The Marker Object
Each detected marker contains a rich set of attributes describing its position, orientation, and classification. All axes are defined relative to the camera, not the robot chassis.
markers = R.see()
for marker in markers:
print(marker.dist)
print(marker.bearing.y)
print(marker.info.id)
You can also use constants provided by the robot library to cleanly identify marker types.
import robot
R = robot.Robot()
for marker in R.see():
if marker.info.type == robot.MARKER_TYPE.TARGET \
and marker.info.target_type == robot.TARGET_TYPE.SUPPLY_DROP:
print(f"Marker {marker.info.id} is a supply drop")
elif marker.info.target_type == robot.TARGET_TYPE.SUPPLY_CRATE:
print(f"Marker {marker.info.id} is a supply crate")