Inertial#

Introduction#

The VEX IQ (2nd gen) Brain includes a built-in 3-axis gyroscope for measuring rotational movement and a 3-axis accelerometer for detecting changes in motion. These sensors allow the robot to track its orientation, heading, and acceleration. Below is a list of all available blocks, grouped by functionality:

Gyro Sensing – Work with heading and rotation tracking.

Inertial Sensing – Use the accelerometer in the Inertial Sensor.

  • acceleration – Reports linear acceleration along the x, y, or z axis.

  • gyro rate – Reports angular velocity around the x, y, or z axis.

  • orientation – Reports roll, pitch, or yaw based on tilt and rotation.

Gyro Sensing#

calibrate gyro#

The calibrate gyro block calibrates a Gyro Sensor. All subsequent blocks will wait for the calibration to complete before executing. Calibration is an internal procedure that measures and compensates for sensor noise and drift over a specified period. During this time, the Gyro Sensor must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.

    calibrate [Gyro1 v] for [2 v] seconds

Parameters

Description

gyro

The Gyro Sensor to calibrate, configured in the Devices window.

duration

How long to calibrate the sensor for in seconds, which can be one of the following:

  • 2
  • 4
  • 8

Example

    when started :: hat events
    [Calibrate a Gyro Sensor and display its angle of heading.]
    calibrate [Gyro1 v] for [2 v] seconds
    print ([Gyro1 v] heading in degrees) on [Brain v] ◀ and set cursor to next row

calibrate BrainInertial#

The calibrate BrainInertial block calibrates the Brain’s built-in Inertial Sensor. All subsequent blocks will wait for the calibration to complete before executing. Calibration is an internal procedure that measures and compensates for sensor noise and drift over a specified period. During this time, the Brain must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.

../../_images/IQ_right_orientation.png../../_images/IQ_left_orientation.png../../_images/IQ_top_orientation.png

VEX brains attempt to calibrate themselves automatically at the start of every project. However, if the robot is being carried or moved during project start, the sensor may fail to calibrate properly or yield incorrect calibration.

    calibrate BrainInertial

Parameters

Description

This block has no parameters.

Example

    when started :: hat events
    [Calibrate the Brain's sensor and display its angle of heading.]
    calibrate BrainInertial
    print ([BrainInertial v] heading in degrees) on [Brain v] ◀ and set cursor to next row

set heading#

The set heading block sets the Gyro Sensor’s heading to a specified value.

    set [Gyro1 v] heading to (0) degrees

Parameters

Description

gyro

The Gyro Sensor to calibrate, configured in the Devices window.

heading

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

Example

    when started :: hat events
    [Turn to the new 0 degrees heading.]
    set [Gyro1 v] heading to (90) degrees
    turn to heading (0) degrees ▶

set rotation#

The set rotation block sets the Gyro Sensor’s heading to a specified value.

    set [Gyro1 v] rotation to (0) degrees

Parameters

Description

gyro

The Gyro Sensor to calibrate, configured in the Devices window.

rotation

The value to use for the new rotation.

Example

    when started :: hat events
    [Turn to the new 0 rotation.]
    set [Gyro1 v] rotation to (-100) degrees
    turn to rotation (0) degrees ▶

angle of heading#

The angle of heading block returns the Gyro Sensor’s heading angle as a decimal number, in the range 0 to 359.99 degrees.

    ([Gyro1 v] heading in degrees)

Parameters

Description

gyro

The Gyro Sensor to calibrate, configured in the Devices window.

Example

    when started :: hat events
    [Display the Gyro Sensor's heading before and after rotating.]
    print ([Gyro1 v] heading in degrees) on [Brain v] ◀ and set cursor to next row
    turn [right v] for (390) degrees ▶
    print ([Gyro1 v] heading in degrees) on [Brain v] ◀ and set cursor to next row

angle of rotation#

The angle of rotation block returns how much the Gyro Sensor has turned since it started, in degrees: positive for clockwise, negative for counterclockwise.

    ([Gyro1 v] rotation in degrees)

Parameters

Description

gyro

The Gyro Sensor to calibrate, configured in the Devices window.

Example

    when started :: hat events
    [Display the Gyro Sensor's angle of rotation before and after rotating.]
    print ([Gyro1 v] rotation in degrees) on [Brain v] ◀ and set cursor to next row
    turn [right v] for (390) degrees ▶
    print ([Gyro1 v] rotation in degrees) on [Brain v] ◀ and set cursor to next row

rate of gyro#

The rate of gyro block returns the Gyro Sensor’s current rotation speed in dps.

    ([Gyro1 v] rate in dps)

Parameters

Description

gyro

The Gyro Sensor to calibrate, configured in the Devices window.

Example

    when started :: hat events
    [Display the Gyro Sensor's current rotation speed.]
    turn [right v]
    wait (1) seconds
    print ([Gyro1 v] rate in dps) on [Brain v] ◀ and set cursor to next row

Inertial Sensing#

acceleration#

The acceleration block returns the Brain’s acceleration along the specified axis (forward, rightward, or downward) in units of g, ranging from -4.00 to 4.00.

    (BrainInertial acceleration of [x v] axis in g)

Parameters

Description

axis

The axis to return the acceleration of:

  • x
  • y
  • z

Example

    when started :: hat events
    [Display the X-axis acceleration while the Drivetrain is moving.]
    set print precision to [0.01 v] on [Brain v]
    set drive velocity to (100) %
    print [Resting: ] on [Brain v] ◀ and set cursor to next row
    print (BrainInertial acceleration of [x v] axis in g) on [Brain v] ◀ and set cursor to next row
    wait (1) seconds
    drive [forward v] for (500) [mm v] ◀ and don't wait
    wait (0.1) seconds
    print [Startup : ] on [Brain v] ◀ and set cursor to next row
    print (BrainInertial acceleration of [x v] axis in g) on [Brain v] ◀ and set cursor to next row

gyro rate#

The gyro rate block returns the Brain’s current rotation speed in dps.

    (BrainInertial gyro rate of [x v] axis in dps)

Parameters

Description

axis

The axis to return the rotational speed of:

  • x
  • y
  • z

Example

    when started :: hat events
    [Display the Y-axis gyro rate while the Drivetrain is turning.]
    turn [right v]
    wait (1) seconds
    print (BrainInertial gyro rate of [z v] axis in dps) on [Brain v] ◀ and set cursor to next row

orientation#

The orientation block returns the Brain’s roll, pitch, or yaw, in the range of -180.00 to 180.00 degrees as a decimal number.

    (BrainInertial orientation of [roll v] in degrees)

Parameters

Description

axis

The orientation axis:

  • roll
  • pitch
  • yaw

Example

    when started :: hat events
    [Display the roll, pitch, and yaw of the Brain as it is rotated by hand.]
    forever
    clear all rows on [Brain v]
    print (BrainInertial orientation of [roll v] in degrees) on [Brain v] ◀ and set cursor to next row
    print (BrainInertial orientation of [pitch v] in degrees) on [Brain v] ◀ and set cursor to next row
    print (BrainInertial orientation of [yaw v] in degrees) on [Brain v] ◀ and set cursor to next row
    set cursor to row (1) column (1) on [Brain v]
    wait (0.05) seconds
    end