In this tutorial, we will show you how to connect and use IMU module on your Rover.
First, make sure you have a compatible IMU module. We recommend
Grove - IMU 9DOF v2.0 but any module with
MPU-9250 sensor should work.
IMU functionality was introduced in leo_firmware version 0.5, so make sure to stay updated.
By default, the IMU will work on hSens2 port. You can change it to hSens1 by modifying the params.h file in
Connect the sensor pins according to the CORE2 manual.
You can use female jumper cables, or create your own IDC cable, like this one:
If you use the Grove IMU, you can 3D print the mounting plate for the MEB cover which contains holes for the self-tapping screws (
00189_imu part). The files can be found here:
Start a remote terminal session on the Rover via SSH
To set IMU functionality on or off, you need to call the
rosservice call /core2/set_imu true
Now, you need to reset the board to apply changes. You can do this by turning on and off the whole Rover, or by calling the
rosservice call /core2/reset_board
After the board reset, new topics should spawn:
/imu/mag on which IMU gyroscope, accelerometer and magnetometer readings are published. (you can check available topics with
Check if the readings are correct with
rostopic echo, for example:
rostopic echo /imu/gyro
The sensor's accelerometer and gyroscope X, Y and Z axes should be printed on the board. If they are not, you can check MPU9250 IC orientation and identify the axes with this drawing:
The magnetometer axes were also transformed to these axes to comply with the North-West-Up world frame.
The gyroscope data (
imu/gyro topic) represents angular velocity around sensor's axes in rad/s (radians per second).
The accelerometer data (
imu/accel topic) represents linear acceleration along sensor's axes in m/s2 (meters per second squared).
The magnetometer data (
imu/mag topic) represents magnetic field along sensor's axes in G (Gauss).
The system should be aware of where the module is located on the robot, in order to be able to use the sensor readings. To specify the location, you can extend the URDF model of the Rover by editing the
/etc/ros/urdf/robot.urdf.xacro. Simply open the file in
nano editor by typing:
Add these lines somewhere between the
<link name="imu"/><joint name="imu_joint" type="fixed"><parent link="base_link"/><child link="imu"/><origin xyz="0.027 0 -0.07" rpy="0 0 0"/></joint>
imu link represents the reference frame of the sensor readings.
base_link is the origin of the robot.
imu_joint specifies the transformation between these two links.
You might need to modify the transformation (
<origin> tag) depending on how you mounted the module.
For more information, visit ROS Development -> Adding additional functionality to the rover -> expanding the URDF model
The firmware also provides services that perform sensor calibration and store the results in a persistent storage.
To calibrate gyroscope and accelerometer biases, just place the Rover on a flat surface, parallel to the ground and call the calibration service:
rosservice call /imu/calibrate_gyro_accel
Calibrating the magnetometer is a bit more difficult task, as it requires collection of a whole range of measurements on each axis. The method that works best is to move the sensor in a 3-dimensional figure eight, however, such motion can be hard to accomplish with the whole Rover.
To start the calibration, just call the service:
rosservice call /imu/calibrate_mag
After 4 seconds, the firmware should start data collection. After another 15 seconds, the service should return success message. Try to move the sensor in a varied motion for the whole duration of the service call.