FemmeVerbeek / Arduino_LSM9DS1

LSM9DS1 Library for Arduino
Other
63 stars 14 forks source link

ODR is inaccurate #17

Closed tdrellich closed 3 years ago

tdrellich commented 3 years ago

I'm using the Arduino Nano 33 BLE Sense board. If in my setup I have:

IMU.setGyroFS(2);
IMU.setGyroODR(5);

IMU.setAccelFS(2);
IMU.setAccelODR(5);

I would expect the ODR of the accelerometer and gyro to be 476Hz. however the IMU.getAccelODR() and IMU.getGyroODR() commands return that I'm getting 469.61Hz. This wouldn't be particularly problematic, however, if I use the following loop:

float acc_x, acc_y, acc_z;
float total_acc_x = 0;
float total_acc_y = 0;
float total_acc_z = 0;
int n_acc_measurements = 0;

float gyro_p, gyro_q, gyro_r;
float total_p = 0;
float total_q = 0;
float total_r = 0;
int n_gyro_measurements = 0;

start_time = micros();
t = micros();

while (t - start_time < 3000000) {

        if (IMU.accelAvailable()){
            IMU.readRawAccel(acc_x, acc_y, acc_z);
            total_acc_x += acc_x;
            total_acc_y += acc_y;
            total_acc_z += acc_z;
            n_acc_measurements++;
        }

        if (IMU.gyroAvailable()){
            IMU.readRawGyro(gyro_p,gyro_q,gyro_r);
            total_p += gyro_p;
            total_q += gyro_q;
            total_r += gyro_r;
            n_gyro_measurements++;
        }
}

and then output n_acc_measurement / 3.0 and n_gyro_measurements / 3.0 I'm getting a frequency of 143.33Hz

FemmeVerbeek commented 3 years ago

You could have saved yourself writing this program, because it's already in the library. The functions getAccelODR() getGyroODR() and getMagnetODR() return the actual ODR value as was measured upon the last change in register settings. It is all explained in the documentation. Yes the original documentation is very inacurate about the actual odr values. That was the reason for doing it this way.