Inertial#
Introduction#
The Brain has a built-in Inertial Sensor. This sensor can measure how the Brain is moving or turning.
The Inertial Sensor uses two parts to do this. The gyro measures turning, such as which direction the Brain is facing and how far it has turned. The accelerometer measures changes in motion, such as speeding up, slowing down, or stopping suddenly during a crash.
The Inertial methods can be used to track turns, reset heading or rotation values, measure roll, pitch, and yaw, and report acceleration.
There are many ways to code the Inertial Sensor. Below is a list of all Inertial methods:
Orientation — Return and set how the Brain is facing, turning, or tilting.
get_heading— Returns the direction the Brain is facing, from 0 to 359 degrees.get_rotation— Returns how far the Brain has turned.get_yaw— Returns how much the Brain has turned left or right from its starting position.get_roll— Returns how much the Brain is tilted left or right.get_pitch— Returns how much the Brain is tilted forward or backward.calibrate— Calibrates the Brain’s Inertial Sensor.reset_heading— Resets the Brain’s current heading to 0 degrees.reset_rotation— Resets the Brain’s current rotation to 0 degrees.set_heading— Sets the Brain’s current heading to a new heading value.set_rotation— Sets the Brain’s current rotation to a new rotation value.
Motion — Return how the Brain is moving.
get_acceleration— Returns how quickly the Brain is speeding up or slowing down on the selected axis.
Orientation#
get_heading#
A heading is the direction the Brain is facing, measured in degrees from 0 to 359. get_heading returns the Brain’s current heading.
The starting heading is 0 degrees. If the Brain turns past 359 degrees, the heading wraps back to 0 degrees.
Usage:
inertial.get_heading()
Parameters |
Description |
|---|---|
This method has no parameters. |
get_rotation#
Rotation is how much the Brain has turned, measured in degrees. Unlike heading, rotation can increase past 359 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. get_rotation returns the Brain’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. Turning one full turn to the left from 0 degrees will return a rotation of -360 degrees.
Usage:
inertial.get_rotation()
Parameters |
Description |
|---|---|
This method has no parameters. |
get_yaw#
Yaw is how much the Brain has turned left or right from its starting position, measured in degrees. get_yaw returns the Brain’s current yaw value.
Turning right increases the yaw value, and turning left decreases the yaw value. Yaw is useful for checking left and right turning without using the wrapped heading value.
Usage:
inertial.get_yaw()
Parameters |
Description |
|---|---|
This method has no parameters. |
get_roll#
Roll is how much the Brain tilts to the left or right, measured in degrees. get_roll returns the Brain’s current roll value.
With the Brain facing forward, tilting left increases the roll value, and tilting right decreases the roll value.
Usage:
inertial.get_roll()
Parameters |
Description |
|---|---|
This method has no parameters. |
get_pitch#
Pitch is how much the Brain tilts forward or backward, measured in degrees. get_pitch returns the Brain’s current pitch value.
With the Brain facing forward, tilting forward increases the pitch value, and tilting backward decreases the pitch value.
Usage:
inertial.get_pitch()
Parameters |
Description |
|---|---|
This method has no parameters. |
calibrate#
calibrate calibrates the Brain’s Inertial Sensor.
Calibration helps the Inertial Sensor measure turns correctly. Keep the Brain still for about 2 seconds during calibration. If the Brain moves during calibration, heading, rotation, yaw, roll, and pitch values may not measure correctly.
The project will wait until calibration is done before the next line of code runs.
Usage:
inertial.calibrate()
Parameters |
Description |
|---|---|
This method has no parameters. |
reset_heading#
A heading is the direction the Brain is facing, measured in degrees. reset_heading resets the Brain’s current heading to 0 degrees.
After this method is used, the Brain’s current direction becomes the new 0 degree heading.
Usage:
inertial.reset_heading()
Parameters |
Description |
|---|---|
This method has no parameters. |
reset_rotation#
Rotation is how much the Brain has turned, measured in degrees. reset_rotation resets the Brain’s current rotation to 0 degrees.
After this method is used, the Brain tracks future turns from the new 0 degree rotation value.
Usage:
inertial.reset_rotation()
Parameters |
Description |
|---|---|
This method has no parameters. |
set_heading#
A heading is the direction the Brain is facing, measured in degrees from 0 to 359. set_heading changes the Brain’s current heading to a new heading value.
For example, if the Brain has turned to face right, setting the heading to 0 degrees makes that right-facing position the new 0 degrees. Then the Brain can track other headings based on that new direction.
Usage:
inertial.set_heading(heading)
Parameters |
Description |
|---|---|
|
The heading value, in degrees, to set for the Brain. This can be a whole number from 0 to 359. |
set_rotation#
Rotation is how much the Brain has turned, measured in degrees. Unlike heading, rotation can increase past 359 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation changes the Brain’s current rotation to a new value.
For example, if the Brain 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 Brain can track rotations based on that new value.
Usage:
inertial.set_rotation(rotation)
Parameters |
Description |
|---|---|
|
The rotation value, in degrees, to set for the Brain. This can be an integer. |
Motion#
get_acceleration#
Acceleration is how quickly the Brain is speeding up or slowing down. get_acceleration returns the acceleration of the Brain on the selected axis, from -4.0 G to 4.0 G.
A G is a unit used to measure acceleration. 1 G is about the acceleration you feel from gravity while sitting still.
The value can be positive or negative depending on the direction of acceleration on the selected axis. The axis options are X, Y, and Z.
Usage:
inertial.get_acceleration(axis)
Parameters |
Description |
|---|---|
|
The axis to measure acceleration on: |
# Build Used: Super Code Base 2.0
def main():
# Display the acceleration after moving.
drivetrain.set_drive_velocity(100)
console.print("Resting: ")
console.print(inertial.get_acceleration(X), precision=2)
console.new_line()
wait(1, SECONDS)
drivetrain.drive_for(FORWARD, 500, MM, wait=False)
wait(0.20, SECONDS)
console.print("Startup: ")
console.print(inertial.get_acceleration(X), precision=2)
# Start threads — Do not delete
start_thread(main)