while tinkering with the main loop and my little accuracy experiment I found a nice way to optimise baro updates for speed and size. Changes towards current dev branch can be viewed here:
https://github.com/sebastianherp/multiw ... roved_baro [source]
https://github.com/sebastianherp/multiw ... roved_baro [diffs]
What changes are in this patch?
- Enhanced taskOrder switch statement in main loop
- Moved the 40 Hz timing from getEstimatedAltitude() to the main loop
- Baro_Update() now combines states, because it is possible to start a new measurement right after an old one was completed instead of waiting for the main loop to call Baro_update() again. It also gets rid of the altitude calculation, and averages the pressure instead (moved from getEstimatedAltitude() into Baro_Common()) which saves 200+ µs when Baro_update() is in the calculation-state.
- getEstimatedAltitude() gets called every 25 ms and calculates the altitude (after 10 seconds to let it settle first) from ground pressure difference (code copied from Ardupilot project). It uses only log() to do that which saves bytes and time (100+ µs) compared to the previous pow() approach
On my copter (ATmega 2560, QuadX, FreeImu 4.3 and SUMPPM) this modification saves 334 bytes and cycle time decreases in those cycles where baro related code is executed. [edit:] And it flies (as posted below) [/edit]
Caveats:
- not tested with a BMP085, but changes included there as well
- don't know how it affects mahowiks BaroPID changes
- ground pressure should probably be also reset(able) when arming the copter/plane
- BaroTemperature is unused, but could be shown somewhere in the GUI or transmitted via other telemetry means to find out how warm/cold it is 200 meters up
Anybody willing to peer review / test this small modification?
Edit (10/10/2012):
Changed the lists to reflect the current state of the patch and updated title (patch is now against r1179)
getEstimatedAltitude() needs to be called in 25 ms steps (40 Hz) or the BaroPID code doesn't work (so I changed it back ... tried 10 Hz). Maybe altitude estimation and BaroPID calculation should be in seperate functions?