Hi
I am using a LSM9DS1 9dof sensor with Arduino UNO to measure foot rotation. I tried to use Madgwick filter, but I had a problem:
The response from the filter is very slow, I have to wait for a long time until it get stable at the accurate value, as shown in the attachment picture. I changed angle for twice at 38 degree and 0 degree respectively.
Here are what I did for the sensor and filter:
For the sensor set up:
Acc:
// [sampleRate] sets the output data rate (ODR) of the gyro
// sampleRate can be set between 1-6
// 1 = 14.9 4 = 238
// 2 = 59.5 5 = 476
// 3 = 119 6 = 952
imu.settings.gyro.sampleRate = 6;
Gyro:
// [sampleRate] sets the output data rate (ODR) of the
// accelerometer. ONLY APPLICABLE WHEN THE GYROSCOPE IS
// DISABLED! Otherwise accel sample rate = gyro sample rate.
// accel sample rate can be 1-6
// 1 = 10 Hz 4 = 238 Hz
// 2 = 50 Hz 5 = 476 Hz
// 3 = 119 Hz 6 = 952 Hz
imu.settings.accel.sampleRate = 6;
Mag:
// [sampleRate] sets the output data rate (ODR) of the
// magnetometer.
// mag data rate can be 0-7:
// 0 = 0.625 Hz 4 = 10 Hz
// 1 = 1.25 Hz 5 = 20 Hz
// 2 = 2.5 Hz 6 = 40 Hz
// 3 = 5 Hz 7 = 80 Hz
imu.settings.mag.sampleRate = 7;
For the filter set up:
#include <MadgwickAHRS.h>
Madgwick mad_filter;
void setup()
{
Serial.begin(1000000);
setupMad(166);
}
void updateAngles()
{
imu.readAccel();
imu.readGyro();
imu.readMag();
float ax = imu.calcAccel(imu.ax);
float ay = imu.calcAccel(imu.ay);
float az = imu.calcAccel(imu.az);
float gx = imu.calcGyro(imu.gx);
float gy = imu.calcGyro(imu.gy);
float gz = imu.calcGyro(imu.gz);
float mx = imu.calcMag(imu.mx);
float my = imu.calcMag(imu.my);
float mz = imu.calcMag(imu.mz);
mad_filter.update(gx,gy,gz,ax,ay,az,mx,my,mz);
}
in the void loop();
void loop()
{
updateAngles()
// then print the roll pitch and yaw
}
I found the time required for each updateAngles() was 6ms, so I put mad_filter.begin(1000/6) for the sample frequency of the filter. Altough the freq for the filter does not match the sample_freq for the sensor, I guess this is not the problem. A filter freq smaller than the sensor sample freq should not cause any probelm.
I also tried to match the filter freq with the sensor sample freq and set the update freq like described in https://www.arduino.cc/en/Tutorial/Genuino101CurieIMUOrientationVisualiser, like set all sensor sample freq = 60 and the filter update freq = 60, but it still does not work.
The lib I am using and the .ino are all in the attachment.
Thanks in advance for any help!!!
LSM9DS1_Basic_I2C.zip (20.2 KB)
LSM9DS1_Settings.ino (10.1 KB)