Remember this graph from the other day? It’s the target pitch angle that was so swamped with noise it was useless – and therefore any attempt at drift compensation was too.
After some serious code tweaking, here’s today’s results:
So where did all the noise go?
If you remember, the conversion from horizontal speed PID output to absolute angle PID target goes like this:
pa_target = -math.atan(evx_out / eaz)
Both the top and bottom sides of the division were loaded with noise. So it had to be disposed of.
Topside was easy: the horizontal velocity PID output had an element of D-gain, which contributed little but noise. Setting the gain to zero all but removed that.
Underside required several different fixes:
- remove the D-gain from the vertical speed PID much as above
- reduce the dlpf to 10Hz (not sure if this actually mattered)
- average out horizontal and vertical acceleration.
It’s the last of these that had the dominant effect. Because I’ve recently changed to updating the PWM less frequently than the code spins, there are several readings from each accelerometer that can be averaged over the period between PWM updates.
Together, the top and bottom side changes has resulted in a pitch / roll angle targets that are perfectly aligned with horizontal velocity errors: when evx is positive (forward movement), pa_target is positive (nose up angle) to compensate.
That doesn’t mean drift compensation is working quite yet – but it at least now seems that only PID tuning stands between drift and no-drift.
I’m so pleased with this transformation I’ve updated the code on GitHub.