Lab2 - IMU

Published:

Objective

The purpose of this lab is to add the IMU to our robot, start running the Artemis & sensors from a battery, and record a stunt on the RC robot.

Keywords

IMU, Accelerometer, Gyroscope, Complementary Filter

Lab Tasks

Task 1 - Set up the IMU

I used the QWIIC cable to connect the IMU and the Artemis board shown in the image as follows:

imu_connection

After I uploaded the example code, it did not work because the value of AD0_VAL is the default 1. However, the ADR jumper was closed, I changed its value from 1 to 0. In this way, the code worked. I shaked the IMU a little bit to get the changed acceleration and gyroscope data when rotating, flipping, and accelerating the board.

IMU_example_code_working

Task 2 - Accelerometer

The accelerometer from our IMU returns the acceleration. In order to get the roll and pitch angles, we need to apply the following equations:

pitch_roll_equations

As I applied the equations in the code, I tested the outputs at {-90, 0, 90} degrees for pitch and roll.

  • 0 degree pitch & 0 degree roll

pitch0_roll0

  • -90 degrees pitch

pitch-90

  • 90 degrees pitch

pitch90

  • -90 degrees roll

roll-90

  • 90 degrees roll

roll90

The accelerometer had a rather poor performance when I tested it at 0-pitch and 0-roll. The pitch values were noisy, but the roll values were far better. Other tested sitations all had good performance.

I recorded the pitch and roll values when I put the IMU on the table still for 15000 ms. I displayed the two kinds of data, which contained much noise.

display_pitch_roll_data

I applied FFT to the data and analysed the frequencies composition as follows:

fft_image

The FFT results showed that the pitch values focused on the base frequency data, but the roll values lied on the base to 10Hz frequency scope. To get more clearer data, a low pass filter with 10Hz cutoff frequency is perferred.

Task 3 - Gyroscope

Based on the equations from lecture notes:

gyr_equation

I implemented the calculation methods in the Artemis code as follows:

gyr_code

where used the gap between the time from millis() as dt.

I recorded some data samples and generated the image of the data from the gyroscpoe as follows:

gyr_data_sample

It shows that the curves are much smoother than the curves from the accelerometer which means there was less noise in gyroscope. However, for the gyroscope, as the time increased, the data drift happened even without moving the device.

I used the complementary filter to improve the data by using the following code:

filter_code

After the complementary filter was applied, the data curves for pitch and roll became less noisy and without drift.

Without filter, curves were:

no_filter

With filter, curves were:

filter_0.2

where alpha is 0.2. With the filter, accuracy was very close to that without filter, and there was nearly no obvious drift.

Task 4 - Sample Data

I added a case command for ble_arduino.ino called LAB2_SAMPLE_DATA, which first created arrays for storing the attributes data from IMU. Then, calculate the time and update the values inside each array. Finally, use BLE to transmit the data to our computer.

lab2_sample_data_code

Also, I modified my notification handler accordingly, and got the outputs shown below:

handler_update

After I converted the data type of the elements in arrays from string into float and int, I calculated the sampling speed:

sample_speed

which showed that the sampling speed is about 326Hz.

For this process, I transmitted 1 int (4Bytes for each) and 6 float (4Bytes for each) variables at one time which occupies in total 28Bytes. The sampling rate is 326Hz, so the “memory occupying rate for transmission” is 9.128kB/s. After 5 seconds’ transmission, we need around 45.64kB. The RAM of Artemis is 384kB. So, there will be enough space for this transmission process.