Inertial#
Introduction#
The VEX AIM Coding Robot has a built-in Inertial Sensor. This sensor measures how the robot is moving and turning.
The Inertial Sensor uses two parts to do this. The gyroscope measures turning, such as the robot’s heading, rotation, yaw, roll, pitch, and turn rate. 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, measure acceleration, detect crashes, reset heading or rotation values, and calibrate the sensor.
Below is a list of all methods:
Orientation — Get and reset how the robot is facing, turning, or tilting.
get_rotation— Returns how far the robot has turned.get_heading— Returns the direction the robot is facing, from 0 to 359.99 degrees.get_yaw— Returns the robot’s yaw angle.get_roll— Returns the robot’s roll angle.get_pitch— Returns the robot’s pitch angle.reset_rotation— Resets the robot’s current rotation to 0 degrees.reset_heading— Resets the robot’s current heading to 0 degrees.set_heading— Sets the robot’s current heading to a new heading value.
Crash — Detect collisions.
crashed— Registers a function to run when a crash is detected.set_crash_sensitivity— Sets how sensitive crash detection is to impacts.
Motion — Measure acceleration and turning speed.
get_acceleration— Returns how quickly the robot is speeding up or slowing down on the selected axis.get_turn_rate— Returns how fast the robot is rotating on the selected axis.
Calibration — Manage sensor calibration.
calibrate— Calibrates the Inertial Sensor.is_calibrating— Returns whether the Inertial Sensor is currently calibrating.
Orientation#
get_rotation#
Rotation is how much the robot has turned, measured in degrees. Unlike heading, rotation can increase past 359.99 degrees or decrease below 0 degrees. At the beginning of a project, the rotation value is set to 0 degrees. get_rotation returns the robot’s current rotation as a float.
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:
robot.inertial.get_rotation()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Display the robot's rotation as it rotates
while True:
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print(f"Rotation: {robot.inertial.get_rotation():.2f}")
wait(50, MSEC)
get_heading#
A heading is the direction the robot is facing, measured in degrees from 0 to 359.99. get_heading returns the robot’s current heading as a float.
The starting heading is 0 degrees. If the robot turns past 359.99 degrees, the heading wraps back to 0 degrees.
Usage:
robot.inertial.get_heading()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Turn right until the heading reaches 90 degrees
robot.turn(RIGHT)
while robot.inertial.get_heading() < 90:
wait(50, MSEC)
robot.stop_all_movement()
# Display the robot's heading as it is rotated by hand
while True:
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print(f"Heading: {robot.inertial.get_heading()} degrees")
wait(50, MSEC)
get_yaw#
Yaw describes the robot turning left or right around its vertical axis. get_yaw returns the robot’s yaw angle in the range -180.00 to 180.00 degrees as a float.
The image below uses arrows to show the direction of positive rotation for yaw.
Usage:
robot.inertial.get_yaw()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Display the robot's yaw angle as it is rotated by hand
while True:
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print(robot.inertial.get_yaw())
wait(50, MSEC)
get_roll#
Roll describes the robot tilting side to side. get_roll returns the robot’s roll angle in the range -180.00 to 180.00 degrees as a float.
The image below uses arrows to show the direction of positive rotation for roll.
Usage:
robot.inertial.get_roll()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Display the robot's roll angle as it is tilted by hand
while True:
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print(robot.inertial.get_roll())
wait(50, MSEC)
get_pitch#
Pitch describes the robot tilting forward or backward. get_pitch returns the robot’s pitch angle in the range -90.00 to 90.00 degrees as a float.
The image below uses arrows to show the direction of positive rotation for pitch.
Usage:
robot.inertial.get_pitch()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Display the robot's pitch angle as it is tilted by hand
while True:
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print(robot.inertial.get_pitch())
wait(50, MSEC)
reset_rotation#
reset_rotation resets the robot’s current rotation to 0 degrees.
After this method is used, the robot tracks future turns from the new 0 degree rotation value.
Usage:
robot.inertial.reset_rotation()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Reset the robot's rotation if it exceeds 180 degrees
while True:
if robot.inertial.get_rotation() >= 180:
robot.inertial.reset_rotation()
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print(f"Rotation: {robot.inertial.get_rotation():.2f}")
wait(50, MSEC)
reset_heading#
reset_heading resets the robot’s current heading to 0 degrees.
After this method is used, the robot’s current direction becomes the new 0 degree heading.
Usage:
robot.inertial.reset_heading()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Turn the robot around using a new 90 degree heading
robot.turn_to(90)
wait(1, SECONDS)
robot.inertial.reset_heading()
robot.turn_to(90)
set_heading#
A heading is the direction the robot is facing, measured in degrees from 0 to 359.99. set_heading changes the robot’s current heading to a new heading value.
For example, if the robot has turned to face right, setting the heading to 0 degrees makes that right-facing position the new 0 degrees. Then the robot can track other headings based on that new direction.
Usage:
robot.inertial.set_heading(heading)
Parameters |
Description |
|---|---|
|
The heading value, in degrees, to set for the robot. This can be a value from 0 to 359.99. |
# Turn the robot to 90 degrees using its new heading
robot.inertial.set_heading(45)
robot.turn_to(90)
Crash#
crashed#
crashed registers a function to be called when the robot detects a sudden impact or collision.
Usage:
robot.inertial.crashed(callback, arg)
Parameters |
Description |
|---|---|
|
A function that is previously defined to execute when a collision is detected. |
|
Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information. |
# Define what happens when a crash occurs
def crash_detected():
# Stop all movement and indicate a crash occurred
robot.screen.print("Crash detected")
robot.stop_all_movement()
robot.inertial.crashed(crash_detected)
# Drive forward until crash
robot.move_at(0, 100)
set_crash_sensitivity#
set_crash_sensitivity adjusts how much sudden acceleration is needed for the robot to detect a crash.
Usage:
robot.inertial.set_crash_sensitivity(sensitivity)
Parameters |
Description |
|---|---|
|
The crash sensitivity:
|
def crashed_callback():
robot.stop_all_movement()
robot.sound.play(CRASH)
# system event handlers
robot.inertial.crashed(crashed_callback)
# add 15ms delay to make sure events are registered correctly.
wait(15, MSEC)
# Detect a crash at a slow velocity.
robot.set_move_velocity(35, PERCENT)
robot.inertial.set_crash_sensitivity(HIGH)
robot.move_at(0)
Motion#
get_acceleration#
Acceleration is how quickly the robot is speeding up or slowing down. get_acceleration returns the robot’s acceleration on the selected axis, from -4.00 G to 4.00 G, as a float.
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. On AIM, the axis options are named for directions on the robot: FORWARD, RIGHTWARD, and DOWNWARD.

