kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.02k stars 469 forks source link

Inaccurate Yaw Values, with a seemingly calibrated Magnetometer #341

Open silaswaxter opened 5 years ago

silaswaxter commented 5 years ago

Dear Kris, I'm a junior in high and am working on a science research project. I am using an MPU9250, a Teensy 3.2, and the "MPU9250BasicAHRS_t3.ino" with the display code removed. I am having issues getting an accurate Yaw. I have read some of the other issues and it seems that it would be an issue with the magnetometer not being calibrated. However, I followed the steps to calibrate it (see video to correct me if the figure-eight motion is wrong) and graphed my values (see graph link below). The graph shows concentric spheres that have a radius of ~250 mG. I also have an filtering rate > 1kHz. Below is a video of my device. Notice that when I accelerate along an axis, the yaw values drift. I have also had issues in the past where the degrees will be increasing until they hit about 260 then they start decreasing even though my rotational velocity is approx. constant. Any help would be greatly appreciated. Thanks, Silas

Graph:https://drive.google.com/file/d/1wPDlHVcQsQg9OosKEtmkQXdNJDlerU_m/view?usp=sharing Video:https://drive.google.com/file/d/1cub582lOsj0S1ebk31tZGa7HnVYIuDq0/view?usp=sharing

kriswiner commented 5 years ago

Wires more so.

On Sat, Jan 26, 2019 at 10:24 PM SilasWaxter notifications@github.com wrote:

Im going to use I2C over the usb cable. I want to use the usb cable bc they are common, replaceable, and cheap.

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

silaswaxter commented 5 years ago

Not for the consumer. If their wire gets worn out they may have to buy a whole new product and thats crappy for them. If I was someone using it and that happened, I would ask "why didn't they just use a replaceable cord?". I am set using usb cables.

silaswaxter commented 5 years ago

I don't think many of the customers would feel confident enough to replace wires.

kriswiner commented 5 years ago

Whatever.

