PID implementation finished

My current plan is to use four PID controllers to control the height and three rotation speeds of my quadrocopter. If you don’t know PID controllers – Wikipedia has a nice description.

Today I found some time to finish my PID controller implementation – but wait! Why an own implementation? First, the code is very, very simple. Second, there is not the one PID controller, but many very different ones and I just did not find a Python implementation that suits my needs (like resetting the target state frequently). The author of the Arduino PID library, Brett Beauregard, describes common pitfalls in his blog posts in http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/. So I use his C implementation and refinement ideas as a basis for my own PID code in Python. The points that I picked from his improvement list are:

  • Derivative Kick: When the target state (=setpoint) is changed, the derivative of error seems to change, too, because the last error was calculated with respect to the last target state. This can be omitted by remembering the last state instead of the last error, and calculating the difference between current and last error only with respect to the current setpoint: \frac{\delta\text{error}}{\delta{t}} =\frac{(\text{setpoint} - \text{currentState})-(\text{setpoint} - \text{lastState})}{\delta{t}} = \frac{\text{lastState} - \text{currentState} }{\delta{t}}.
    With this redefinition of the derivative, the output remains much more stable in the case of a setpoint change.
  • Reset window mitigation: A PID does not assume much about the system it tries to control. By giving it at least some information about the value domain (minimum and maximum), some errors can be omitted.

If I find a need to refine it further, I can do so, it’s my code! Now the plan is:

  • develop a very basic high-level planning module (just fly up 1m, stay there 5s, go down)
  • test the control loop
  • think about failsafe mechanisms
  • finish the hardware build as described in my previous blog entry
  • tune the PID settings and state change planning parameters
  • let it fly!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s