tim-balloon / TIMflight

Flight MCP repo
0 stars 0 forks source link

Overhaul inclinometer code #88

Closed evanmayer closed 5 months ago

evanmayer commented 6 months ago

Summary

Bugfix inclinometer code that would often throw checksum errors, sometimes segfault on init, and report incorrect angle values for certain angles.

Background

Each flight computer has its own independent inclinometer. The devices will have the same internal serial number, so the same code runs on each FC.

Details

Overall control flow of initializing, reading from serial, checking for errors, and reconnecting stays the same. Guts of the algorithm refactored for readability, testability, and correctness. The core algorithm that unpacks data from each message is lifted from the Jewell manual for this device, so it is "known" to be correct. Trust, but verify: in addition, cmocka test code was added for the new core functions, and the tests take canned real inclinometer data as input to check against the functions.

Additional improvements:

I added some comments here on the Pull Request to help you find your way around this substantial review.

Follow-on:

Explore possibility of updating ElSolutionStruct variance to give inclinometers more sway over elevation solution. These are better than what BLAST-TNG flew, and the the bugs ironed out, should be reliable, although somewhat low resolution.