Gyro Sensor#

Introduction#

The Gyro Sensor measures the heading and the rotation of the robot.

The Gyro Sensor category will only appear when the sensor is configured independently, not as part of a drivetrain configuration, in the Devices window.

This page uses gyro_sensor as the example Gyro Sensor name. Replace it with your own configured name as needed.

Below is a list of available methods:

  • calibrate – Calibrates the configured Gyro Sensor.

  • set_heading – Changes the Gyro Sensor’s current heading to a new heading.

  • set_rotation – Changes the Gyro Sensor’s current rotation to a new rotation.

  • heading – Returns the Gyro Sensor’s heading angle as a float.

  • rotation – Returns how much the Gyro Sensor has rotated since the project started as a float.

Constructor – Manually initialize a Gyro Sensor.

  • Gyro – Create a Gyro Sensor.

calibrate#

calibrate calibrates the Gyro Sensor. All subsequent methods 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 sensor must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.

Usage:
gyro_sensor.calibrate()

Parameters

Description

This method has no parameters.

set_heading#

A heading is the direction the sensor is facing, measured in degrees. set_heading 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 heading.

Usage:
gyro_sensor.set_heading(value, units)

Parameters

Description

value

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

units

Optional. The heading unit: DEGREES

set_rotation#

Rotation is how much the sensor has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation 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.

Usage:
gyro_sensor.set_rotation(value, units)

Parameters

Description

value

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

units

Optional. The rotation unit: DEGREES

heading#

A heading is the direction the sensor is facing, measured in degrees. heading returns that heading as a float from 0 to 359.99 degrees.

The starting heading is 0 degrees.

Usage:
gyro_sensor.heading(units)

Parameters

Description

units

Optional. The heading unit: DEGREES

rotation#

Rotation is how much the sensor has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns 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 return a rotation of 720 degrees.

Usage:
gyro_sensor.rotation(units)

Parameters

Description

units

Optional. The rotation unit: DEGREES

Constructor#

Constructors are used to manually create Gyro objects, which are necessary for configuring a Gyro Sensor outside of VEXcode.

Gyro#

Gyro creates a Gyro Sensor.

Usage:
Gyro(port)

Parameter

Description

port

The 3-Wire Port that the Gyro Sensor is connected to:

  • On the EXP Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Gyro Sensor in Port A
gyro_sensor = Gyro(brain.three_wire_port.a)