Sensors#

Introduction#

The VEX AIR Hornet 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 Hornet can also keep track of its battery levels. These sensors allow the Hornet to track its orientation, heading, acceleration, and distance from objects.

Below is a list of all available blocks:

Inertial - Track the Hornet’s rotational movement,

  • rotation – Returns how much the Hornet has turned since it started.

  • heading – Returns the Hornet’s heading angle (0 to 359.99 degrees).

  • orientation – Returns the Hornet’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 Hornet’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 Hornet’s Range Sensor.

  • distance – Returns the distance from a Range Sensor.

Battery - Detect the Hornet’s battery percentage.

  • battery level – Returns the Hornet’s battery level in percent.

Inertial#

rotation#

The rotation block returns how much the Hornet has turned since it started. It adds up all turns and returns the total in degrees: positive for clockwise, negative for counterclockwise.

The Rotation reporter block.#
    (rotation in degrees)

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Display the rotation while turning.]
    take off to [500] mm ▶
    turn [right v] for (480) degrees ◀ and don't wait
    forever
    clear screen
    set cursor to row (1) column (1) on screen
    print (rotation in degrees) on screen ▶
    wait (0.05) seconds

heading#

The heading block returns the Hornet’s heading angle. This returns a decimal number in the range 0 to 359.99 degrees.

The Heading reporter block.#
    (heading in degrees)

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Display the heading while turning.]
    take off to [500] mm ▶
    turn [right v] for (480) degrees ◀ and don't wait
    forever
    clear screen
    set cursor to row (1) column (1) on screen
    print (heading in degrees) on screen ▶
    wait (0.05) seconds

orientation#

The orientation block returns the Hornet’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.

A VEX Hornet 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.

The Orientation reporter block.#
    orientation of [roll v] in degrees

Parameters

Description

axis

The orientation axis:

  • roll
  • pitch
  • yaw

Example

    [Display the orientation while controlling the Hornet.]
    take off to [500] mm ▶
    forever
    move with controller
    clear screen
    set cursor to row (1) column (1) on screen
    print (orientation of [roll v] in degrees) on screen ▶
    wait (0.05) seconds

acceleration#

The acceleration block returns the Hornet’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.

A VEX Hornet 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.

The Acceleration reporter block.#
    (acceleration of [forward v] axis in g :: custom-controller-inertial-timer)

Parameters

Description

axis

The axis to return the acceleration of:

  • forward
  • rightward
  • downward

Example

    when started :: hat events
    [Display the acceleration before and while moving.]
    take off to [500] mm ▶
    print (join [Resting: ] (acceleration of [forward v] axis in g)) on screen ▶
    set cursor to next row on screen
    wait (0.5) seconds
    move [forward v] for (100) [mm v] ◀ and don't wait
    wait (0.1) seconds
    print (join [Startup: ] (acceleration of [forward v] axis in g)) on screen ▶
    forever
    wait (0.1) seconds

get turn rate#

The get turn rate block returns the rate at which the Hornet 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.

A VEX Hornet 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.

The Get Turn Rate reporter block.#
    (get turn rate of [roll v] axis in dps)

Parameters

Description

axis

The axis to return the turn rate of:

  • roll
  • pitch
  • yaw

Example

    when started :: hat events
    [Observe the yaw rate as the Hornet turns.]
    take off to [500] mm ▶
    turn [right v] for (180) degrees ◀ and don't wait
    forever
    clear screen
    set cursor to row (1) column (1) on screen
    print (get turn rate of [yaw v] axis in dps) on screen ▶

reset rotation#

The reset rotation block resets the Hornet’s rotation value to 0 degrees.

The Reset rotation stack block.#
    reset rotation

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Turn and track rotation before resetting.]
    take off to [500] mm ▶
    turn [right v] for (480) degrees ▶
    reset rotation

    when started :: hat events
    forever
    clear screen
    set cursor to row (1) column (1) on screen
    print (rotation in degrees) on screen ▶
    wait (0.1) seconds

reset heading#

The reset heading block resets the Hornet’s heading to zero degrees.

The Reset heading stack block.#
    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 ▶
    turn to heading (90) degrees ▶
    wait (1) seconds
    reset heading
    turn to heading (90) degrees ▶

Range#

distance#

The distance block returns the distance between a Range Sensor and the nearest object.

move forward stack block#
    (distance [forward v] range in [mm v])

Parameters

Description

range

The Range Sensor to use:

  • forward – The distance from the front of the Hornet.
  • downward – The distance from the bottom of the Hornet.

units

The unit that represents the distance:

  • mm (millimeters)
  • inches

Example

    when started :: hat events
    [Fly forward until close to an object.]
    take off to [500] mm ▶
    move [forward v]
    wait until <(distance [forward v] range in [mm v]) [< v] [75]>
    land ▶

Battery#

battery level#

The battery level block returns the Hornet’s battery charge level as a percentage. This returns a number from 0 to 100.

The battery level in percent reporter block.#
  (drone battery level in %)

Parameters

Description

This block has no parameters.

A stack of blocks that begins with a when started block, followed by a comment block reading Get the battery level and display it. A print block then displays the battery level percentage on the screen.#
  when started :: hat events
  [Display the battery level.]
  print (drone battery level in %) on screen ▶