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?
Is this effecting your COVID project?
No. Oh sorry i selected covid by mistake.
@alwynsajan, your topic moved to project guidance.
It's probably something in the code you found or wrote.
Please share the entire sketch with us so we can take a peek.
The are inaccuracies, but you can expect to do a bit better than 60 should be 90. Quite a bit better.
a7
#include "MadgwickAHRS.h"
#include "Arduino_LSM9DS1.h"
// initialize a Madgwick filter:
Madgwick filter;
// sensor's sample rate is fixed at 104 Hz:
const float sensorRate = 104.00;
float sax, say, saz, sgx, sgy, sgz;
void setup() {
Serial.begin(9600);
// 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);
}
// start the filter to run at the sample rate:
filter.begin(sensorRate);
}
long lastPrint = 0;
long nz = 0;
float x = 0, y = 0, z = 0;
void loop() {
// values for acceleration and rotation:
float xAcc, yAcc, zAcc;
float xGyro, yGyro, zGyro;
float xmag,ymag,zmag;
// values for orientation:
float roll, pitch, heading;
// check if the IMU is ready to read:
if (IMU.accelerationAvailable() &&
IMU.gyroscopeAvailable()) {
// read accelerometer &and gyrometer:
IMU.readAcceleration(xAcc, yAcc, zAcc);
IMU.readGyroscope(xGyro, yGyro, zGyro);
IMU.readMagneticField(xmag,ymag,zmag);
nz++;
if (nz < 500) //hold the board still until nz is 500 for calibration
{
sgz += zGyro;
sgx += xGyro;
sgy += yGyro;
x = sgx / nz;
y = sgy / nz;
z = sgz / nz;
}
// update the filter, which computes orientation:
filter.update(xGyro - x, yGyro - y, zGyro - z, xAcc, yAcc, zAcc,xmag,ymag,zmag);
// print the heading, pitch and roll
roll = filter.getRoll();
pitch = filter.getPitch();
heading = filter.getYaw();
long a = millis();
if (lastPrint + 333 < millis())
{
Serial.print(" ~~Orientation: ");
Serial.print("Yaw : ");
Serial.print(heading);
Serial.print(" Pitch : ");
Serial.print(pitch);
Serial.print(" Roll : ");
Serial.println(roll);
}
}
}
To get correct yaw angles, you must calibrate the magnetometer. The best procedure is Tutorial: How to calibrate a compass (and accelerometer) with Arduino | Underwater Arduino Data Loggers
Specific example: https://forum.pololu.com/t/correcting-the-balboa-magnetometer/14315
There are simpler procedures that don't work as well.
No. Nothing ever does.
Oh , I just wanted to know is it possible to get the required data?
What are your requirements?
I want to get the roll pitch and yaw values correctly.
For the most accurate results with all three angles, calibrate both the accelerometer and the magnetometer. The accelerometer measures roll and pitch, and the magnetometer, yaw.
Depending on how careful you are with the calibration, you might be able to get accuracy of +/- 3 degrees.
So how is this calibration done exatly?
In the earlier mentioned article i think they are using some other stuffs for calibration. Cant i just do the calibration with code itself?
The links in post #8 explain the calibration process in great detail.
It will take some effort on your part.
But they are using some softwares that isn,t available now!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.