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 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 methods:

Inertial - Track the drone’s rotational movement,

  • get_rotation – Returns how much the drone has turned since it started.

  • get_heading – Returns the current heading (0 to 359.99°).

  • get_yaw – Returns the yaw angle (–180 to 180°).

  • get_roll – Returns the roll angle (–180 to 180°).

  • get_pitch – Returns the pitch angle (–90 to 90°).

  • reset_rotation – Resets the rotation value to 0.

  • reset_heading – Sets the current heading to 0.

  • set_heading – Sets the heading to a specific value.

  • get_acceleration – Returns acceleration in a specific direction.

  • get_turn_rate – Returns turning rate in degrees per second.

Range - Detect distances from the drone’s Range Sensor.

  • get_distance – Returns the distance from a Range Sensor.

Battery - Detect the drone’s battery percentage.

Inertial#

get_rotation#

get_rotation returns the drone’s net rotation in degrees as a float.

Usage:
drone.inertial.get_rotation()

Parameters

Description

This method has no parameters.

# Display the rotation while rotating
drone.take_off(500)
drone.turn_for(480, 0, wait=False)

while True:
    controller.screen.clear_screen()
    controller.screen.set_cursor(1, 1)
    controller.screen.print("Rotation value: {}".format(drone.inertial.get_rotation()))
    wait(0.1, SECONDS)

get_heading#

get_heading returns the drone’s heading angle as a float in the range 0 to 359.99 degrees.

Usage:

drone.inertial.get_heading()

Parameters

Description

This method has no parameters.

# Display the heading while rotating
drone.take_off(500)
drone.turn_for(480, 0, wait=False)

while True:
    controller.screen.clear_screen()
    controller.screen.set_cursor(1, 1)
    controller.screen.print("Heading value: {}".format(drone.inertial.get_heading()))
    wait(0.1, SECONDS)

get_yaw#

get_yaw returns the drone’s yaw angle in the range –180.00 to 180.00 degrees as a float.

The image below uses arrows to show the direction of positive rotation for yaw.

A VEX drone is shown with one labeled colored arrow indicating its yaw. A  blue arrow labeled Yaw points directly downward from the center.

Usage:

drone.inertial.get_yaw()

Parameters

Description

This method has no parameters.

# Display the yaw while flying the drone with the controller
drone.take_off(500)

while True:
    # Move with the controller
    drone.move_with_vectors(
        controller.axis4.position(),
        controller.axis3.position(),
        controller.axis1.position(),
        controller.axis2.position()
    )
    controller.screen.clear_screen()
    controller.screen.set_cursor(1, 1)
    controller.screen.print("Yaw: {}".format(drone.inertial.get_yaw()))
    wait(0.1, SECONDS)

get_roll#

get_roll returns the drone’s roll angle in the range –180.00 to 180.00 degrees as a float.

The image below uses arrows to show the direction of positive rotation for roll.

A VEX drone is shown with one labeled colored arrow indicating its roll. A green arrow labeled Roll points diagonally downward to the right.

Usage:

drone.inertial.get_roll()

Parameters

Description

This method has no parameters.

# Display the roll while flying the drone with the controller
drone.take_off(500)

while True:
    # Move with the controller
    drone.move_with_vectors(
        controller.axis4.position(),
        controller.axis3.position(),
        controller.axis1.position(),
        controller.axis2.position()
    )
    controller.screen.clear_screen()
    controller.screen.set_cursor(1, 1)
    controller.screen.print("Roll: {}".format(drone.inertial.get_roll()))
    wait(0.1, SECONDS)

get_pitch#

get_pitch returns the drone’s pitch angle in the range –90.00 to 90.00 degrees as a float.

The image below uses arrows to show the direction of positive rotation for pitch.

A VEX drone is shown with one labeled colored arrow indicating its pitch. A red arrow labeled Pitch points diagonally downward to the left.

Usage:

drone.inertial.get_pitch()

Parameters

Description

This method has no parameters.

# Display the pitch while flying the drone with the controller
drone.take_off(500)

while True:
    # Move with the controller
    drone.move_with_vectors(
        controller.axis4.position(),
        controller.axis3.position(),
        controller.axis1.position(),
        controller.axis2.position()
    )
    controller.screen.clear_screen()
    controller.screen.set_cursor(1, 1)
    controller.screen.print("Pitch: {}".format(drone.inertial.get_pitch()))
    wait(0.1, SECONDS)

reset_rotation#

reset_rotation resets the drone’s rotation value to 0.

