PID Control

Overview

PID control is a very common technique for controlling a system in which you have a desired set-point for the system to be in, and are able to control this with one variable. PID is an acronym for proportional-derivative-integral, and describes the three mathematical processes used to decide on a output to the control system.

You change the dynamics of the PID control loop by varying three parameters, the proportional, integral and derivative constants.

Different Types Of PID Control

Distance control: This type of PID is used when you need control the linear or rotation position of something. The PID loop controls the motor effort to get the object into the set position. When the object is in the correct position, no extra control effort is needed, and so the output is 0.

Velocity control: This is the type of PID control that you would use for something such as controlling the speed of a BLDC motor. This requires modification of the PID equation to work correctly. Instead of the PID loop controlling the velocity itself, it controls the change in velocity. When the motor is running at the correct velocity, no change in the control effort is needed, and so the output is a constant value (see the difference between distance control here?).

The Maths

The standard PID equation is:

$output = K_{p}e(t) + K_{i}\int e(t) \mathrm{d} x + K_{d}\frac{d}{dt}e(t)$

The error is always defined as the setpoint value – acutal value, so the error is positive when the actual value is less than what it needs to be. It is defined by the following equation:

$e = u(t) – y(t)$

where $e$ = error, $u(t)$ = setpoint value, $y(t)$ = actual value

This PID equation is in the continuous time domain. However, most PID control loops are implemented digitally. The discrete equation is written:

$output = K_{p}e_{k} + K_{i}T\sum\limits_{i=0}^k e_{k} + K_{d}\frac{(e_{k} – e_{k-1})}{T}$

where $T$ is the time period between samples

This equation is suitable for implementing in code. There also exists the Z transformation of the equation, but this obscures the physical meaning of the parameters used in the controller.

Tuning Methods

Coming soon…

Integral Windup

Integral windup is a common problem with PID controllers. It is when a sudden change in the set-point or large disturbance on the output (really anything that causes a large error between where you are and where you want to be), causes the integral term to build up (remember that the integral term accumulates errors). Once you have reached where you want to be, the integral term has to “unwind”, and will drive the output past the setpoint until the error-time product is unwound.

Firmwave Modules

If you are looking for PID code for an embedded system, check out my Pid project on GitHub (CP3id). It is written in C++ and designed to be portable enough to run on many embedded systems, as well as Linux.

External Links

A really cool open-source hardware project is the osPID Kit which is sold at RocketScream. It looks really swank in it’s acrylic blue enclosure.

Improving The Beginners PID: Introduction is a great set of articles explaining PID control loops and use Arduino code examples to supplement the explanations.

Practical Process Control: Proven Methods And Best Practices For Automated Process Control has lots of useful information on PID.

Posted: October 1st, 2012 at 4:55 pm
Last Updated on: October 17th, 2013 at 3:59 pm