Vision#
Introduction#
The VEX AIR Drone has two Vision Sensors that detect and track AprilTag IDs. These allow the drone to analyze its surroundings, follow objects, and react based on detected visual data.
Below is a list of all available blocks:
Actions — Control the Vision feed and capture object data.
get object data — Captures data for AprilTag IDs.
Settings — Adjust which detected objects are accessed.
set Vision object item — Selects a specific object from the detected object list.
Values — Retrieve object presence, classification, and properties.
Vision object exists — Reports whether an object is detected.
Vision object is AprilTag ID — Checks if a detected AprilTag ID matches a specific ID.
Vision object count — Reports the number of detected objects.
Vision object property — Retrieves details such as:
centerX & centerY — Center position coordinates in the sensor’s view.
bearing — Angle of the object relative to the front Vision Sensor or the degrees needed for the drone to face the object.
rotation — Orientation of the object.
originX & originY — Top-left corner position coordinates in the sensor’s view.
id — Identification number of an AprilTag ID.
Actions#
get object data#
The get object data stack block filters data from the Vision Sensor’s frame. The Vision Sensors can detect AprilTag IDs.
The dataset stores objects ordered from largest to smallest by width, starting at index 0. Each object’s properties can be accessed using the Vision object property block. An empty dataset is reported if no matching objects are detected.
get [all AprilTags v] data from Vision [forward v] camera
Parameter |
Description |
|---|---|
signature |
Filters the dataset to only include data of the given signature. The available signature is all AprilTags. |
camera |
The Vision Sensor to retrieve data from, either forward or downward. |
Example
when started
[Climb upward when an AprilTag ID is detected.]
take off to [300] [mm v] ▶
forever
get [all AprilTags v] data from Vision [forward v] camera
if <Vision object exists?> then
climb [up v] for [200] [mm v] ▶
Settings#
set Vision object item#
The set Vision object item stack block sets which item in the dataset to use.
set Vision object item to [1]
Parameters |
Description |
|---|---|
item |
The number of the item in the dataset to use. |
Example
when started
[Display the smallest-appearing AprilTag ID.]
forever
get [all AprilTags v] data from Vision [forward v] camera
clear console
if <Vision object exists?> then
set Vision object item to (Vision object count)
print (Vision object [id v]) on console ▶
Values#
Vision object exists#
The Vision object exists Boolean block reports whether the specified Vision Sensor currently detects any objects.
True — The specified Vision Sensor detects an object.
False — The specified Vision Sensor does not detect an object.
<Vision object exists?>
Parameter |
Description |
|---|---|
This block has no parameters. |
Example
when started
[Climb upward when an AprilTag ID is detected.]
take off to [300] [mm v] ▶
forever
get [all AprilTags v] data from Vision [forward v] camera
if <Vision object exists?> then
climb [up v] for [200] [mm v] ▶
Vision object is AprilTag ID#
The Vision object is AprilTag ID Boolean block reports whether the AprilTag ID is a specific ID number.
True — The AprilTag ID is the number.
False — The AprilTag ID is not the number.
<Vision object is AprilTag ID [1]>
Parameters |
Description |
|---|---|
AprilTag ID number |
The number to compare against the detected AprilTag ID number from 0 to 37. |
Example
when started
[Display when the target AprilTag ID is detected.]
forever
get [all AprilTags v] data from Vision [forward v] camera
clear console
if <Vision object exists?> then
if <Vision object is AprilTag ID [21]> then
print [Target found!] on console ▶
end
Vision object count#
The Vision object count reporter block reports the amount of detected objects in the dataset as a whole number.
(Vision object count)
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started
[Display how many AprilTag IDs are detected.]
forever
get [all AprilTags v] data from Vision [forward v] camera
clear console
print (Vision object count) on console ▶
wait [0.2] seconds
Vision object property#
There are multiple properties that are included with each object (shown below) stored after the get object data block is used.
(Vision object [width v])
All property values except id describe the detected object’s position, size, orientation, or bearing at the moment the get object data block was used. These values are measured in pixels or degrees. Each Vision Sensor has a different resolution:
Forward-facing: 640 x 480 pixels
Downward-facing: 640 x 400 pixels
Parameter |
Description |
|---|---|
property |
Which property of the detected object to use: |
width#
The width property reports the width of the detected object in pixels as a whole number from 1 to 640.
(Vision object [width v])
Example
when started
[Show if the AprilTag ID appears large or small.]
forever
get [all AprilTags v] data from Vision [forward v] camera
clear console
if <Vision object exists?> then
if <(Vision object [width v]) [math_greater_than v] [100]> then
print [Large] on console ▶
else
print [Small] on console ▶
end
end
wait [0.2] seconds
height#
The height property reports the height of the detected object in pixels as a whole number from 1 to 480.
(Vision object [height v])
Example
when started
[Show if the AprilTag ID appears large or small.]
forever
get [all AprilTags v] data from Vision [forward v] camera
clear console
if <Vision object exists?> then
if <(Vision object [height v]) [math_greater_than v] [100]> then
print [Large] on console ▶
else
print [Small] on console ▶
end
end
wait [0.2] seconds
centerX#
The centerX property reports the x-coordinate of the center of the detected object in pixels as a whole number from 1 to 640.
(Vision object [centerX v])
Example
when started
[Show if an AprilTag ID is to the left or the right of the camera.]
forever
get [all AprilTags v] data from Vision [forward v] camera
clear console
if <Vision object exists?> then
if <(Vision object [centerX v]) [math_less_than v] [320]> then
print [To the left] on console ▶
else
print [To the right] on console ▶
end
end
wait [0.2] seconds
centerY#
The centerY property reports the y-coordinate of the center of the detected object in pixels as a whole number from 1 to 480.
(Vision object [centerY v])
Example
when started
[Take off and attempt to align the drone with an AprilTag ID on the wall.]
[Adjust the takeoff height to observe different results.]
take off to [800] [mm v] ▶
get [all AprilTags v] data from Vision [forward v] camera
if <Vision object exists?> then
if <(Vision object [centerY v]) [math_less_than v] [240]> then
print [Below the target!] on console ▶
else
print [Above the target!] on console ▶
end
else
print [No target found!] on console ▶
bearing#
The bearing property reports an angle indicating an object’s position relative to the drone. The behavior depends on which Vision Sensor is used.
A value of 0° indicates the center of the object and sensor are aligned. Positive values mean the object is to the right, while negative values mean the object is to the left.
Sensor |
Returns |
|---|---|
Downward |
Degrees the front of the drone must turn to align with the center of the object, from –180º to 180º. |
Forward |
Degrees the object is offset to the left or right of the Vision Sensor’s center from –180º to 180º. |
(Vision object [bearing v])
Examples
when started
[Align the front of the drone to an AprilTag ID.]
set turn velocity to (15) %
take off to [500] [mm v] ▶
forever
get [all AprilTags v] data from Vision [downward v] camera
if <Vision object exists?> then
if <[-20] [math_less_than v] (Vision object [bearing v]) [math_less_than v] [20]> then
[Hover once sensor is centered on the AprilTag ID.]
hover
play sound [success v] ▶
else if <(Vision object [bearing v]) [math_less_than v] [-21]> then
turn [left v]
else
turn [right v]
rotation#
The rotation property reports the orientation of the detected AprilTag ID as a whole number in degrees from 1 to 359.
(Vision object [rotation v])
Example
when started
[Turn left or right based on the rotation of an AprilTag ID.]
take off to [1000] [mm v] ▶
forever
get [all AprilTags v] data from Vision [forward v] camera
if <Vision object exists?> then
if <[240] [math_less_than v] (Vision object [rotation v]) [math_less_than v] [300]> then
turn [left v] for [90] degrees ▶
else if <[60] [math_less_than v] (Vision object [rotation v]) [math_less_than v] [120]> then
turn [right v] for [90] degrees ▶
else
hover
originX#
The originX property reports the x-coordinate of the top-left corner of the detected object’s bounding box in pixels as a whole number from 1 to 640.
(Vision object [originX v])
Example
when started
[Draw lines to the AprilTag ID origin from all corners.]
forever
clear screen
get [all AprilTags v] data from vision [forward v] camera
if <Vision object exists?> then
draw line [0] [0] (Vision object [originX v]) (Vision object [originY v]) on screen
draw line [0] [480] (Vision object [originX v]) (Vision object [originY v]) on screen
draw line [640] [0] (Vision object [originX v]) (Vision object [originY v]) on screen
draw line [640] [480] (Vision object [originX v]) (Vision object [originY v]) on screen
end
wait [0.2] seconds
originY#
The originY property reports the y-coordinate of the top-left corner of the detected object’s bounding box in pixels as a whole number from 1 to 480.
(Vision object [originY v])
Example
when started
[Draw lines to the AprilTag ID origin from all corners.]
forever
clear screen
get [all AprilTags v] data from vision [forward v] camera
if <Vision object exists?> then
draw line [0] [0] (Vision object [originX v]) (Vision object [originY v]) on screen
draw line [0] [480] (Vision object [originX v]) (Vision object [originY v]) on screen
draw line [640] [0] (Vision object [originX v]) (Vision object [originY v]) on screen
draw line [640] [480] (Vision object [originX v]) (Vision object [originY v]) on screen
end
wait [0.2] seconds
id#
The id property reports the identification number of the detected AprilTag ID as a whole number.
(Vision object [id v])
Example
when started
[Display the detected AprilTag ID.]
forever
get [all AprilTags v] data from Vision [forward v] camera
clear console
if <Vision object exists?> then
print (Vision object [id v]) on console ▶
end
wait [0.2] seconds