Electronic – arduino – PID algorithm: how to account for fast input value changes after a long delay

algorithmarduinocontrolcontrol systempid controller

I am trying to implement a basic PID algorithm on an Arduino Leonardo to mix hot and cold tap water using servo-controlled valves. The goal is to hold the temperature as close to a setpoint as possible. Especially important is preventing the output temperature from overshooting the setpoint to protect the user from burns. Secondarily important is getting the temperature near the setpoint as quickly as possible.

For small changes in temperature, a standard implementation of the PID algorithm seems to work OK. But I don't know how to account for the long delays that may occur when waiting for hot water to reach the valve, since these delays are much longer than standard delays after changing the valve positions.

Obviously depending on the length of the hot water line and time since last use of hot water, it can take multiple tens of seconds for the hot water to reach the valve, so during this time, the water temperature remains fairly constant at a low temperature and the hot water valve soon opens 100%. The integral component begins to accumulate a large error value.

When hot water finally reaches the valve, the detected temperature rises very rapidly to the max hot water temperature. Due to the large integral error, the hot water valve is held at 100% for a long time after the temperature exceeds the setpoint, due to waiting on the integral value be reduced to normal levels. Thus the result is maximum-temperature water for several (tens) of seconds.

I'm not sure how to account for this possible long delay. In such a case, would it be wise to set an upper (and lower) bound on the integral error value, in order to limit max response time? This seems to defeat the purpose of the integral component, and would also still impose some lag after reaching the setpoint.

Or is there a better way to handle fast input changes after a long delay?

Thanks for any advice!

Best Answer

Your problem is called Integral Windup, it's a common control problem. In a non-linear or otherwise bounded region, the controller can't track the setpoint, and the integral increases to a large value. This causes a large overshoot when the setpoint is finally reached, which is exactly what you have deduced is the problem.

The simplest solution is to limit the Integrator value itself to a sensible maximum. Limiting the integral contribution won't work as well, because the integrator will still be wound up to some large value.

Mathworks has a page with some other solutions to integral windup.

In a PID controller, you generally want as little integral term as possible. In a standard mechanical temperature control valve, only proportional control is used, and they work ok. Keep the integral term as small as you can - the user isn't going to notice a small error in the final temperature. You might find that you get acceptable performance with just PD.

As this is a very special, known case, you might consider having a different mode for the controller. Measure the hot inlet temperature, and while it is below the setpoint, just run hot 100%, cold 20%. When it warms up, switch to the PID, with good initial conditions.