juliangaal / mpu6050

MPU6050 embedded-hal driver written in Rust
https://crates.io/crates/mpu6050
MIT License
52 stars 31 forks source link

Fix bug when convert raw gyro data to rad/s #40

Closed tfx2001 closed 2 years ago

juliangaal commented 2 years ago

What is your source for this change?

tfx2001 commented 2 years ago

When I use get_gyro(), the range of results looks a bit strange. Then I tried to derive it myself and found that it was a algorithm problem.

After this change, I use the result in Madgwick fusion and it works good.

juliangaal commented 2 years ago

How did you setup madgwick fusion and/or could you post before and after? Thanks!

Which revision of the manual did you get the image above from? Or is it some other source?

tfx2001 commented 2 years ago

How did you setup madgwick fusion and/or could you post before and after? Thanks!

Which revision of the manual did you get the image above from? Or is it some other source?

I'm sorry, I don't have a record of before and after changes. And the formula above is my own derivation. If I have misunderstood, please point it out and apologize for that.

juliangaal commented 2 years ago

no worries, I am not 100% sure myself.

Which madgwick filter package did you use? I'll check it out as soon as I can, prob Christmas Break

tfx2001 commented 2 years ago

The AHRS package I use:

[dependencies]
ahrs = "0.4"

And here is my test code: main.rs

juliangaal commented 2 years ago

perfekt, thank you!

HeikoRibberink commented 2 years ago

Can you please still push this branch to master, and push to crates.io?

juliangaal commented 2 years ago

You are absolutely correct in your assessment @tfx2001.

The confusion for me arose in the way I apply "sensitivity", basically the inverse "resolution".

According to the datasheet, depending on the scale configuration of the gyroscope, the data needs to be scaled, like this:

250DPS => 250.0 / 32768.0,
500DPS => 500.0 / 32768.0,
1000DPS => 1000.0 / 32768.0,
2000DPS => 2000.0 / 32768.0,

RAW_DATA * (!) FACTOR is the default scaling. I tried to save some calculations and saved results of this scaling factor as the "sensitivity"

// 32768.0 / 250.0, ....
pub const GYRO_SENS: (f32, f32, f32, f32) = (131., 65.5, 32.8, 16.4);

of course, this "sensitvity" must be applied my dividing, exactly as you have found.

Thanks again, I will merge and publish to crates.io.

juliangaal commented 2 years ago

done