You might consider powering the sensors using ESP32 GPIO pins (digitalWrite(HIGH/LOW for 3V3 and GND). You might be able to avoid an I2C multiplexer.

On Sat, Jan 26, 2019 at 10:40 PM SilasWaxter notifications@github.com wrote:

I don't think many of the customers would feel confident enough to replace wires.

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

silaswaxter commented 5 years ago

When the sensor starts up, is there initialization code it has to run? A time delay?

kriswiner commented 5 years ago

Yes, probably won't work...

On Sun, Jan 27, 2019 at 10:01 AM SilasWaxter notifications@github.com wrote:

When the sensor starts up, is there initialization code it has to run? A time delay?

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

silaswaxter commented 5 years ago

Ok. What do you think about the pcb? Should I try to customize your pcb with the sensor, or should I get a single layer pcb that connects the sensor and the micor-usb pinout?

kriswiner commented 5 years ago

depends on a lot of things.

On Sun, Jan 27, 2019 at 12:59 PM SilasWaxter notifications@github.com wrote:

Ok. What do you think about the pcb? Should I try to customize your pcb with the sensor, or should I get a single layer pcb that connects the sensor and the micor-usb pinout?

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

silaswaxter commented 5 years ago

Like what?

kriswiner commented 5 years ago

Skill level, experience, application, end user, cost, etc

On Sun, Jan 27, 2019 at 1:36 PM SilasWaxter notifications@github.com wrote:

Like what?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/341#issuecomment-457956570, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qhcGpMbC3ZBREc4dDn2-se-7Oaiiks5vHhvlgaJpZM4Z8yoX .

silaswaxter commented 5 years ago

Hey Kris, I need the angles on all three axises (roll, pitch, yaw) to be a range of 0 to 360. Currently, I have both roll and yaw as this range, but the pitch range is different. The range is from -90 to 90 (see https://drive.google.com/file/d/1kULqbL3oiiO0bxU3yDOV19UMZs2hc9sI/view?usp=sharing). Do you know the equation to change pitch to a 0 to 360?

Current COde ` float roll = atan2(2.0f (qw1 qx1 + qy1 qz1), qw1 qw1 - qx1 qx1 - qy1 qy1 + qz1 qz1); float pitch = asin(2.0f qx1 qy1 + 2.0f qz1 qw1); float yaw = atan2(2.0f (qx1 qy1 + qw1 qz1), qw1 qw1 + qx1 qx1 - qy1 qy1 - qz1 qz1);

pitch = 180.0f / PI; yaw = 180.0f / PI; if(yaw < 0) yaw += 360.0f; // Ensure yaw stays between 0 and 360 roll *= 180.0f / PI; if(roll <0) roll += 360.0f; // Ensure roll stays between 0 and 360`

kriswiner commented 5 years ago

Heading is 0 to 360, pitch from -180 to 180 and roll from -90 to 90 by definition, see https://en.wikipedia.org/wiki/Euler_angles

On Tue, Feb 26, 2019 at 9:44 PM SilasWaxter notifications@github.com wrote:

Hey Kris, I need the angles on all three axises (roll, pitch, yaw) to be a range of 0 to 360. Currently, I have both roll and yaw as this range, but the pitch range is different. The range is from -90 to 90 (see https://drive.google.com/file/d/1kULqbL3oiiO0bxU3yDOV19UMZs2hc9sI/view?usp=sharing http://url). Do you know the equation to change pitch to a 0 to 360?

Current COde ` float roll = atan2(2.0f (qw1 qx1 + qy1 qz1), qw1 qw1 - qx1 * qx1

  • qy1 qy1 + qz1 qz1); float pitch = asin(2.0f qx1 qy1 + 2.0f qz1 qw1); float yaw = atan2(2.0f (qx1 qy1 + qw1 qz1), qw1 qw1 + qx1 qx1 - qy1 qy1 - qz1 * qz1);

pitch = 180.0f / PI; yaw = 180.0f / PI; if(yaw < 0) yaw += 360.0f; // Ensure yaw stays between 0 and 360 roll *= 180.0f / PI; if(roll <0) roll += 360.0f; // Ensure roll stays between 0 and 360`

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

silaswaxter commented 5 years ago

Alright then. Is it possible to measure the angle of the shortest path between two quaternions?

kriswiner commented 5 years ago

What does this mean?

On Tue, Feb 26, 2019 at 9:54 PM SilasWaxter notifications@github.com wrote:

Alright then. Is it possible to measure the angle of the shortest path between two quaternions?

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

silaswaxter commented 5 years ago

Quaternions represent an orientation in 3d space. Between two orientations, there is an axis that both orientations lie on. Is there a way to measure the angle between the two quaternions along this axis?

kriswiner commented 5 years ago

Yes.

On Tue, Feb 26, 2019 at 10:09 PM SilasWaxter notifications@github.com wrote:

Quaternions represent an orientation in 3d space. Between two orientations, there is an axis that both orientations lie on. Is there a way to measure the angle between the two quaternions along this axis?

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

silaswaxter commented 5 years ago

Do you know how to do that?

kriswiner commented 5 years ago

Maybe look at using something like the dot product of the quaternions?

On Tue, Feb 26, 2019 at 11:00 PM SilasWaxter notifications@github.com wrote:

Do you know how to do that?

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

silaswaxter commented 5 years ago

Hey Kris thank you for your previous help.

There seems to be industrial-grade IMUs that are even more accurate then these lower cost sensors. What separates these categories?

I am aiming for the highest accuracy of rotation, meaning I am less worried about accuracy in relation to true orientation (based on Earth) and more interested in the accuracy of rotation between two orientations. I realize that these are intertwined, but does this effect what an optimal sensor fusion algorithm looks like for me?

kriswiner commented 5 years ago

" What separates these categories?"

Cost

If all you care about is rotation a gyro ought to be good enough. If you think another solution might be more appropriate you are just going to have to gove it a try. But the industrial-grade IMUs are pretty pricey.

On Mon, Mar 11, 2019 at 6:36 PM SilasWaxter notifications@github.com wrote:

Hey Kris thank you for your previous help.

There seems to be industrial-grade IMUs that are even more accurate then these lower cost sensors. What separates these categories?

I am aiming for the highest accuracy of rotation, meaning I am less worried about accuracy in relation to true orientation (based on Earth) and more interested in the accuracy of rotation between two orientations. I realize that these are intertwined, but does this effect what an optimal sensor fusion algorithm looks like for me?

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

silaswaxter commented 5 years ago

Ok thank you.

silaswaxter commented 5 years ago

Hey Kris, how familiar are you with machine learning?

kriswiner commented 5 years ago

Not too...why?

I do know that the latest LSM6DS0X accel/gyro has a state machine plus machine learning capability built in, and I will eventually try to make use of this...

On Mon, Apr 8, 2019 at 3:13 PM SilasWaxter notifications@github.com wrote:

Hey Kris, how familiar are you with machine learning?

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

silaswaxter commented 5 years ago

I am familiarizing myself with machine learning. From what I understand, you can create a neural network with inputs, outputs, and layers in between. You then need a large set of data, which is labeled. In other words you have many data sets of inputs with what the outputs should give. The "neural network algortithm" then forms an algortithm to convert the inputs into the outputs.

I am wondering if this would be more efficient then using a traditional method like a kalman, mahony, madgwick filter or if a combination would be optimal. I am planning on contacting some prof. of computer science who specialize in machine learning. Perhaps they can explain the limitations and any flaws in my thinking as well as point me in the right direction.

Mat-Lab has support for machine learning. I was thinking of using it. It also has support for of offloading the code in c to embedded processors.

While researching better IMUs, I came across a few that had "static gps heading".

http://www.airmar.com/productdescription.html?id=95 (heading: 1deg static, 2deg dynamic) https://inertialsense.com/products/dual-gnss-ins-compass/ (heading: gps 0.3deg w/ 1 meter baseline)

For my application, the device is strapped to a person and measuring their joints. They device would not be moving in a vector, which could be turned into a heading. Does the gps/gnss only aid in accuary when the sensor is traveling in a direction? It probably depends on the accuracy of the gnss system.

I'm interested to hear your thoughts.

kriswiner commented 5 years ago

Required for accurate absolute heading estimation in order of importance are 1) quality sensors, 2) proper sensor calibration, ..., 42) sensor fusion algorithm, 100+) everything else. Using two or more absolute orientation devices to track joint angle is a common use for applications such as ergonometrics, training, activity capture and feedback, etc. The devices are usually worn in the pants or shirt pocket, on the legs, on the small of the back, on the hand and wrist in a glove, or various combinations of these, etc.This is done for animals as well, like horses, etc.

