Capstone: Model, Estimate and Control

A continuous glucose monitor and an insulin pump forming an artificial pancreas

Open the Artificial Pancreas Control Studio app

Advanced Control Exercise 30 of 30 in Uncertainty and Machine Learning · All exercises · Time: 15 minutes

An artificial pancreas measures glucose and doses insulin, and insulin only lowers glucose: the input is one-sided. Meals are the large disturbance. This capstone assembles everything in the course on one plant: a physiological model, an MPC that plans within the pump's limits, and an estimator that must decide whether a rise in glucose is a meal that will fade or an offset that will stay.

Learning Outcomes

  • Assemble a model, an estimator and a constrained controller for one plant, and explain each one's role.
  • Explain a one-sided input as a constraint the controller must plan around, and why announcing a disturbance helps.
  • Compare an MHE with a meal state and a Kalman filter with an offset, by peak glucose and time below 70 mg/dL.

Book Chapter

Control of Biological Systems and Human Performance (Volume 19), Chapter 2, Artificial Pancreas Simulator for Direct Action and One-Sided Insulin Delivery. Read the chapter, open the PDF, or watch the lecture slides.

Theory in Brief

A minimal glucose-insulin model has plasma glucose `G`, remote insulin action `X`, plasma insulin `I`, insulin infusion `u` and meal appearance `D`:

$$\begin{gathered} \frac{dG}{dt} = -p_1\left(G - G_b\right) - X G + D, \\ \frac{dX}{dt} = -p_2 X + p_3 \left(I - I_b\right), \\ \frac{dI}{dt} = -n\left(I - I_b\right) + \frac{u}{V_I} \end{gathered}$$

The MPC plans insulin over its horizon with a band objective, a higher price on low glucose than on high, and the pump's limits:

$$\min_u \sum_k w_k \left(G_k - G_{sp}\right)^2 + R\, \Delta u_k^2 \quad \mathrm{s.t.} \quad 0 \le u_k \le u_{max}$$

The constraint `u \ge 0` means a plan cannot take insulin back: once dosed, it acts for hours. A meal the plan is told about can be met early; one it is not told about must be estimated. A Kalman filter with an offset state books the rise as a lasting bias and keeps dosing. An MHE with a meal state `D` and a bounded, decaying model of it books the rise as a meal that will fade:

$$\min_{x, D} \sum_{k=t-N}^{t} \left\| y_k - \hat G_k \right\|^2 + \sum_k \left\| D_{k+1} - a D_k \right\|^2_{W} \quad \mathrm{s.t.} \quad D_k \ge 0$$

Model: Physics-based physiology with patient parameters, plus a meal disturbance state.
Decision: Insulin infusion every few minutes, planned over hours within the pump's limits and a priced glucose band.
Learning: The estimator learns the unannounced meal online; the patient parameters come from the model.

Exercise

Read 2 min · Predict 1 min · Run 7 min · Explain 3 min · Check your AI 2 min.

Predict. The MPC is told about a meal two hours ahead. Will it dose before the meal? If nobody tells it, will an MHE with a meal state or a Kalman filter with an offset lead to the lower glucose afterward, and which is the dangerous one?

Run the Artificial Pancreas Control Studio app. Use the fastest speed, 10 h/s, and press Run again to pause at the times in each step.

  1. Open 9 · MPC with an announced meal (meal announced). Press Run and pause at 24 h. Read the blood glucose IAE in the Control performance tiles, and the peak and lowest glucose after the meal on the trend.
  2. Set Controller to PID, press Reset, and run to 24 h. Read the same.
  3. Open 10 · Unannounced meal: Kalman or an MHE with a meal state (meal not announced, MHE with a meal state). Run to 24 h and read the same.
  4. Set Estimator to Kalman (Advanced), press Reset, and run to 24 h.

Explain.

  1. Why does the announced-meal MPC dose before the meal, and why is that allowed only because it planned it?
  2. The MHE run peaks higher than the Kalman run, yet it is the safer one. Why?

Generative AI Learning

"Design an artificial pancreas with model predictive control. Insulin can only be added, not removed, and meals are not always announced. How should the estimator treat a sudden rise in glucose?"

Check the answer against your run: A good answer treats insulin as a nonnegative, long-acting input, and estimates a meal as a fading disturbance so the controller does not keep dosing after it. Your step 3 and 4 time below 70 mg/dL is the test. The assistant is your tutor and reviewer; you answer for every claim you turn in.

What to Turn In

A four-row table (MPC announced, PID, MPC with MHE meal, MPC with Kalman) with IAE, peak glucose, lowest glucose and time below 70 mg/dL, your written prediction, and three sentences that answer the two questions.

Told of the meal, the MPC trims and then raises the pump before the meal, so glucose is down to 75.0 mg/dL when the meal arrives, then peaks at 98.6 mg/dL and never goes low; its IAE over 24 h is 50.9 mg/dL·h. The PID sees the meal only in the sensor: glucose peaks at 116.8, falls to 66.2, and spends 0.67 h below 70, with an IAE of 83.7. Dosing early is safe only because the plan knows the meal is coming and accounts for every unit already given; a controller that cannot plan that far would cause a low.

Without the announcement, the MHE with a meal state books the rise as a meal that will fade: glucose peaks at 155.8 but never falls below 75.9, with 0.00 h below 70. The Kalman filter books the same rise as a lasting offset, keeps dosing after the meal is gone, and glucose falls to 64.9, 0.84 h below 70, after a peak of 130.9. Its IAE, 99 against the MHE's 114, rewards the faster correction. On a plant with a one-sided input, a low is the outcome that matters most, and the estimator's model of the disturbance decides it.

Measured with the app build of December 3, 2026 by a scripted replay of the steps above. Numbers that no tile shows come from the replay's record; your readings from the trends will be close. A later app release may move the last digit.

Artificial Pancreas builds this model in GEKKO. Add an unmeasured meal state with a decay, estimate it with `IMODE=5` from glucose alone, and feed the estimate to an `IMODE=6` controller with `u \ge 0`. Compare with the same controller using a constant-bias estimator.

Related

References

  1. Hedengren, J. D. (ed.), Control of Biological Systems and Human Performance, Volume 19 of Interactive Control Engineering, Chapter 2, "Artificial Pancreas Simulator for Direct Action and One-Sided Insulin Delivery", pp. 23–53, Advanced Process Solutions, 2026. PDF (CC BY 4.0).
  2. Bergman, R. N., Ider, Y. Z., Bowden, C. R., Cobelli, C., Quantitative estimation of insulin sensitivity, American Journal of Physiology 236(6), E667–E677, 1979.
  3. Hovorka, R., Canonico, V., Chassin, L. J., et al., Nonlinear model predictive control of glucose concentration in subjects with type 1 diabetes, Physiological Measurement 25(4), 905–920, 2004.

Course Information

TCLab

Project

Applications

Advanced Control Exercises

Exams

Modeling

Machine Learning

Estimation

Control

Reinforcement Learning

Related Courses

Admin