Vehicle kinematics using the Nano 33 BLE

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(";");
    }  
  }
}

Hi there,
i have been trying to get the roll pitch and yaw using Arduino Nano 33 BLE for the past one month i am able to get some values but the yaw value that i am getting is not correct.
Earlier yaw used to drift when i used accelerometer and gyroscope (6 DOF).That drift is now gone when i used magnetometer along with the accelerometer and gyro. But now i am facing another issue with yaw, that is the yaw value is not giving the correct change in angle .When i am changing the board by 90 degrees i am getting a change of only 60 degrees in the serial moniter. Is there a way to resolve this problem?And does this board give 100% accuracy?

Hi.
allow me to bring my experience in this point.
I am actually developping signal processing for a vehicle car, usign IMU of my Nano 33 BLE.
I made (what I can) to calibrate the accelerometer and get good results. To synthetise: because of linearity and offset, your +1G, -1G and zero G are not exactly in symetry. The same observation was made for the gyro but unfortunately, we dont have at home a reference point for rotation.
So, my gyro on axis Z (the one requested to see the car spinning) have a rough value of +80 (in bytes) for zero rotation (that's is my offset). With a stable zero signal, I provoke counterclockwise and clockwise quarter of circle (to reach clean and understandable value like 90°, 180°, 270° and back to0/360°).
I observe half a complete spin will give me 160° in value for 180° expected. by repeating the rotation, I can observe that data are consistent in time (important point: the value tends to be zero when back to initial position from counter AND clockwise rotation). There is my scale! Half a complete spin will give me the underestimated value of 160. I simply put the equation Value_corrected = Raw_value *160/180 and Voilà!

Please note you should have obtain a far accurate result if you were able (like for accelerometer) to generate constant value from both side of the zero value, and therefore evaluate the real answer curve of the sensor.

And finally: it is important you make sure:

  • data are read frequently from the sensor to ensure a "fresh" view of your environment
  • data are processed by the Arduino as often as you can, so a change in the environment is quickly processed.
  • data are NOT displayed to human eye as frequently as they are processed

from my project:

  • accelerometer and gyroscope are set up on default frequency (119Hz) wich is just larger than 1 mesure/10ms.
  • availability of a new pack of data is checked every 10ms in software (so data should be generated a little more frequently than requested by reading), and then immediately transfered from sensor to RAM in Arduino. This is the time I make calculation on gyro Zaxis and calculate the new direction of the car (and others calculations based on acceleration and magnetometer data).
  • then you are free to use the freshest data to way you want.
  • ultimately, a report is made every second by exporting major data to serial port.

I have the same problem: even after testAndCalibrate, the Madgwick method choice and the RollPitchYaw example of femmeverbeek library (or any other available), the measured yaw is always more different than the true angle.
Furthermore, fusion measures are converging very very slowly to a value. The suggested correction "Raw_value *160/180" does not work; no scale gain can solve the problem. How did you solve the trouble Kinisat and Alwynsajan ? Maybe that the Nano33BLE 9axis sensor is not usable ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.