Usage:
robot.inertial.get_acceleration(type)
Parameters |
Description |
|---|---|
|
The axis to measure acceleration on:
|
# Display the acceleration as the robot begins to move
robot.screen.set_cursor(4,1)
sitting_accel = robot.inertial.get_acceleration(RIGHTWARD)
robot.screen.print(f"Resting: {sitting_accel:.2f}")
wait(0.5, SECONDS)
robot.screen.next_row()
robot.move_at(90, 100)
wait(0.1, SECONDS)
robot.screen.print(f"Startup: {robot.inertial.get_acceleration(RIGHTWARD):.2f}")
get_turn_rate#
Turn rate is how fast the robot is rotating. get_turn_rate returns the robot’s turning rate in degrees per second (dps) as a float, from -1000.00 to 1000.00 dps.
The value can be positive or negative depending on the direction the robot is rotating on the selected axis. The image below uses arrows to show the direction of positive rotation for roll, pitch, and yaw.

Usage:
robot.inertial.get_turn_rate(axis)
Parameters |
Description |
|---|---|
|
Which orientation to return:
|
# Display the gyro rate as the robot is rotated by hand
while True:
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print(robot.inertial.get_turn_rate(YAW))
wait(50, MSEC)
Calibration#
Calibration helps the Inertial Sensor measure turns correctly by measuring and compensating for sensor noise and drift over a 2-second period. During this time, the robot must remain completely still on a stable surface. Movement during calibration can produce inaccurate results.
VEX robots attempt to calibrate themselves automatically upon startup, waiting until they detect no motion. However, if the robot is being carried or moved during startup, the sensor may fail to calibrate properly or yield incorrect calibration.
If your project relies heavily on having an accurate heading, or if you need consistent and repeatable turns, calling calibrate at the beginning of your code can help. It’s good practice to display a message like “Calibrating…” on the robot’s screen during calibration, then update it to “Calibration complete.” afterward to remind you (and anyone else using the robot) that the robot must remain motionless during this period.
calibrate#
calibrate calibrates the gyro. Calibration helps the Inertial Sensor measure turns correctly by measuring and compensating for sensor noise and drift over a 2-second period. During this time, the robot must remain completely still on a stable surface. Movement during calibration can produce inaccurate results.
VEX robots attempt to calibrate themselves automatically upon startup, waiting until they detect no motion. However, if the robot is being carried or moved during startup, the sensor may fail to calibrate properly or yield incorrect calibration.
Usage:
robot.inertial.calibrate()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Calibrate the gyro before moving
robot.inertial.calibrate()
robot.screen.show_emoji(THINKING)
wait(2, SECONDS)
robot.screen.show_emoji(PROUD)
robot.move_for(50, 90)
is_calibrating#
is_calibrating returns a Boolean indicating whether the Inertial Sensor is calibrating.
True— The Inertial Sensor is calibrating.False— The Inertial Sensor is not calibrating.
Usage:
robot.inertial.is_calibrating()
Parameters |
Description |
|---|---|
This method has no parameters. |
# Move after the calibration is completed
robot.inertial.calibrate()
while robot.inertial.is_calibrating():
robot.screen.show_emoji(THINKING)
wait(50, MSEC)
robot.screen.show_emoji(PROUD)
robot.move_for(50, 90)