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 blocks can be used to track turns, reset heading or rotation values, detect crashes, and report acceleration.
There are many ways to code the Inertial Sensor. Below is a list of all Inertial blocks:
Settings — Calibrate or set sensor values.
calibrate gyro — Calibrates the Brain’s built-in Inertial Sensor.
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.
Values — Check sensor information.
heading — Reports the Brain’s current heading from 0 to 359 degrees.
rotation — Reports the Brain’s current rotation.
detected crash — Reports whether the Brain has detected a sudden impact.
acceleration — Reports how quickly the Brain is speeding up or slowing down on the selected axis.
calibrate gyro#
The calibrate gyro stack block calibrates the gyro part of the Brain’s built-in 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 and rotation values may not measure turns correctly.
The project will wait until calibration is done before the next block in the stack runs.
calibrate gyro
Parameters |
Description |
|---|---|
This block has no parameters. |
set heading#
A heading is the direction the Brain is facing, measured in degrees from 0 to 359. The set heading stack block 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.
set heading to [0] degrees
Parameters |
Description |
|---|---|
heading |
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. The set rotation stack block 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.
set rotation to [0] degrees
Parameters |
Description |
|---|---|
rotation |
The rotation value, in degrees, to set for the Brain. This can be an integer. |
heading#
A heading is the direction the Brain is facing, measured in degrees. The heading reporter block reports that heading from 0 to 359 degrees.
The starting heading is 0 degrees. If the Brain turns past 359 degrees, the heading wraps back to 0 degrees.
(heading in degrees)
Parameters |
Description |
|---|---|
This block has no parameters. |
rotation#
Rotation is how much the Brain has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. The rotation reporter block reports 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 report a rotation of 720 degrees. Turning one full turn to the left from 0 degrees will report a rotation of -360 degrees.
(rotation in degrees)
Parameters |
Description |
|---|---|
This block has no parameters. |
detected crash#
The detected crash Boolean block reports whether the Brain has detected a sudden impact, such as the robot hitting an object or being bumped hard enough to quickly change its motion.
True — A crash has been detected.
False — A crash has not been detected.
<detected crash?>
Parameters |
Description |
|---|---|
This block has no parameters. |
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Back up and turn after crashing.]
set drive velocity to [100] %
drive [forward v]
wait until <detected crash?>
drive [reverse v] for [100] [mm v] ▶
turn [right v] for [90] degrees ▶
acceleration#
Acceleration is how quickly the Brain is speeding up or slowing down. The acceleration reporter block reports 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 selected axis tells which direction of motion the block reports.
(acceleration of [x v] axis in g)
Parameters |
Description |
|---|---|
axis |
The axis to measure acceleration on:
|
Example
when started :: hat events
[Build Used: Super Code Base 2.0]
[Display the acceleration after moving.]
set print precision to [All Digits v]
set drive velocity to [100] %
print [Resting: ] ▶
print (acceleration of [x v] axis in g) ▶
set cursor to next row
wait [1] seconds
drive [forward v] for [500] [mm v] ◀ and don't wait
wait [0.2] seconds
print [Startup: ] ▶
print (acceleration of [x v] axis in g) ▶