Closed Loop Control

In the video chat today John Mastrototaro mentioned that the medtronic artificial pancreas prototype is using a PID (proportional-integral-derivative) type control. What does that mean? How good is it? Read on!

The PID algorithm has been used for decades in the process control industry. It is used in all types of industrial processes throughout the world. Some of the pros of PID:

  • Can be tuned (adjusted to act faster or slower) to match a specific need
  • Extremely well understood; everybody uses it, so a lot is known about how it works.
  • Can respond to the the rate at which change is occurring (e.g. could see how fast you're dropping or climbing)

How it works:

  • The controller is given a setpoint (SP, or target value). In this case that would be the target glucose concentration. For example, you might set the SP to 100 mg/dl or 5.5 mmol/l.
  • The controller reads a process variable (PV, or actual value). In this case that would be the glucose measurement from the CGM.
  • The controller continuously changes the output (OP) up or down, depending on whether the measured glucose is above or below the setpoint. In this case the output goes to the pump to adjust the infusion rate.

In simple terms, if your glucose (PV) is above your target (SP) then the controller would increase the rate at which the pump is delivering insulin. How much depends on how high you are.

The tricky part is that the formulas start changing the output before the PV reaches the SP. In other words, it doesn't keep dumping in insulin until you're low and then try to fix it. Instead, it is always trying to achieve a "soft landing" by gradually bringing your glucose closer to your target. So by the time you reach your ideal glucose, the infusion rate is hardly changing at all.

Of course nothing is perfect. Cons of PID:

  • It can be very sensitive to delays in response (dead time). In other words, it has to be tuned carefully because your glucose doesn't respond immediately to changes in infusion rate. The delays are cumulative and caused by lag time in the sensor (around 15 minutes) and the time it takes for the insulin to affect your glucose.
  • Doesn't handle noise very well. With any measurement there is a bit of randomness. You can see this if you take several measurements with your glucose meter all at once. They don't all come out exactly the same. The PID can see these differences as changes in your actual glucose, and try to correct for them by changing your insulin infusion rate.

The basic solution to these issues is to make the control act slower. The downside of slower action is that it will not respond as quickly to real changes such as your glucose going up rapidly from eating sugar. Slower action would translate into a wider range of glucose, i.e. your control wouldn't be as tight.

Hopefully we don't have too many glazed-over eyes out there now! I'll save further details and comparison to other control methods for a different post, if there's interest.


My eyes are not glazed over at all, thanks for that very comprehensive report on the PID algorithm and its' potential advantages and disadvantages when used in an insulin pump. Now if they could miniaturize it and make it implantable I might even consider it. But in the meantime I'm still happy with MDI.

Thanks Eb, for the very accessible explanation! Would love to see more ;)

Unfortunately, while a PID controller works well with a linear system, it can work rather poorly on a non-linear system. And our bodies are non-linear, resulting in potential instabilities and as you note poor convergence properties. It is a good start, but I suspect that it just won't work in the long term.

ps. In addition, to work properly in a control system you need an ability to raise as well as lower blood sugar, hence the efforts to introduce glucagon into the mixture.

Non-linearity may not be a huge problem. Within selected limits, they can be approximated by linear systems. There are also variants of PID like gap control and adaptive gain that can extend its usefulness. Remember that even without these, the controllers have already been used successfully on real patients in small clinical trials.

The ability to raise glucose would provide better performance, but it is feasible to have an AP without this feature. For the most part we manage lows just by eating. There is also a natural upward drift that is typically controlled by a basal rate or long lasting insulin. With closed loop control, technically there would not be a distinction between basal and bolus delivery.

Part 2 - Model Predictive Control

Every solution has drawbacks, so what other option is there if we don't like the characteristics of PID for closed loop control? Well, I'm glad you asked that!

As the name implies, Model Predictive Control (MPC) uses a mathematical model to improve control. The model takes into account the expected response to insulin. The model can also include the expected responses to things that aren't measured, like food and exercise.

Using this model, the controller has a reasonably good idea of what should happen if it increases or decreases the insulin rate. It predicts what the glucose should do when it looks at the CGM value next. That allows it to factor out its own actions from the actual glucose reading it gets. What is left are the changes resulting from "something else." This helps the controller avoid getting confused by its own actions.

The MPC is also more sophisticated than PID because it remembers the history of moves that it has made. This is analogous to, but more sophisticated than, the concept of insulin on board (IOB). Not only does the controller know and use the info about how much insulin is in play, it also knows how much and how fast it should affect the glucose.

Some advantages of MPC:

  • Very good at noise rejection; much less likely to get confused by a couple of inaccurate readings.
  • Better stability; less likely to swing to extremes
  • Good handling of dead time; the model helps it understand that it takes a while for the glucose to come down after more insulin is applied
  • Can survive (at least for a short time) with missing readings


  • Slower; PID can easily make moves every second; MPC usually runs around once per minute. This isn't a real drawback for glucose control since the response is in minutes rather than seconds anyway.
  • Takes more computing power; it has to solve matrix equations, which is more demanding. Also the program is much more complicated than a few formulas, so it would be difficult to write from scratch. The program would probably have to be ported from an existing computer application to a mobile device.


Thanks for taking a somewhat complicated topic and making it understandable. I like reading about some of the more complex facets of using insulin.