Once you have an accurate absolute orientation estimation engine then you can catalog various body movements in terms of measured changes in orientation and use this data base to construct a machine learning algorithm(s) to identify particular movements and gestures. Neural networks is one way to do this, but as I mentioned there is at least one accel/gyro with a machine learning capability that I am interested in. The idea would be to encapsulate in the device algorithm(s) to detect various gestures. The advantage is that no host processing is required resulting in very fast ID of what a person or animal is doing in a contextually meaningful way.

GNSS is useless for tracking human gestural activity unless the idea is to track travel motion (location and velocity) as opposed to gestures and body movements.

On Mon, Apr 8, 2019 at 9:07 PM SilasWaxter notifications@github.com wrote:

I am familiarizing myself with machine learning. From what I understand, you can create a neural network with inputs, outputs, and layers in between. You then need a large set of data, which is labeled. In other words you have many data sets of inputs with what the outputs should give. The "neural network algortithm" then forms an algortithm to convert the inputs into the outputs.

I am wondering if this would be more efficient then using a traditional method like a kalman, mahony, madgwick filter or if a combination would be optimal. I am planning on contacting some prof. of computer science who specialize in machine learning. Perhaps they can explain the limitations and any flaws in my thinking as well as point me in the right direction.

Mat-Lab has support for machine learning. I was thinking of using it. It also has support for of offloading the code in c to embedded processors.

While researching better IMUs, I came across a few that had "static gps heading".

http://www.airmar.com/productdescription.html?id=95 (heading: 1deg static, 2deg dynamic) https://inertialsense.com/products/dual-gnss-ins-compass/ (heading: gps 0.3deg w/ 1 meter baseline)

For my application, the device is strapped to a person and measuring their joints. They device would not be moving in a vector, which could be turned into a heading. Does the gps/gnss only aid in accuary when the sensor is traveling in a direction? It probably depends on the accuracy of the gnss system.

I'm interested to hear your thoughts.

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

silaswaxter commented 5 years ago

How is sensor calibration done now? I rember waving the device in a figure eight for the magnetometer. How about the accel and the gyro?

Do you think a machine learning algotrithm could be used instead of the senor fusion algorithm? Would it be more effective?

What if the machine learning algorithm was more like a correction filter? The sensor fusion algorithm would run off the raw data. The output would be taken with the raw data and put into the machine learnging algorithm to refine the results.

Note: My project is creating a device to measure the range of motion of a joint. I know these already exist, but they are expensive, relatively innaccurate, and not user friendly.

kriswiner commented 5 years ago

" motion of a joint. I know these already exist, but they are expensive, relatively innaccurate, and not user friendly."

