IMU
Last updated
Last updated
IMU, or inertial measurement unit, is an incredible device that measures the robot’s acceleration, angular velocity, and orientation! It works by tracking changes in motion over time. By integrating acceleration data, you can calculate velocity and position. Similarly, integrating angular velocity data gives you orientation.
Located in the FTC Control Hub,
IMUs are typically used for autonomous navigation. In combination with other sensors, the robot can autonomously and efficiently traverse across the gamefield, using the IMU to help guide itself and identify where the robot is located. It's also used to automatically stabilize the robot, making piloting the robot easier.
This lesson will teach you the fundamentals on how to receive data from an IMU. If you want to explore how to use this information, please check out the advanced guide where I will show you a simplified version of Roadrunner, a common program used in FTC that uses the IMU to quickly traverse the field autonomously.
IMU programming comes in two parts: initialization and recording.
Initialization
The first step is defining the units the IMU will use. To stick with default parameters, this step can be skipped but it is recommended to define the units the IMU will use so that it can fit its intended need and make calculations easier.
set the variable imuParameters to new IMU-BNO055.Parameters
This will tell the program to set the variable to a set of parameters object for the IMU. This is necessary as the imu cannot be set to anything other than IMU-BNO055.Parameters objects.
call IMU-BNO055.parameters to set what measurement you want.
There are several options to set the IMU parameters to. For example some common ones are:
setAngleUnit will set the angular units the IMU uses.
setAccelUnit which will set the acceleration units the IMU uses.
The parameters is the IMU-BNO055.Parameters object you want to change. The unit defines the new unit the object will use.
More options are listed in the IMU-BNO055.Parameters section under Sensors.
Initialize the IMU with the new parameters.
Finally, this will set the IMU’s parameters to the variable containing a IMU-BNO055.Parameters object, changing the units the IMU uses.
Recording
You can access the IMU data recording in the IMU using the get___ block like getAngularVelocity or getAngularOrientation or the imu.___ blocks with the wanted parameter listed afterwards. The options are listed in the IMU-BNO055 section under Sensors.
Oftentimes, you will set the parameters you want to a variable like
which will make it easier for the coder (that's you!) to understand what parameter refers to what.
If you want to see what the data is like in real time then, in the program’s main loop like with
Don’t forget to call Telemetry.Update at the end of the loop to update the Telemetry!
Putting it all together, the code for this example looks like:
Now you can access the IMU! If you want to see how the IMU can work in action then check out the advanced guide for more!
which will run as long as the game has begun, call the Telemetry to add the data you want:
. The key is a helpful description for the displayed number, making it easier to understand which number refers to what. The number is set to any number or variable that represents a number.
You should see the resulting telemetry displayed on the upper right hand corner: