Hello guys, I am working on a project where I need to use the vehicles kinematics (accelerations, yaw, roll, pitch). Thus for a proof of concept i decided to use the Nano 33 BLE.
I followed the subject about calibrating and calculating the yaw,pitch and roll using @femmeverbeek library for lsm9ds1 and the Madgwick filter and the code from this thread.(link)
My question is: is that enough to obtain the kinematics of a moving car or should I use another sensor/algorithm for more precision ?
thanks in advance for your help!
My code:
#include <Arduino.h>
#include <Arduino_LSM9DS1.h>
#include <MadgwickAHRS.h>
// initialize a Madgwick filter:
Madgwick filter;
#define gscale 1;
void setup()
{
Serial.begin(115200);
// attempt to start the IMU:
if (!IMU.begin())
{
Serial.println("Failed to initialize IMU");
// stop here if you can't access the IMU:
while (true);
}
//Accelerometer setup
IMU.setAccelFS(3);
IMU.setAccelODR(5);
IMU.setAccelOffset(-0.000387, -0.004826, -0.010827);
IMU.setAccelSlope (1.000736, 0.996282, 1.002104);
//gyroscope setup
IMU.gyroUnit = DEGREEPERSECOND;
IMU.setGyroFS(3);
IMU.setGyroODR(5);
IMU.setGyroOffset (0.055847, -0.537537, 0.391968);
IMU.setGyroSlope (1.149754, 1.126221, 1.185088);
//magnetometer setup
IMU.setMagnetFS(0);
IMU.setMagnetODR(8);
IMU.setMagnetOffset(35.554199, -5.238647, -58.648682);
IMU.setMagnetSlope (1.701424, 1.518531, 1.521027);
Serial.println("Gyro settting ");
Serial.print("Gyroscope FS= "); Serial.print(IMU.getGyroFS());
Serial.print("Gyroscope ODR="); Serial.println(IMU.getGyroODR());
Serial.print("Gyro unit="); Serial.println(IMU.gyroUnit);
//
// The slowest ODR determines the sensor rate, Accel and Gyro share their ODR
float sensorRate = min(IMU.getGyroODR(),IMU.getMagnetODR());
// start the filter to run at the sample rate:
filter.begin(sensorRate);
}
void loop()
{
// values for acceleration & rotation:
float xAcc, yAcc, zAcc;
float xGyro, yGyro, zGyro;
float xMag, yMag, zMag;
static int count=0;
// values for orientation:
float roll, pitch, heading;
// check if the IMU is ready to read:
if (IMU.accelerationAvailable() &&
IMU.gyroscopeAvailable() && IMU.magneticFieldAvailable())
{
// read all 9 DOF of the IMU:
IMU.readAcceleration(xAcc, yAcc, zAcc);
IMU.readGyro(xGyro, yGyro, zGyro);
IMU.readMagneticField(xMag, yMag, zMag);
// update the filter, which computes orientation:
// note X and Y are swapped, X is inverted
filter.update( yGyro,xGyro, zGyro, yAcc, xAcc, zAcc, yMag, -xMag, zMag);
// print the heading, pitch and roll
roll = filter.getRoll();
pitch = filter.getPitch();
heading = filter.getYaw();
count++;
if (count > 20)
{ count = 0;
//Serial.print("y");
Serial.print(xAcc);
Serial.print(";");
Serial.print(yAcc);
Serial.print(";");
Serial.print(zAcc);
Serial.print(";");
Serial.print(zGyro);
Serial.print(";");
Serial.print(heading);
Serial.print(";");
Serial.print(pitch);
Serial.print(";");
Serial.print(roll);
Serial.println(";");
}
}
}