Fix BMM150 blocking magnetometer read - #50
Conversation
|
The automated GPS test currently fails while compiling |
There was a problem hiding this comment.
Picking up this review myself as I am the SME for legacy IMU. Nick, you're still more than welcome to get eyes on it too.
This looks solid! Consider dropping the rev 1 conddefs, but other than that I'm happy with this!
Agreed that there's no worries about the test issue. That happens on the target branch as well, but will be fixed once FCF changes hit main.
| imu_status = read_mag_regs( MAG_REG_DATAX_L, | ||
| ®Mag[0] , | ||
| sizeof( regMag ) ); | ||
| #if defined(A0002_REV1) |
There was a problem hiding this comment.
We are dropping support for the rev 1 IMU in #28. Let's consider dropping this path for rev 1 mag reads.
| #elif defined(A0002_REV2) | ||
| mag_x_raw = | ||
| (int16_t)(((uint16_t)regMag[1] << MAG_XY_MSB_BITSHIFT) | | ||
| (((uint16_t)regMag[0] & MAG_XY_LSB_BITMASK) >> |
There was a problem hiding this comment.
OOF no wonder our mag reads on the blocking path always used to be missing precision on the lower bits lmaoooo! Good spot!
| ( ( (uint16_t) regMag[4] && MAG_Z_LSB_BITMASK ) >> MAG_Z_LSB_BITSHIFT ); | ||
| #elif defined(A0002_REV2) | ||
| mag_x_raw = | ||
| (int16_t)(((uint16_t)regMag[1] << MAG_XY_MSB_BITSHIFT) | |
There was a problem hiding this comment.
nit: this compound is getting a bit hard to read. Consider using the styling that was here before i.e.
mag_x_raw = (int16_t)( (uint16_t) regMag[1] << MAG_XY_MSB_BITSHIFT ) |
( ( (uint16_t) regMag[0] & MAG_XY_LSB_BITMASK ) >> MAG_XY_LSB_BITSHIFT );
If you're not used to SDR's code styling it might seem trivial or not as readable, but it makes a huge difference to me as a reviewer and to readability throughout our codebase if everything is more uniform. The compound makes it a bit hard to track everything, but the extra spacing and forcing everything to two lines helps tell me how this works:
- The byte order out of the raw registers is little endian
- There is a bitmask applied to the least significant bits of each register
- There is a shift applied to both the MSB and LSB
- We bitwise OR the MSB and LSB, then store them into an int16_t that houses the scaled raw values.
|
Thanks for the review Eli! I removed the Rev 1 path from |
8091bc5
into
integration/state-estims-telemetry


Description
Fixes the blocking BMM150 magnetometer read path so it is consistent with the interrupt-driven read path.
Changes:
&&operations with bitwise&masksIMU_RAWIssue Link
Related to SunDevilRocketry/Flight-Computer-Firmware#300
Testing
Passes existing unit tests
Unit tests modified
Integration test performed
git diff --checkpassedNo existing host-side unit-test target compiles
driver/imu/imu.cHardware validation is still required
Other
This PR fixes the blocking
imu_get_mag_xyz()function, which is not currently called by the flight firmware, but served as a useful first step in familiarizing myself with the magnetometer implementation. Further work for issue #300 will investigate and validate the interrupt-driven magnetometer path used during normal operation and determine how the retrieved magnetometer data can be used for sensor fusion.https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmm150-ds001.pdf
https://getyarn.io/yarn-clip/23a5374e-cb47-431e-82a0-7a63da68f11f/gif
Reviewer Checklist
Standards
Error Handling
Memory
Performance