Inertial and Gyro Sensor#
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 blocks are also available with an external Gyro Sensor. These sensors allow the robot to track its orientation, heading, and acceleration.
Below is a list of all blocks:
Gyro Sensing — Work with heading and rotation tracking.
calibrate gyro — Calibrates an external Gyro Sensor for stable heading tracking.
calibrate BrainInertial — Calibrates the brain’s built-in Inertial Sensor for stable heading tracking.
set Inertial/Gyro heading — Sets the sensor’s heading to a specified value.
set Inertial/Gyro rotation — Sets the sensor’s rotation value.
angle of Inertial/Gyro heading — Returns the sensor’s current heading.
angle of Inertial/Gyro rotation — Returns the sensor’s cumulative rotation.
rate of gyro — Returns the angular velocity.
Inertial Sensing — Use the accelerometer in the Inertial Sensor.
acceleration — Returns linear acceleration along the x, y, or z axis.
gyro rate — Returns angular velocity around the x, y, or z axis.
orientation — Returns 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:
|
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
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.
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
[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 Inertial/Gyro heading#
The set Inertial/Gyro heading block sets the Gyro Sensor’s heading to a specified value.
set [Gyro1 v] heading to (0) degrees
Parameters |
Description |
|---|---|
gyro |
The Inertial or Gyro Sensor to set the heading of, 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
[Turn to the new 0 degrees heading.]
set [Gyro1 v] heading to (90) degrees
turn to heading (0) degrees ▶
set Inertial/Gyro rotation#
The set Inertial/Gyro rotation block sets the Gyro Sensor’s heading to a specified value.
set [Gyro1 v] rotation to (0) degrees
Parameters |
Description |
|---|---|
gyro |
The Inertial or Gyro Sensor to set the rotation of, configured in the Devices window. |
rotation |
The value to use for the new rotation as a decimal number or integer. |
Example
when started
[Turn to the new 0 rotation.]
set [Gyro1 v] rotation to (-100) degrees
turn to rotation (0) degrees ▶
angle of Inertial/Gyro heading#
The angle of Inertial/Gyro 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 Inertial or Gyro Sensor to return the heading from, configured in the Devices window. |
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 Inertial/Gyro rotation#
The angle of Inertial/Gyro rotation block returns how much the Gyro Sensor has turned since it started, in degrees as a decimal number: positive for clockwise, negative for counterclockwise.
([Gyro1 v] rotation in degrees)
Parameters |
Description |
|---|---|
gyro |
The Inertial or Gyro Sensor to return the rotation from, configured in the Devices window. |
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 block returns the Gyro Sensor’s current rotation speed in dps.
([Gyro1 v] rate in dps)
Parameters |
Description |
|---|---|
gyro |
The Gyro Sensor to return the rotation speed from, configured in the Devices window. |
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
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:
|
Example
when started
[Display the acceleration along the x-axis 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 as a decimal number.
(BrainInertial gyro rate of [x v] axis in dps)
Parameters |
Description |
|---|---|
axis |
The axis to return the rotational speed of:
|
Example
when started
[Display the gyro rate around the z-axis 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:
|
Example
when started
[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


