Gyro Sensor#
Introduction#
The VEX IQ (1st gen) Gyro Sensor measures rotational movement around a single axis. It is used to track changes in heading as a robot turns.
Below is a list of all blocks:
calibrate gyro — Calibrates an external Gyro Sensor for stable heading tracking.
set Gyro heading — Sets the sensor’s heading to a specified value.
set Gyro rotation — Sets the sensor’s rotation value.
angle of Gyro heading — Returns the sensor’s current heading.
angle of Gyro rotation — Returns the sensor’s cumulative rotation.
rate of gyro — Returns the angular velocity.
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.
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:
|
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#
The set Gyro 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 set the heading of. |
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 Gyro rotation#
The set Gyro 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 set the rotation of. |
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 Gyro heading#
The angle of 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 Gyro Sensor to return 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#
The angle of 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 Gyro Sensor to return 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 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. |
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