# Model Free Control

Sophisticated control laws almost always involve some model of the dynamics of the system. But there are many systems that are tame enough to be controlled without any model.

## Bang-Bang

Probably the simplest form of closed loop control, bang-bang control alternates between two extreme outputs to try to keep some measured value in a desired range. An example is a space heater that’s either on or off, and switches itself between these states to maintain a desired temperature in your room. Many full scale HVAC systems actually work this way too.

Bang bang control works quite well when the system is sufficiently damped. In particular, it’s a good choice when your controller can work on timescales much faster than those of the system evolution, and all the high frequency noise it introduces quickly decays. This is often the case for temperature control, since a lot of energy can be required to heat materials, and heat will often dissipate slowly into the environment (relative to the speed at which a heater can turn on and off).

## PID

The proportional-integral-derivative controller is the workhorse of servo motor control. It consists of three components: a proportional term, an integral term, and a derivative term. You can use these independently, and in fact for simple scenarios it’s not uncommon to see just proportional control, or proportional-derivative control, instead of full PID control.

Let’s assume that we have some measurement $$y$$. It could be the angle of a motor shaft, for instance. Let’s also assume we want $$y$$ to follow a trajectory $$\hat{y}(t)$$. We don’t necessarily need to know this in advance; it could be determined in real time by a knob that you turn, for example.

### Proportional Control

A proportional controller operates on a simple principle: we should push the system toward $$\hat{y}(t)$$ with an intensity proportional to the error $$y - \hat{y}(t)$$. For a servo motor, this would mean that we apply a torque proportional to the error. Mathematically we describe this by choosing a constant of proportionality $$k$$, and setting our torque to be $$-k (y - \hat{y}(t))$$.

### Proportional-Derivative Control

Proportional control has one big problem: oscillation. It makes sense to push the system toward where we want it, but if we don’t start pushing in the other direction until we’re already too far, we overshoot and start oscillating. Proportional-derivative control helps solve this by adding a term proportional to the rate of change of the error. So overall our force (or torque) would be

$-k_p (y - \hat{y}(t)) - k_d (\dot{y} - \dot{\hat{y}}(t))$

(I’m putting minus signs in front of the constants since then they’ll usually be positive. But that’s an arbitrary convention.) When the two constants $$k_p$$ and $$k_p$$ are tuned appropriately, PD control can fix errors without overshooting and introducing oscillations.

### Proportional-Integral-Derivative Control

Sometimes, though, small errors can persist for too long. This can result from nonlinearities in the system. The final term integrates the error cumulatively, and applies a final force proportional to this integral. So the longer the error has the same sign, the harder the controller will try to push it back. If the PD terms keep the error effectively zero all the time, the integral will remain around zero and the I term won’t be doing much. But when you need it, it can be essential.

$-k_p (y - \hat{y}(t)) - k_d (\dot{y} - \dot{\hat{y}}(t)) - k_i \int_0^t (y(t) - \hat{y}(t)) dt$

Often the integral is implemented in a “leaky” manner, meaning it decays over time. This prevents it from growing without bound. This naturally happened in analog systems using op-amps to do the integration, and is sometimes a useful feature to emulate in digital control systems.

### Parameter Tuning

An important part of using a PID loop is tuning the parameters. Sometimes you can find good parameters just by experimenting, but there are also more systematic methods. The most common of these is the Ziegler-Nichols method. It involves first finding the smallest proportional term needed to produce stable oscillations, while the derivative and integral terms are zero. Then you use a table to set the three constants based on the value you found, and the period of the oscillations it generated.