CGM-driven artificial pancreas — PID and reinforcement-learning dosing controllers regulating glucose in real time
The modern artificial pancreas is fundamentally a control-systems problem wrapped around human physiology: a noisy, delayed sensor (the CGM) feeds an algorithm that must compute a safe insulin dose to counteract an unpredictable, meal-driven, highly nonlinear disturbance (blood glucose) — with a actuator (subcutaneous insulin) that itself has a multi-hour delay and no way to "undo" an overdose once delivered.
Most industrial control problems have fast, direct actuators and clean sensors. Glucose control has neither: the CGM measures interstitial glucose (a proxy, lagging true blood glucose by 10–15 minutes and carrying ~8–9% random measurement error), while the actuator — subcutaneous rapid-acting insulin — takes 15 minutes just to begin absorbing and 60–90 minutes to reach peak effect, with total action persisting 3–5 hours.
A meal can raise blood glucose by 100+ mg/dL within 30–60 minutes, faster than insulin can respond even with perfect prediction — this is why hybrid closed-loop systems still require a manual pre-meal bolus announcement in most commercial systems (Tandem Control-IQ, Medtronic 780G): the control loop alone cannot react fast enough to fully blunt a meal spike without meal-time forewarning.
The mismatch between meal-glucose speed (minutes) and insulin action speed (hours) is the single hardest unsolved problem in closed-loop insulin delivery — faster insulin analogs (Fiasp, Lyumjev) and dual-hormone systems (adding glucagon) are the two main engineering responses.
PID control is the same algorithm family used in cruise control, thermostats, and industrial process control — and its transparency, tunability, and decades of engineering track record make it the backbone of nearly every FDA-cleared hybrid closed-loop insulin pump on the market today.
The proportional term (Kp·e) delivers extra insulin proportional to how far current glucose sits above target right now — a large, immediate error gets a large, immediate correction. The integral term (Ki·∫e dt) accumulates past error over time, catching persistent small deviations that the proportional term alone would under-correct — e.g., glucose sitting 20 mg/dL above target for hours due to a slightly wrong basal rate. The derivative term (Kd·de/dt) reacts to the rate of change, allowing the controller to preemptively reduce insulin as glucose is already falling fast, even before it reaches target — critical for avoiding a rebound low after a correction.
Insulin dosing PID controllers almost universally implement asymmetric gains: they act much more aggressively increasing insulin above target than decreasing/suspending below it, and most commercial systems bias toward insulin suspension (Kp effectively capped near zero net insulin) rather than negative dosing, since insulin cannot be "taken back" once infused — a fundamental actuator asymmetry that has no analogue in a thermostat.
Where PID control applies the same fixed-gain formula to every glucose trajectory, reinforcement learning approaches instead learn a dosing policy directly from data (real or simulated), adapting to an individual's unique insulin sensitivity, meal timing patterns, and circadian variation in ways a fixed PID gain set cannot easily capture.
An RL dosing agent is trained (typically offline, on the FDA-accepted UVA/Padova type-1 diabetes simulator population, or on de-identified real patient CGM+pump data) to maximize a reward that combines time-in-range with an asymmetric penalty for hypoglycemia — reflecting the clinical reality that a low blood glucose event carries acute danger (seizure, loss of consciousness) that a moderately high reading does not.
Unlike PID, an RL policy can in principle learn patient-specific structure: that this patient tends to under-bolus for breakfast, that overnight sensitivity rises around 3 a.m. (the "dawn phenomenon" in reverse), or that a particular meal pattern predicts a delayed post-prandial rise from high-fat content. In practice, every clinically deployed RL-adjacent system wraps the learned policy in hard safety constraints — bounded maximum dose, mandatory suspension below a glucose floor, and supervisory override — because an unconstrained learned policy exploring novel dosing strategies on a live patient is not an acceptable risk; RL contributes the adaptive "how much" within limits that remain rule-based.
Every RL-based glucose controller in active clinical development runs inside a rule-based safety supervisor that can veto or clip the RL output — the learned policy proposes, but a simple, auditable safety layer always has final authority over insulin delivery.
No dosing algorithm, however sophisticated, can outrun the physical absorption kinetics of insulin injected into subcutaneous fat. Understanding "insulin on board" — the residual glucose-lowering effect of insulin already delivered but not yet fully acted — is what separates a controller that avoids delayed hypoglycemia from one that stacks doses into a dangerous low.
When the pump delivers a correction bolus, that insulin does not act instantaneously and then vanish — it follows a pharmacokinetic action curve that rises over ~60–90 minutes and then decays over several hours. "Insulin on board" (IOB) tracks how much of a previous dose is still pharmacologically active. A controller that ignores IOB and doses again purely off the current glucose reading risks "stacking" — delivering a second full correction on top of a first dose that has not yet finished acting, driving glucose down further than intended once both doses reach peak effect simultaneously.
Every closed-loop algorithm — PID or RL — must therefore subtract estimated IOB from any new dose recommendation. This is precisely why faster-acting insulin analogs (Fiasp, Lyumjev) are such a meaningful engineering lever for closed-loop performance: shrinking the action-curve delay directly shrinks the unavoidable control lag, letting the same algorithm achieve tighter time-in-range with less stacking risk.
All the control theory in the world is ultimately judged against three simple, clinically validated metrics tracked over a 24-hour glucose trace: how much time was spent in the safe target range, how much above it, and — most consequentially — how much below it.
Time-in-Range (TIR, glucose 70–180 mg/dL), Time-Above-Range (TAR, >180 mg/dL) and Time-Below-Range (TBR, <70 mg/dL) are now standardized, consensus-endorsed metrics (used alongside HbA1c) because they capture glycemic variability that a single averaged HbA1c number hides entirely — two patients can share an identical HbA1c while one spends hours in dangerous hypoglycemia and the other does not.
Randomized trials of commercial hybrid closed-loop systems (Control-IQ, 780G, CamAPS FX) consistently show a 10–15 percentage-point absolute increase in TIR compared to sensor-augmented pump therapy without automation, concentrated overnight when patients cannot manually respond to alarms — the single largest real-world benefit of automated insulin delivery is not daytime meal handling (still often manually bolused) but continuous, fatigue-proof overnight correction that no amount of patient vigilance can reliably replicate.
The overnight TIR improvement — not daytime meal control — is what nearly every closed-loop pivotal trial identifies as the dominant source of benefit, because it is the one period where a tireless algorithm has a structural advantage over an sleeping human.