New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][IMU] Correct calibration of Gyroscope #57
Conversation
Plus some other fixes
imu_sensor_notes.md
Outdated
|
||
### Gyroscope - Rotation (in revolutions/s) | ||
|
||
The equation will become: | ||
|
||
`acc_vector_component = acc_raw_component * acc_coeff * 0.0027777778` | ||
`acc_vector_component = (acc_raw_component - uint16_to_int16(cal_gyro_offset)) * acc_coeff * 0.0027777778` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks to me like it's using the gyro offset in calculation of an acceleration vector. Should it actually be a gyro vector (gyro_raw_component, etc), given its context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste mistake, I will fix it
Hi @CTCaer, thanks for including me in this. It looks like a typo at lines 137 and 145, with acc_vector_component being used with gyro offsets. But otherwise the changes about offset look good to me. However, for my own education's sake: it's not clear to me why gyro offset is used to calculate the gyro coefficient, or at least not why it's used as is: Thanks for your help! |
@JibbSmart Well for ACC it's clear why. There's a lot mumbo jumbo in the decompiled switch code though. I will check the code again, before proceeding with an OK. |
@dekuNukem @JibbSmart So basically the simple way is: And the simple drift mitigation way: So it seems that the noise is also scaled by rotation. And that's why it is also used for scaling, additionally to offset (for still noise removal). |
@CTCaer EDIT: Though I understand you're just going with what the Switch does |
Actually bigger and smaller coefficients. I really don't know why they chose to do this. No matter how I look at the calibration code, it's what it does. And it seems to work well for me. Also the code constantly uses zero drift recalibration algorithms when it detects stillness. And indeed what I wrote is mostly the switch usage scenario. I will again study the code though. Maybe I'm really missing something. |
@JibbSmart But, I can't decode the exact value.. |
I can't really tell the difference between constant coefficients and using the offset in the coefficient calculation. Offseting the raw output is the most important thing, it seems. The offsets make such a tiny difference to the coefficient. The difference is much smaller than the (still tiny) error I'm actually getting from the Switch's calibration, so I'm happy to ignore it for my purposes (as a gyro mouse, which only needs to turn x and y rotational velocities into x and y mouse movements multiplied by a user-defined sensitivity), although I imagine the exact details are probably important for accurately estimating real world changes in orientation (which I'm not doing).
That seems plausible.
Wow, the Switch does this itself? I thought it was just something game developers were doing. Thanks for the info! I noticed it in Splatoon 2, and especially DOOM, where tracking distant slow targets while keeping a steady hand (movements that look like drift to the console/game), the aimer would stop as it recalibrates. Then I actually stop moving my hand and it'd drift in the opposite direction until it detects the drift-like motion and "stillness" of the controller and recalibrates again. I quite dislike it, and much prefer games would encourage people to put down the controller like you describe. It's not hard, the game doesn't have to do it itself (the Switch has the option in system settings, although it can be nice to do it oneself and be more confident it's properly calibrated), and it's something I've got going in my project that treats Switch controllers and DualShock 4s the same. And the gyro bias changes so slowly over time that one calibration will last multiple play sessions (so it's nice that the JoyCons save their calibration through spi!).
Interesting! I'm curious if you do manage to decode it at some point, but I'm satisfied that I've got useful results already. Thank you so much for all the clear explanations :) I'm happy with what I have working, so please don't feel any pressure to decode anything else on my account. |
Plus some other fixes
@wormyrocks, @mfosse, @JibbSmart