kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.03k stars 472 forks source link

Joint angle calculation #46

Open ijunglee opened 8 years ago

ijunglee commented 8 years ago

I want to attach the 9-axis imu on finger to calculate the joint angles. I have used Madgwick Algorithm and got the quaternion of imu after each update. I know the quaternion can show the attitude of each sensor's rotation without gimbal lock, but how can I calculate and show the angle between two imu? When my hand back is toward up, I can simply use the difference between euler angles of two imu.(roll of imu1 - roll of imu2) However, when my hand back toward left or right, I can not get the correct angle. Do you have any ideas about solving this problem? Thank you very much.

kriswiner commented 8 years ago

You can use the Euler angles but they won't be correct unless you properly calibrate your sensor first.

How did you perform the calibration?

-----Original Message----- From: ijunglee [mailto:notifications@github.com] Sent: March 7, 2016 1:43 AM To: kriswiner/MPU-9250 Subject: [MPU-9250] Joint angle calculation (#46)

I want to attach the 9-axis imu on finger to calculate the joint angles. I have used Madgwick Algorithm and got the quaternion of imu after each update. I know the quaternion can show the attitude of each sensor's rotation without gimbal lock, but how can I calculate and show the angle between two imu? When my hand back is toward up, I can simply use the difference between euler angles of two imu.(roll of imu1 - roll of imu2) However, when my hand back toward left or right, I can not get the correct angle. Do you have any ideas about solving this problem? Thank you very much.

Reply to this email directly or view it on GitHub https://github.com/kriswiner/MPU-9250/issues/46 . https://github.com/notifications/beacon/AGY1qq1SvGmSnduUtnOfi5w6w55bj7T6ks5 pq_MQgaJpZM4Hqnz0.gif

ijunglee commented 8 years ago

For magnetometer, I rotated and moved the sensor as 8-shape to find the min-max value in each axis. After getting the min-max values, I average them as the offset in each axis.

For accelerometer and gyroscope, I put the imu on the table(with Z-axis toward up), and average every input (maybe receive 1000 records). For accelerometer, I remove (0g, 0g, 1g) to get the offset in each axis because this is the ideal value for acceleration when Z-axis is toward up. For gyroscope, I think when the imu is stable, the value should be (0, 0, 0) rad/s. So the average values are offset for gyroscope. (Is this correct?)

This is what I perform for calibration, I am not sure the method is correct. Please give me advice, thanks for a lot!

kriswiner commented 8 years ago

Yes, this is correct. Can you verify that the magnetic response surface is centered at the origin after calibration? Plot Mx vs Mz and Mx vs My. Are the plots a spherical cloud or do you have a lot of ellipsoidal variation?

To get adequate Madgwick sensor fusion the algorithm has to converge for ach data set. This means the algorithm should be running at four or five times the rate of the gyro sample rate. So if you choose a gyro sampl rate of 200 Hz with 40 Hz bandwidth (a good choice) your processor should be able to run the sensor fusion algorithm at 1 kHz or so.

What processor are you using?

-----Original Message----- From: ijunglee [mailto:notifications@github.com] Sent: March 7, 2016 6:42 PM To: kriswiner/MPU-9250 Cc: Kris Winer Subject: Re: [MPU-9250] Joint angle calculation (#46)

For magnetometer, I rotated and moved the sensor as 8-shape to find the min-max value in each axis. After getting the min-max values, I average them as the offset in each axis.

For accelerometer and gyroscope, I put the imu on the table(with Z-axis toward up), and average every input (maybe receive 1000 records). For accelerometer, I remove (0g, 0g, 1g) to get the offset in each axis because this is the ideal value for acceleration when Z-axis is toward up. For gyroscope, I think when the imu is stable, the value should be (0, 0, 0) rad/s. So the average values are offset for gyroscope. (Is this correct?)

This is what I perform for calibration, I am not sure the method is correct. Please give me advice, thanks for a lot!

Reply to this email directly or view it on GitHub https://github.com/kriswiner/MPU-9250/issues/46#issuecomment-193567775 . https://github.com/notifications/beacon/AGY1qhlE4JKjzd1udZBF05Q_emSlxCDTks5 prOHlgaJpZM4Hqnz0.gif

ijunglee commented 8 years ago
  1. Thanks for your response. I will try to verify the magnetic data.
  2. I use the MSP430F5438A. How do I choose the sampling rate and bandwidth of the acc, gyro and mag? I used the LSM9DS0 sensor for the same project before. And I use the sampling rate 800 Hz for accelerometer, 760 Hz for gyroscope, and 100 Hz for magnetometer. However, I am not sure how to choose the proper bandwidth.

Thanks for your kindly help. I look forward to your reply.

kriswiner commented 8 years ago

These can all be chosen in the MPU9250 initialization function.

-----Original Message----- From: ijunglee [mailto:notifications@github.com] Sent: March 7, 2016 7:08 PM To: kriswiner/MPU-9250 Cc: Kris Winer Subject: Re: [MPU-9250] Joint angle calculation (#46)

  1. Thanks for your response. I will try to verify the magnetic data.
  2. I use the MSP430F5438A. How do I choose the sampling rate and bandwidth of the acc, gyro and mag? I used the LSM9DS0 sensor for the same project before. And I use the sampling rate 800 Hz for accelerometer, 760 Hz for gyroscope, and 100 Hz for magnetometer. However, I am not sure how to choose the proper bandwidth.

Thanks for your kindly help. I look forward to your reply.

Reply to this email directly or view it on GitHub https://github.com/kriswiner/MPU-9250/issues/46#issuecomment-193579671 . https://github.com/notifications/beacon/AGY1qkVSO8PLV-pJ2Kd4p7TaFkIocK-Pks5 prOgqgaJpZM4Hqnz0.gif

ijunglee commented 8 years ago

Thanks for your reply. I will try it. And what are the proper sampling rate and bandwidth of acc and mag?

kriswiner commented 8 years ago

200/40 Hz for accel, 100 Hz for the mag although 8 Hz should work well too.

-----Original Message----- From: ijunglee [mailto:notifications@github.com] Sent: March 7, 2016 7:38 PM To: kriswiner/MPU-9250 Cc: Kris Winer Subject: Re: [MPU-9250] Joint angle calculation (#46)

Thanks for your reply. I will try it. And what are the proper sampling rate and bandwidth of acc and mag?

Reply to this email directly or view it on GitHub https://github.com/kriswiner/MPU-9250/issues/46#issuecomment-193589422 . https://github.com/notifications/beacon/AGY1qnjW7UHTc3hkENObXM2_c-BkqpdCks5 prO8vgaJpZM4Hqnz0.gif

ijunglee commented 8 years ago

Thanks for your response. I will try it. Do you have any idea about how to get the joint angle between 2 sensors using euler angle? Thank you very much.

kriswiner commented 8 years ago

This is trivial if in the same plane, otherwise requires some straightforward trigonometry.

-----Original Message----- From: ijunglee [mailto:notifications@github.com] Sent: March 7, 2016 10:12 PM To: kriswiner/MPU-9250 Cc: Kris Winer Subject: Re: [MPU-9250] Joint angle calculation (#46)

Thanks for your response. I will try it. Do you have any idea about how to get the joint angle between 2 sensors using euler angle? Thank you very much.

Reply to this email directly or view it on GitHub https://github.com/kriswiner/MPU-9250/issues/46#issuecomment-193621730 . https://github.com/notifications/beacon/AGY1qlCo-aqYxPtCLfIQhFwLwT5igIzwks5 prRMbgaJpZM4Hqnz0.gif

ijunglee commented 8 years ago

Hello, this is the before and after of my magnetometer calibration. I found that the data form more like a sphere after calibration. Is the result correct? figures up are Mx vs Mz and Mx vs My without calibration, below are after calibration MagCal.pdf

ijunglee commented 8 years ago

Sorry, I think the result is much better. magcalibration

kriswiner commented 8 years ago

Yes, this is much better. Make sure the initial bias values are 0x8000 for max and 0x7FFF for min.

thisum commented 5 years ago

@ijunglee, were you able to calculate the joint angle with quaternions or euler angles?

ijunglee commented 5 years ago

@thisum

I use quaternions to calculate the inner product of two quaternions (as vectors) to get the joint angle. You can get a good result if your magnetometer is well-calibrated. But I am not sure if the method is correct, maybe we can have more discussion.

I also try the function Quaternion.Angle in Unity 3D...I think it also uses the similar method.

thisum commented 5 years ago

I tested the calibration as described above and seems working fine. But the problem I'm having is to get the joint angle. I used q_relative = q_shin*qt.q_inv(q_thigh) to get the relative quaternion of the leg. And my plan was to calculate Euler angles from that. But it's not the correct way. Still trying to figure out the appropriate way.

Inner product is cross product?

kriswiner commented 5 years ago

Why not simply use the Euler angle differences?

On Sun, Dec 9, 2018 at 1:48 PM Thisum Buddhika notifications@github.com wrote:

I tested the calibration as described above and seems working fine. But the problem I'm having is to get the joint angle. I used q_relative = q_shin*qt.q_inv(q_thigh) to get the relative quaternion of the leg. And my plan was to calculate Euler angles from that. But it's not the correct way. Still trying to figure out the appropriate way.

Inner product is cross product?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/46#issuecomment-445574941, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qg-VeDBoLHdGRWm38zKcQ7G8sIOSks5u3YUigaJpZM4Hqnz0 .

thisum commented 5 years ago

One problem is the gimbal lock. For example, I'm trying to measure the angle of the knee with respect to the thigh IMU. Let's say the knee angle is 90 degrees. while having the angle fixed, I move the leg in the 3D space, even lying on the ground. So all these times, the knee angle is 90.

anziboy commented 5 years ago

Hi, @ijunglee, I am having the same problem for when I'm trying to measure the absolute knee angle using two BNO055 adafruit sensors on arduino. I have fully calibrated both of the sensors and I'm getting the pitch, yaw and roll angles, however my angle values are incorrect. Any thoughts or tips on how I can get the correct ones? Thank you so much ,

best wishes, Anza