9DOF IMU
ICM-20948
Navio2 Plus contains two 9DOF (degree of freedom) IMU: ICM-20948. Each of them combines a gyroscope, an accelerometer and a magnetometer in one device. IMU sensors are not only popular as a part of drone autopilot projects, but are also widely used in devices like cellphones, tablets, etc.
IMU example
If you have not already done that, download Navio2 Plus drivers and examples code here.
IMU example for Navio2 Plus runs with one of the on-board sensors at a time. During start-up program you have to specify with which sensor to work.
C++
note
If you have not build the examples yet, perform the following commands:
cd C++
make
To check the IMU example, you need to run this command:
cd Build
./AccelGyroMag -i [sensor name]
Python
Move to the folder with the source code, compile and run the example:
cd Python
python AccelGyroMag.py -i [sensor name]
Argument [sensor name] allows you to choose inertial measurement unit: icm1 is ICM-20948 on CS 1, icm3 is ICM-20948 CS 3.
You should immediately see 9 values, updated in real time. Try to move the device around and see them change. They include Accelerometer, Gyroscope and Magnetometer data, three axis each.
Selected: ICM20948 CS 1
Connection established: True
Acc: +0.014 +0.139 +9.974 Gyr: -0.042 +0.022 +0.011 Mag: -3525.450 +29.584 +0.000
Acc: -0.010 +0.268 +10.036 Gyr: -0.042 +0.019 +0.015 Mag: -14.963 +43.390 -50.130
Acc: -0.010 +0.278 +9.888 Gyr: -0.043 +0.021 +0.012 Mag: -16.566 +42.852 -50.302
Acc: +0.010 +0.187 +10.041 Gyr: -0.039 +0.021 +0.011 Mag: -14.963 +42.314 -50.817
Acc: -0.062 +0.158 +9.855 Gyr: -0.039 +0.020 +0.011 Mag: -15.497 +42.493 -49.959
Acc: -0.067 +0.196 +10.056 Gyr: -0.044 +0.020 +0.013 Mag: -14.963 +43.748 -50.130
For further information, see source code.
tip
Function create_inertial_sensor() creates object of class ICM20948 depending on the argument passed to the program.
The next thing we should pay attention to is the line sensor->initialize(), as it does an important job of setting internal device parameter. Note that this function also sets scales for both Accelerometer and Gyroscope.
The main function loop is pretty straightforward: read the data, print the data.
note
You can find additional information about the chip in ICM-20948 datasheet.