Gyro#
Introduction#
The Gyro Sensor provides methods for tracking and changing the robot’s orientation. These methods allow the Brain to track its orientation and heading.
For the examples below, the configured Gyro Sensor will be named Gyro1
, and will be used in all subsequent examples throughout this API documentation when referring to Gyro class methods.
Below is a list of all methods:
Actions – Calibrate and detect changes in orientation with the Gyro Sensor.
calibrate – Calibrates the Gyro Sensor for stable heading tracking.
changed – Registers a function to call when the Gyro Sensor detects change.
Mutators – Modify the Gyro Sensor’s heading and rotation.
setHeading – Sets the Gyro Sensor’s heading to a specified value.
setRotation – Sets the Gyro Sensor’s rotation value.
resetHeading – Sets the heading of the Gyro Sensor to 0.
resetRotation – Sets the rotation of the Gyro Sensor to 0.
Getters – Return orientation and movement data with the Gyro Sensor.
heading – Returns the current heading.
rotation – Returns the cumulative rotation.
rate – Returns the angular velocity around the x, y, or z axis.
isCalibrating – Returns whether or not the Gyro Sensor is calibrating.
installed – Returns whether or not a Gyro Sensor is connected to the Brain.
Constructors – Manually initialize the Gyro Sensor.
gyro – Create a Gyro Sensor.
Actions#
calibrate#
calibrate
calibrates the Gyro Sensor. Calibration should be used when the Gyro Sensor is not moving.
Usage:
Gyro1.calibrate(time, wait);
Parameters |
Description |
---|---|
|
One of the valid calibration types:
|
|
Optional. Whether or not to wait before executing the next command:
|
// Example coming soon
changed#
changed
registers a callback function for when the Gyro Sensor’s heading changes.
Usage:
Gyro1.changed(callback);
Parameters |
Description |
---|---|
|
A function that is previously defined to execute when the Gyro Sensor’s heading changes. |
// Example coming soon
Mutators#
setHeading#
setHeading
sets the heading of the Gyro Sensor to a specific value.
Usage:
Gyro1.setHeading(value, units);
Parameters |
Description |
---|---|
|
The heading value to set. |
|
The unit that represents the new heading:
|
// Example coming soon
setRotation#
setRotation
sets the rotation of the Gyro Sensor to a specific value.
Usage:
Gyro1.setRotation(value, units);
Parameters |
Description |
---|---|
|
The rotation value to set. |
|
The unit that represents the new rotation:
|
// Example coming soon
resetHeading#
resetHeading
resets the heading of the Gyro Sensor to 0.
Usage:
Gyro1.resetHeading();
Parameters |
Description |
---|---|
This method has no parameters. |
// Example coming soon
resetRotation#
resetRotation
resets the rotation of the Gyro Sensor to 0.
Usage:
Gyro1.resetRotation();
Parameters |
Description |
---|---|
This method has no parameters. |
// Example coming soon
Getters#
heading#
heading
returns the current heading of the Gyro Sensor.
Usage:
Gyro1.heading(units)
Parameters |
Description |
---|---|
|
Optional. The unit that represents the heading:
|
// Example coming soon
rotation#
rotation
returns the current rotation of the Gyro Sensor.
Usage:
Gyro1.rotation(units)
Parameters |
Description |
---|---|
|
Optional. The unit that represents the rotation:
|
// Example coming soon
rate#
rate
returns the current rate of change of the Gyro Sensor’s rotation.
Usage:
Gyro1.rate(units)
Parameters |
Description |
---|---|
|
Optional. The unit used to represent the gyro rate:
|
// Example coming soon
isCalibrating#
isCalibrating
returns a Boolean indicating if the Gyro Sensor is currently calibrating.
true
- The Gyro Sensor is calibrating.false
- The Gyro Sensor is not calibrating.
Usage:
Gyro1.isCalibrating()
Parameters |
Description |
---|---|
This method has no parameters. |
// Example coming soon
installed#
installed
returns a Boolean indicating whether the Gyro Sensor is connected to the Brain.
true
- The Gyro Sensor is connected to the Brain.false
- The Gyro Sensor is not connected to the Brain.
Usage:
Gyro1.installed()
Parameters |
Description |
---|---|
This method has no parameters. |
Constructors#
gyro#
gyro
creates an object of the gyro Class in the specified port.
Usage:
gyro Gyro1 = gyro(port);
Parameter |
Description |
---|---|
|
Which Smart Port that the Gyro Sensor is connected to as |
// Example coming soon