Apply gravity compensation to accelerometer readings - #138
Apply gravity compensation to accelerometer readings#138bjornhbengtsson wants to merge 6 commits into
Conversation
|
Linked child PR. Please remember to do that going forward so we can navigate between dependent code easier! |
There was a problem hiding this comment.
@NArmistead Gonna want you to spot check the math here, but I'm happy from a software design perspective.
The one change request on the child PR is to move the tests into this repo.
| QUAT vector_world | ||
| ) | ||
| { | ||
| QUAT attitude_conj = quat_conj(attitude); |
|
Video resource if anyone wants extra study material on the subject of frame rotations: https://youtu.be/4WKghhPzonE?is=AnQzI4YVkjorqC7R |
dr shane ross!!! 🗣️🗣️🗣️🗣️ |
NArmistead
left a comment
There was a problem hiding this comment.
Math looks good too but I want to wait until we try it on hardware before we merge. Unless you already did that then go ahead and send it. Also thanks for writing unit tests for this and getting that set up for mod although I have one non-critical request for remaning the test folder
| velo_x * velo_x + | ||
| velo_y * velo_y + | ||
| velo_z * velo_z |
| ( | ||
| quat_mult(attitude, vector_body), | ||
| attitude_conj | ||
| ); |
There was a problem hiding this comment.
rare case where i wish we had operator overloading
| float accel_x = imu_converted->accel_x; | ||
| float accel_y = imu_converted->accel_y; | ||
| float accel_z = imu_converted->accel_z; | ||
| /* The world frame defines gravity in the +Z direction. */ |
There was a problem hiding this comment.
we should probably mention somewhere that we use NED
| return quat_mult | ||
| ( | ||
| quat_mult(attitude, vector_body), | ||
| attitude_conj | ||
| ); |
There was a problem hiding this comment.
this is hard to read but I think the comment explains it
one of the rare cases where I kinda wish we had operator overloading lol
There was a problem hiding this comment.
only thing I would maybe like you to change is to rename the "test" folder to "_test" to be consistent with driver
There was a problem hiding this comment.
+1 tbh, I did that in driver to make it not look like we had a driver named test. would be good here since the test framework submodule doesnt live in mod and that might be ambiguous
|
Sounds good. Haven't tested it on hardware |
|
@bjornhbengtsson actually can we wait to merge this and #142 until #134 goes in? most of that PR is reviewed and ready so we don't want to creep it too much |
|
Yup we can wait. And if you want to wait on reviewing Mahony for Kalman that's cool. I'm deep into Kalman by now |
Description
Adds quaternion vector rotation helpers and uses the current body to world attitude estimate to remove gravity from accelerometer measurements before velocity integration.
Changes
v_body = conjugate(q) * v_world * qv_world = q * v_body * conjugate(q)+Z.powf(x, 2)calls with direct multiplication, because it's computationally zoomier.Frame convention
state_estimate->attituderepresents the body to world rotation.The gravity-compensation path is now:
g_world
-> world to body rotation
g_body
accel_measured_body - g_body
= accel_linear_body
accel_linear_body
-> body-to-world rotation
accel_linear_world
accel_linear_world * dt
-> world-frame velocity
Issue Link
github.com//issues/139
child: SunDevilRocketry/Flight-Computer-Firmware#304
Testing
The corresponding quaternion and gravity-compensation tests cover:
Identity world-to-body rotation
Identity body-to-world rotation
Body-to-world-to-body round trip
Positive 90-degree yaw rotation
Stationary identity attitude producing zero linear acceleration after gravity subtraction
Local test result:
Passes: 26
Fails: 0
Result: PASS
Other
Leave any additional notes here
Reviewer Checklist
Standards
Error Handling
Memory
Performance