kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.04k stars 471 forks source link

Initialization Madgwick algorithm #270

Open francescoricciuti opened 6 years ago

francescoricciuti commented 6 years ago

Hi Kris,

first of all, thanks for this blog, it's amazing and super useful!!

I have a question about Madgwick's algorithm which probably arises from my wrong understanding of what the algorithm does.

From what I understood, the algorithm uses the data from the gyro and aligns them with earth's reference frame thanks to accelerometer and magnetometer. If this is true, I would expect that no initialization for the quaternion is needed, because whatever is the initialized quaternion it should align with earths reference frame after the first iteration of optimization.

And here comes my problem: when I feed the algorithm with my data (which i prepared by calibrating everything and expressing everything in NED reference frame) I get a result which is not aligned with earths reference frame, but with my sensor's one. I know this because I'm starting the log with the robot facing sud and the resulting initial yaw from the algorithm is zero (while it should be 180 degrees).

The yaw I'm talking about is the one calculated from the conjugate of the final quaternion.

The problem is that if I initialize the quaternion with the correct orientation ([0 0 0 1] in my case), everything looks super fine.

Is this normal in your opinion, or am I doing something wrong? Does the algorithm need an initialization of the quaternion?

Thank a lot, Francesco

kriswiner commented 6 years ago

" The problem is that if I initialize the quaternion with the correct orientation ([0 0 0 1] in my case), everything looks super fine. "

This doesn't sound like a problem, it sounds like a solution and I would just use and move on.

I don't know exactly what you are doing to calculate the yaw (and don't really want to) but if you are getting good results with this initialization, then congratulations!

On Mon, Apr 23, 2018 at 7:01 AM, francescoricciuti <notifications@github.com

wrote:

Hi Kris,

first of all, thanks for this blog, it's amazing and super useful!!

I have a question about Madgwick's algorithm which probably arises from my wrong understanding of what the algorithm does.

From what I understood, the algorithm uses the data from the gyro and aligns them with earth's reference frame thanks to accelerometer and magnetometer. If this is true, I would expect that no initialization for the quaternion is needed, because whatever is the initialized quaternion it should align with earths reference frame after the first iteration of optimization.

And here comes my problem: when I feed the algorithm with my data (which i prepared by calibrating everything and expressing everything in NED reference frame) I get a result which is not aligned with earths reference frame, but with my sensor's one. I know this because I'm starting the log with the robot facing sud and the resulting initial yaw from the algorithm is zero (while it should be 180 degrees).

The yaw I'm talking about is the one calculated from the conjugate of the final quaternion.

The problem is that if I initialize the quaternion with the correct orientation ([0 0 0 1] in my case), everything looks super fine.

Is this normal in your opinion, or am I doing something wrong?

Thank a lot, Francesco

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/270, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qt-dHLYbize5-jaTMWQDNTTMizLtks5trd7EgaJpZM4Tf9Bc .