FastRobots

ECE4160/5160-MAE 4190/5190: Fast Robots course, offered at Cornell University in Spring 2024

This project is maintained by FastRobotsCornell

Enabling the IMU DMP

In Fast Robots, we use the Pimoroni ICM-20948 9DoF breakout board to detect our car’s orientation. The Pimoroni board is a platform for the TDK InvenSense ICM-20948, a 9-axis motion tracking sensor. We also use the SparkFun ICM-20948 Arduino library, which was written by SparkFun for their own 9DoF IMU breakout board, but is compatible with any board fitted with the TDK InvenSense ICM-20948, which we’ll simply refer to as the “ICM”.

One of the ICM’s key features is the InvenSense digital motion processor (DMP), which is described in the ICM datasheet as follows:

The DMP enables ultra-low power run-time and background calibration of the accelerometer, gyroscope, and compass, maintaining optimal performance of the sensor data for both physical and virtual sensors generated through sensor fusion.

In other words, the DMP is capable of error and drift correction by fusing readings from the ICM’s 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer/compass.

By default, the DMP is disabled in the SparkFun Arduino library, because it requires 14 kB of additional program memory on the host microprocessor. Activating the DMP requires a small modification to the library (detailed below), while configuration is illustrated in several of SparkFun’s example Arduino sketches:

Most relevant to our purposes is Example7_DMP_Quat6_EulerAngles, which will take quaternion data from the DMP and convert it to roll, pitch, and yaw angles. The video below shows a visual demo of the DMP quaternion output.

Follow the steps below to get the DMP and the visual demo running on your Artemis.

Step 1: Modifying the Library

Open the SparkFun ICM-20948 library directory on your computer. The location is typically something like:

There, edit the file ICM_20948_C.h and uncomment line 29 to define the constant ICM_20948_USE_DMP.

Step 2: Example Sketch

In the Arduino IDE, open the sketch Examples > SparkFun 9DoF IMU Breakout > Arduino > Example7_DMP_Quat6_EulerAngles.

Similar to what we did in Lab 2, you may need to change the value of AD0_VAL to 0 in the line:

#define AD0_VAL 1

Burning the sketch to your Artemis with the IMU breakout connected over I2C will present you with the serial prompt Press any key to continue.... Pressing Enter should then start a stream of Euler angles for pitch, roll, and yaw. This can be plotted using the serial plotter function.

Step 3: Optional: Visualization

The visualization seen in the video above requires Node.js. Install v20 or later.

Edit the Example7_DMP_Quat6_EulerAngles sketch and uncomment line 27 to define QUAT_ANIMATION. Burn the sketch to your Artemis but close the serial monitor and serial plotter. The Node.js runtime will need exclusive access to the serial port.

After installation, clone the 3D visualization repository and edit the file index.js to set the SERIAL_PORT and SERIAL_BAUD values for your particular setup.

Next, run the following in the respository directory to install the needed libraries:

npm install

Then, to start the demo, run:

node index.js

The console should start outputting quaternion data. The visualization can then be opened under http://localhost:3000/ in a browser.

Acknowledgements: Special thanks to Stephan Wagner for providing this tutorial to Fast Robots.