Software PID controller

Rob Lewis rob at whidbey.com
Sat Mar 12 17:10:54 EST 2016


One of my main uses for XTension is temperature control of things, like my hacked-together Sous Vide cooker and my beer fermenter. 

The simplest control algorithm is just a dumb thermostat: if the pot is too cold, turn on the heat, and if it’s too warm, turn it off. This works, but since the systems have lag, the temperature will overshoot and undershoot the target value. 

As many of you know, the Proportional-Integral-Differential (or PID) controller can do a better job of stabilizing the temperature. It uses not just the current temperature error, but also its rate of change (derivative) and the accumulated temperature error (integral) to compensate for the lag. 

I’ve been experimenting with implementing one in AppleScript and at the moment it seems to be working very well on the beer keg. It’s set up as a script that runs every 50 seconds and does the PID calculations resulting in a heater “on” time for the next 50-second interval. It’s maintaining the temperature within a ±0.2°F tolerance. 

Basically, it’s a software realization of Figure 4 here: http://www.ni.com/white-paper/3782/en/ 

I’m certainly no expert in these things but as I said, it seems to work. It’s fun to watch XTdb display the temperature fluctuations and the varying-width heat pulses. 

If anyone’s interested in seeing the code, let me know. (Caveat: getting best performance requires “tuning” the coefficients for the application, but I haven’t found that too difficult.) 


More information about the XTensionList mailing list