Sensors#
Introduction#
The VEX AIR Drone includes an Inertial Sensor for measuring rotational movement and for detecting changes in motion as well as a Range Sensor for detecting distances. The VEX AIR Drone can also keep track of its battery levels. These sensors allow the drone to track its orientation, heading, acceleration, and distance from objects.
Below is a list of all available blocks:
Inertial - Track the drone’s rotational movement.
rotation — Returns how much the drone has turned since it started.
heading — Returns the drone’s heading angle (0 to 359.99 degrees).
orientation — Returns the drone’s roll, pitch, or yaw (–180.00 to 180.00 degrees).
acceleration — Returns acceleration along the forward, rightward, or downward axis.
get turn rate — Returns the drone’s current rotation speed in degrees per second (dps).
reset rotation — Resets the rotation value to zero.
reset heading — Resets the heading value to zero.
Range - Detect distances from the drone’s Range Sensor.
distance — Returns the distance from a Range Sensor.
Battery - Return the drone’s battery level.
battery level — Returns the drone’s battery level in percent.
Inertial#
rotation#
The rotation block returns how many degrees the drone has turned since it started. It adds up all turns and returns the total in degrees: positive for clockwise, negative for counterclockwise.
(rotation in degrees)
Parameters |
Description |
---|---|
This block has no parameters. |
Example
when started :: hat events
[Display the rotation after turning.]
take off to [500] [mm v] ▶
turn [left v] for (450) degrees ▶
print (rotation in degrees) on console ▶
land ▶
heading#
The heading block returns the drone’s heading angle. This returns a decimal number in the range 0 to 359.99 degrees.
(heading in degrees)
Parameters |
Description |
---|---|
This block has no parameters. |
Example
when started :: hat events
[Display the rotation after turning left.]
take off to [500] [mm v] ▶
turn [left v] for (90) degrees ▶
print (heading in degrees) on screen ▶
orientation#
The orientation block returns the drone’s roll, pitch, or yaw in the range –180.00 to 180.00 degrees as a decimal number.
The image below uses arrows to show the direction of positive rotation for roll, pitch, yaw.
orientation of [roll v] in degrees
Parameters |
Description |
---|---|
axis |
The orientation axis:
|
Example
when started :: hat events
[Display the drone orientation as it is rotated by hand.]
forever
clear screen
set cursor to row (7) column (1) on screen
print [Roll:] on screen ▶
print (orientation of [roll v] in degrees) on screen ▶
end
acceleration#
The acceleration block returns the drone’s acceleration in a specified direction. The returned value represents the rate of change in velocity, measured in units of g (where 1g ≈ 9.81 m/s²), as a number ranging from -4.00 to 4.00.
The image below uses arrows to show the direction of positive acceleration for forward and rightward, and negative acceleration for downward.
(acceleration of [forward v] axis in g :: custom-controller-inertial-timer)
Parameters |
Description |
---|---|
axis |
The axis to return the acceleration of:
|
Example
when started :: hat events
[Display the acceleration as the drone takes off.]
take off to [500] mm ◀ and don't wait
forever
clear screen
set cursor to row [1] column [1] on screen
print (acceleration of [downward v] axis in g) on screen ▶
wait [0.5] seconds
end
get turn rate#
The get turn rate block returns the rate at which the drone is rotating along the specified axis. This returns a value in degrees per second (dps) as an integer.
The image below uses arrows to show the direction of positive rotation for roll, pitch, yaw.
(get turn rate of [roll v] axis in dps)
Parameters |
Description |
---|---|
axis |
The axis to return the turn rate of:
|
Example
when started :: hat events
[Display the drone turn rate as it is rotated by hand.]
forever
clear screen
set cursor to row (7) column (1) on screen
print [Roll:] on screen ▶
print (get turn rate of [roll v] axis in dps) on screen ▶
end
reset rotation#
The reset rotation block resets the drone’s rotation value to 0 degrees.
reset rotation
Parameters |
Description |
---|---|
This block has no parameters. |
Example
when started :: hat events
[Display the rotation after resetting.]
take off to [500] [mm v] ▶
turn [right v]
wait until <(rotation in degrees) [math_greater_than v] [360]>
hover
reset rotation
wait [1] seconds
print (rotation in degrees) on console ▶
reset heading#
The reset heading block resets the drone’s heading to zero degrees.
reset heading
Parameters |
Description |
---|---|
This block has no parameters. |
Example
when started :: hat events
[Turn to the same heading before and after resetting.]
take off to [500] [mm v] ▶
turn to heading [90] degrees ▶
wait [1] seconds
reset heading
turn to heading [90] degrees ▶
wait [1] seconds
land ▶
Range#
distance#
The distance block returns the distance between a Range Sensor and the nearest object.
(distance [forward v] range in [mm v])
Parameters |
Description |
---|---|
range |
The Range Sensor to use:
|
units |
The unit that represents the distance:
|
Example
when started :: hat events
[Hover at 200 mm.]
take off to [500] [mm v] ▶
climb [down v]
wait until <(distance [downward v] range in [mm v]) [math_less_than v] [200]>
hover
wait (3) seconds
land ▶
Battery#
battery level#
The battery level block returns the drone’s battery charge level as a percentage. This returns a number from 0 to 100.
(drone battery level in %)
Parameters |
Description |
---|---|
This block has no parameters. |
when started :: hat events
[Display the battery level.]
print (drone battery level in %) on screen ▶