Usage:
drone.inertial.reset_rotation()

Parameters

Description

This method has no parameters.

# Turn and track rotation before and after resetting
drone.take_off(500)
drone.turn_for(480, 0, wait=False)

while drone.is_turn_active():
    controller.screen.clear_screen()
    controller.screen.next_row()
    controller.screen.print("Rotation value: {}".format(drone.inertial.get_rotation()))
    wait(0.1, SECONDS)

controller.screen.print("After resetting: ")
drone.inertial.reset_rotation()
controller.screen.print(drone.inertial.get_rotation())

reset_heading#

reset_heading resets the drone’s heading to 0 degrees.

Usage:

drone.inertial.reset_heading()

Parameters

Description

This method has no parameters.

# Turn to the same heading before and after resetting
drone.take_off(500)
drone.turn_to(90, 0)
wait(1, SECONDS)
drone.inertial.reset_heading()
drone.turn_to(90, 0)

set_heading#

set_heading sets the drone’s heading to a specified value.

Usage:

drone.inertial.set_heading(heading)

Parameters

Description

heading

The value to use for the new heading in the range 0 to 359.99 degrees.

# Turn left
drone.take_off(500)
drone.inertial.set_heading(90)
drone.turn_to(0, 0)

get_acceleration#

get_acceleration 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 float ranging from -4.00 to 4.00.

A VEX drone is shown with three labeled colored arrows indicating direction. A red arrow labeled RIGHTWARD points diagonally downward to the left, a green arrow labeled FORWARD points diagonally downward to the right, and a blue arrow labeled DOWNWARD points directly downward from the center.

Usage:

drone.inertial.get_acceleration(type)

Parameters

Description

type

The direction of acceleration to report:

  • DOWNWARD – Acceleration affecting the drone’s vertical movement.
  • FORWARD – Acceleration affecting the drone’s movement along its front-to-back direction.
  • RIGHTWARD – Acceleration affecting the drone’s movement along its side-to-side direction.
  • # Display the acceleration before and while moving.
    drone.take_off(500)
    controller.screen.print("Resting: {}".format(drone.inertial.acceleration(FORWARD)))
    controller.screen.next_row()
    wait(0.5, SECONDS)
    drone.move_for(0, 100, 0, MM, wait=False)
    wait(0.1, SECONDS)
    controller.screen.print("Startup: {}".format(drone.inertial.acceleration(FORWARD)))
    
    

    get_turn_rate#

    get_turn_rate returns the drone’s turning rate for a given orientation in degrees per second (dps). It returns a float from –1000.00 to 1000.00 dps.

    The image below uses arrows to show the direction of positive rotation for roll, pitch, and yaw.

    A VEX drone is shown with three labeled colored arrows indicating its rotational axes. A red arrow labeled Pitch points diagonally downward to the left, a green arrow labeled Roll points diagonally downward to the right, and a blue arrow labeled Yaw points directly downward from the center.

    Usage:

    drone.inertial.get_turn_rate(axis)

    Parameters

    Description

    axis

    Which orientation to report:

    • YAW
    • ROLL
    • PITCH

    # Display the yaw rate as the drone turns
    drone.take_off(500)
    drone.turn_for(180, 0, wait=False)
    while True:
        controller.screen.clear_screen()
        controller.screen.set_cursor(1, 1)
        controller.screen.print(drone.inertial.get_turn_rate(YAW))
    
    

    Range#

    get_distance#

    get_distance returns the distance between a Range Sensor and the nearest object.

    Usage:

    drone.range.get_distance(range, units)

    Parameters

    Description

    range

    The Range Sensor to use:

    • FORWARD_RANGE – The distance from the front of the drone.
    • DOWNWARD_RANGE – The distance from the bottom of the drone.

    units

    Optional. The unit that represents the distance:

    • DistanceUnits.CM – Centimeters
    • MM (default) – Millimeters
    • INCHES
    # Fly forward until close to an object
    drone.take_off(500)
    drone.move_at(0, 50)
    while not drone.range.get_distance(FORWARD_RANGE, MM) < 75:
        wait(0.1, SECONDS)
    drone.land()
    
    

    Battery#

    get_battery_level#

    get_battery_level returns the drone’s battery charge level as a percentage. This returns a number from 0 to 100.

    Usage:
    drone.get_battery_level()

    Parameters

    Description

    This method has no parameters.

    # Display the drone's battery level
    if drone.get_battery_level() < 25:
        controller.screen.print("Charge the drone Battery!")
    else:
        controller.screen.print("Ready to fly!")