Cell phone sensors and proper methods run on a microcontroller makes this cheap, accurate, and easy to do. This is my point...

On Tue, Apr 9, 2019 at 12:01 PM SilasWaxter notifications@github.com wrote:

How is sensor calibration done now? I rember waving the device in a figure eight for the magnetometer. How about the accel and the gyro?

Do you think a machine learning algotrithm could be used instead of the senor fusion algorithm? Would it be more effective?

What if the machine learning algorithm was more like a correction filter? The sensor fusion algorithm would run off the raw data. The output would be taken with the raw data and put into the machine learnging algorithm to refine the results.

Note: My project is creating a device to measure the range of motion of a joint. I know these already exist, but they are expensive, relatively innaccurate, and not user friendly.

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

silaswaxter commented 5 years ago

Your right. I misread this post. I am going to order new/fresh em7180 as well as a rotation stage to test the headings. This will allow me to check if my results are the same. If they are not, I would likely have error(s) in my code. How did you find the true heading for the rotation stage? A compass? What type of compass?

kriswiner commented 5 years ago

We have used https://hackadaycom.files.wordpress.com/2019/03/hackaday_journal-gregorytomasch_kriswiner-heading_accuracy_using_mems_sensors.pdf a rotation stage to test accuracy, and we are using a 2-stage goniometer to test accuracy. We are also developing a simple and inexpensive calibration tool which we expect to sell on Tindie soon. This should allow anyone to easily and properly calibrate their 9 DoF sensors for best absolute orientation accuracy.

On Tue, Apr 9, 2019 at 3:17 PM SilasWaxter notifications@github.com wrote:

Your right. I misread this post https://github.com/kriswiner/EM7180_SENtral_sensor_hub/wiki/H.-Typical-Results-Using-the-SENtral. I am going to order new/fresh em7180 as well as a rotation stage to test the headings. This will allow me to check if my results are the same. If they are not, I would likely have error(s) in my code. How did you find the true heading for the rotation stage? A compass? What type of compass?

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

silaswaxter commented 5 years ago

Hey Kris, I am looking into a battery system for my device. Do you know how much current is drawn for the EM7180 for both startup and run-time?

kriswiner commented 5 years ago

Not sure exactly, it will depend on your implementation: sensor sample rates, quaternion rate, etc, I would guess 1 mA average current, maybe less

On Tue, Apr 23, 2019 at 2:31 PM SilasWaxter notifications@github.com wrote:

Hey Kris, I am looking into a battery system for my device. Do you know how much current is drawn for the EM7180 for both startup and run-time?

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

silaswaxter commented 5 years ago

Okay thanks.

silaswaxter commented 4 years ago

Hey Kris hope you are doing well. I have changed the design of my device so now each of the two sensors have their own micro-controller. The micro-controllers being used are the D2 mini, which is a ESP8266 module. I am using your sketch, ESP32/EM7180/EM7180_LSM6DSM_LIS2MDL_LPS22HB_ESP32. I ran the sketch and noticed that there was no calibration like I have seen in other IMU sketches. The test seemed to be pretty accurate, however. Could you explain what the deal is?

PS: I'm not sure this is the best way to contact you. If you would prefer, I'd be happy to contact you another way.

kriswiner commented 4 years ago

Email at tleracorp@gmail is always best.

The EM7180 automatically calibrates the gyro at rest and the mag after some motion.

On Wed, Aug 14, 2019 at 4:50 PM SilasWaxter notifications@github.com wrote:

Hey Kris hope you are doing well. I have changed the design of my device so now each of the two sensors have their own micro-controller. The micro-controllers being used are the D2 mini, which is a ESP8266 module. I am using your sketch, ESP32/EM7180/EM7180_LSM6DSM_LIS2MDL_LPS22HB_ESP32. I ran the sketch and noticed that there was no calibration like I have seen in other IMU sketches. The test seemed to be pretty accurate, however. Could you explain what the deal is?

PS: I'm not sure this is the best way to contact you. If you would prefer, I'd be happy to contact you another way.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/341?email_source=notifications&email_token=ABTDLKXL3COGNZUESDKDFODQESK23A5CNFSM4GPTFIL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4KNYBI#issuecomment-521460741, or mute the thread https://github.com/notifications/unsubscribe-auth/ABTDLKVUZ4K7OVCLXHGJMTDQESK23ANCNFSM4GPTFILQ .

silaswaxter commented 4 years ago

Thank you!