Gyro Sensor#

Introduction#

The VEX IQ Gyro Sensor measures rotational movement around a single axis. It is used to track how far a robot has turned and which direction it is facing.

Below is a list of all blocks:

calibrate gyro#

The calibrate gyro stack block calibrates a configured Gyro Sensor.

Calibration helps the Gyro Sensor measure turns correctly. Keep the sensor still during calibration. If the sensor moves during calibration, heading, rotation, and rate values may not measure turns correctly.

The project will wait until calibration is done before the next block in the stack runs.

Note: This block is only available if there is a configured Gyro Sensor outside of a drivetrain.

    calibrate [Gyro1 v] for [2 v] seconds

Parameters

Description

gyro

The Gyro Sensor to calibrate.

duration

How long to calibrate the sensor for in seconds:

  • 2
  • 4
  • 8

Example

    when started
    [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

set Gyro heading#

A heading is the direction the sensor is facing, measured in degrees from 0 to 359.99. The set Gyro heading stack block changes the Gyro Sensor’s current heading to a new heading value.

For example, if the sensor has turned to face right, setting the heading to 0 degrees makes that right-facing position the new 0 degrees. Then the sensor can track other headings based on that new direction.

    set [Gyro1 v] heading to (0) degrees

Parameters

Description

gyro

The Gyro Sensor to use.

heading

The heading value, in degrees, to set for the sensor. This can be a value from 0 to 359.99.

Example

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

set Gyro rotation#

Rotation is how much the sensor has turned, measured in degrees. Unlike heading, rotation can increase past 359.99 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. The set Gyro rotation stack block changes the Gyro Sensor’s current rotation to a new value.

For example, if the sensor has made two full turns to the right, its rotation value will be 720 degrees. Setting the rotation to 0 degrees will reset that rotation from 720 to 0 degrees. Then the sensor can track rotations based on that new value.

    set [Gyro1 v] rotation to (0) degrees

Parameters

Description

gyro

The Gyro Sensor to use.

rotation

The rotation value, in degrees, to set for the sensor. This can be an integer or a decimal.

Example

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

angle of Gyro heading#

A heading is the direction the sensor is facing, measured in degrees from 0 to 359.99. The angle of Gyro heading reporter block reports the Gyro Sensor’s current heading.

The starting heading is 0 degrees. If the sensor turns past 359.99 degrees, the heading wraps back to 0 degrees.

    ([Gyro1 v] heading in degrees)

Parameters

Description

gyro

The Gyro Sensor to report the heading from.

Example

    when started
    [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 Gyro rotation#

Rotation is how much the sensor has turned, measured in degrees. Unlike heading, rotation can increase past 359.99 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. The angle of Gyro rotation reporter block reports the Gyro Sensor’s current rotation.

Turning right increases the rotation, and turning left decreases the rotation. For example, making two full turns to the right will report a rotation of 720 degrees. Turning one full turn to the left from 0 degrees will report a rotation of -360 degrees.

    ([Gyro1 v] rotation in degrees)

Parameters

Description

gyro

The Gyro Sensor to report the rotation from.

Example

    when started
    [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 reporter block reports the Gyro Sensor’s current rotation speed in degrees per second (dps). The value can be positive or negative depending on the direction the Gyro Sensor is rotating.

    ([Gyro1 v] rate in dps)

Parameters

Description

gyro

The Gyro Sensor to report the rotation speed from.

Example

    when started
    [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