24 hours later.

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.

Target pitch angle

Target pitch angle

After some serious code tweaking, here’s today’s results:

Velocity vs Angle Targets

Velocity vs Angle Targets

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.