Lab 2: IMU

1. Objective

The main goal of this lab is to use and test the IMU ICM 20948. It also contains recording the stunt of the RC car.

2. Lab Tasks

2.1 Set up

2.1.1 Set up the IMU

First, I connect the IMU to the Artemis board and install the SparkFun 9 DOF IMU Breakout. Here is a picture of the connection.

lab2/3-1

2.1.2 IMU example

After running the example, It returns the IMU data. It can be seen in the following video.

2.1.3 AD0_VAL definition

In the datasheet, it shows that the AD0_VAL is used to change the I2c address of IMU.

2.1.4 The acceleration and gyroscope data

When I flip, rotate and accelerate the board, the data of accelerometer and gyroscope changes rapidly.

2.1.5 Blink the LED

I add a function of blinking the LED and use the for loop to run it three times. It now blinks three times in the beginning, watch it below.

2.2 Accelerometer

2.2.1 Output at {-90,0,90} degrees

Using the surface and edges of my table, I try to do 90 degree tilt and roll. Here is the result.

Here is a picture of the code

lab2/3-2

2.2.2 Accelerometer accuracy discussion

According to the data from the above part, The measured pitch range is [-90.82, 91.51] and the measured roll range is [-92.02, 93.26]. The conversion factor is

\( Pitch Conversion Factor = \frac{90-(-90)}{91.51-(-90.82)} = 0.98 \)

\( Roll Conversion Factor = \frac{90-(-90)}{93.26-(-92.02)} = 0.97 \)

The final pitch and roll degree can be calculated by the equation:

\( Final pitch output = -90 + Conversion Factor (measured output- (-90.82))\)

\( Final roll output = -90 + Conversion Factor (measured output- (-92.02))\)

2.2.3 Noise in the frequency spectrum analysis

After I record the data and load the data in python, I first plot the pitch and roll angle in time domain with sample rate equals to 240 Hz. The first picture is the pitch angle in time domain and the second one is the roll angle in time domain.

lab2/3-3
lab2/3-4

After fourier transform, the pitch and roll angle in frequency spectrum is:

lab2/3-5
lab2/3-6

In the datasheet, it shows that the IMU already has a low pass filter so it has little noise in frequency spectrum. The cut off frequency I select is 20 Hz. With the equations:

\( a=\frac{T}{T+RC} \)

\( fc=\frac{1}{2RC\pi} \)

\( T=\frac{1}{f} \)

Here fc is the cut off frequency and f is the sample rate, and the a is equal to 0.347. However, the low pass filter can not change the result too much. Here is the code:

lab2/3-7

2.3 Gyroscope

2.3.1 Pitch, roll and yaw calculated by gyroscope

Use the code below, I change the IMU positions and it returns different pitch, row and yaw.

lab2/3-8
lab2/3-9

Compared to the data in accelerometer, the gyroscope data increases rapidly as time goes on. Besides, the sample rate need to be high, as low sample rate will cause the updated data become slower.

2.3.2 Complementary filter

Use the equation learned in the class, the code of complementary filter is shown below.

lab2/3-10

Then, I tilt and roll the IMU to different degrees. The video shows that the result is quite accurate

2.4 Sample Data

2.4.1 Speed of sampling

Using the equations in the class, the program returns pitch, roll and yaw. I delete all delay and serial print. The sample rate is about 64 Hz. That is because the data rate of magnetometer is much more smaller than others. Moreover, the main loop on the Artemis board runs faster than the IMU process new values as it's execution time is only about 3ms

2.4.2 Stored IMU data and time stamp in arrays

In arduino, I write a new method which can calculate pitch,roll,yaw and timestamp in float numbers. The data is stored in arrays. It is used in a new case which is called "GET_5s_IMU". Then, each pieces of data is sent in a for loop. The code is shown below.

lab2/3-11

2.4.3 5s of IMU data sent over Bluetooth

As the Artemis board has 384kB of RAM and each piece of data is 8 bytes (4 float numbers:pitch,roll,yaw,timestamp), it can store 48000 pieces of data. The timestamp shows the interval of each piece of data is about 4ms. Therefore, in order to get 5s IMU data, the Artemis board need to store and send 1250 datapoints. Here is part of the result in jupyter lab.

lab2/3-12

2.5 Record a Stunt

Here is the video of the toy car.

Back to the main page