PID controlled heater

@Colin good idea. So I removed all the node links and hard coded the PID values. also removed the comments to check that I was setting correct values. Nothing changed but I did learn something.

Do you know how integral_default and max_interval effect the PID node? I had set the max interval to .1sec because that it the thermocouple update rate. I changed it to 1 second and it seems to hit the setpoint now but it blinks "integral locked". maybe at .1second max interval it was too fast.

Current Settings:
prop_band = 10
t_integral = 1800
t_derivative = 0
integral_default = 0.1 (need suggestion)
smooth_factor = 0
max_interval = 1sec

Edit: started tuning some more. I am a little under-dampened now but by setting the max_interval to 1sec its working better

I made a linear ramp step function. That increases the setpoint value once each second from 30c-75c over roughly 50 seconds.

[{"id":"74f91b50.a099c4","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"deae283b.abb9f8","type":"ui_chart","z":"74f91b50.a099c4","name":"","group":"cf1b24f4.be83c8","order":0,"width":"12","height":"10","label":"test 2","chartType":"line","legend":"true","xformat":"auto","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"100","removeOlderPoints":"","removeOlderUnit":"1","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#ff0000","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1530,"y":160,"wires":[[]]},{"id":"59ad1117.8c652","type":"inject","z":"74f91b50.a099c4","name":"delete graph","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[]","payloadType":"json","x":410,"y":160,"wires":[["deae283b.abb9f8"]]},{"id":"1a534b3b.860fb5","type":"PID","z":"74f91b50.a099c4","name":"","setpoint":"30","pb":"10","ti":"10","td":"0","integral_default":".1","smooth_factor":"3","max_interval":"1","enable":1,"disabled_op":0,"x":890,"y":420,"wires":[["d5a3f26d.b21c1","adef209.b5b30e"]]},{"id":"ea301f53.b298e","type":"inject","z":"74f91b50.a099c4","name":"enable","repeat":"","crontab":"","once":false,"topic":"enable","payload":"true","payloadType":"bool","x":430,"y":420,"wires":[["1a534b3b.860fb5"]]},{"id":"bdd755b6.4f3f48","type":"inject","z":"74f91b50.a099c4","name":"disable","repeat":"","crontab":"","once":false,"topic":"enable","payload":"false","payloadType":"bool","x":430,"y":460,"wires":[["1a534b3b.860fb5"]]},{"id":"d5a3f26d.b21c1","type":"timeprop","z":"74f91b50.a099c4","name":"","cycleTime":"1","deadTime":"0","triggerPeriod":"0.1","invert":false,"x":1100,"y":420,"wires":[["77186146.50a44"]]},{"id":"4f12449f.32165c","type":"inject","z":"74f91b50.a099c4","name":"Setpoint 75","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"setpoint","payload":"75","payloadType":"num","x":400,"y":240,"wires":[["1a534b3b.860fb5"]]},{"id":"f05004d5.760f18","type":"inject","z":"74f91b50.a099c4","name":"Setpoint 30","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"setpoint","payload":"30","payloadType":"num","x":400,"y":200,"wires":[["1a534b3b.860fb5"]]},{"id":"77186146.50a44","type":"rpi-gpio out","z":"74f91b50.a099c4","name":"","pin":"11","set":"","level":"0","freq":"","out":"out","x":1320,"y":420,"wires":[]},{"id":"56800358.ae70bc","type":"serial in","z":"74f91b50.a099c4","name":"","serial":"bca839cb.ac5688","x":390,"y":100,"wires":[["df523cf6.1dfb7","1a534b3b.860fb5","5a1730fc.f2ba6"]]},{"id":"df523cf6.1dfb7","type":"ui_gauge","z":"74f91b50.a099c4","name":"","group":"cf1b24f4.be83c8","order":2,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":710,"y":60,"wires":[]},{"id":"266f8ee4.fa2592","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Proportional band","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"prop_band","format":"{{value}}","min":0,"max":"100","step":"1","x":450,"y":620,"wires":[["1a534b3b.860fb5"]]},{"id":"933585cc.b0bea8","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Integral time","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"t_integral","format":"{{value}}","min":0,"max":"2000","step":"1","x":450,"y":660,"wires":[["1a534b3b.860fb5"]]},{"id":"be612735.acd788","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Derivative time","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"t_derivative","format":"{{value}}","min":0,"max":"2000","step":"1","x":440,"y":700,"wires":[["1a534b3b.860fb5"]]},{"id":"94387bbf.1a0478","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"prop_band","payload":"12","payloadType":"num","x":170,"y":620,"wires":[["266f8ee4.fa2592"]]},{"id":"ac6d9561.516298","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"t_integral","payload":"10","payloadType":"num","x":160,"y":660,"wires":[["933585cc.b0bea8"]]},{"id":"8dd4d550.4598a8","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"t_derivative","payload":"0","payloadType":"num","x":170,"y":700,"wires":[["be612735.acd788"]]},{"id":"7bc48198.6c43c","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Max sample interval","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"max_interval","format":"{{value}}","min":0,"max":"100","step":".1","x":440,"y":740,"wires":[["1a534b3b.860fb5"]]},{"id":"3bdb46fe.57766a","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"max_interval","payload":"1","payloadType":"num","x":160,"y":740,"wires":[["7bc48198.6c43c"]]},{"id":"5a1730fc.f2ba6","type":"change","z":"74f91b50.a099c4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":100,"wires":[["deae283b.abb9f8"]]},{"id":"adef209.b5b30e","type":"range","z":"74f91b50.a099c4","minin":"0","maxin":"1","minout":"0","maxout":"25","action":"scale","round":false,"property":"payload","name":"","x":1030,"y":280,"wires":[["e61a811a.16bb7"]]},{"id":"2d7a4dfe.6622f2","type":"function","z":"74f91b50.a099c4","name":"","func":"var count= 30;\n\nvar counter=setInterval(timer, 1000); //1000 will  run it every 1 second\n\n    function timer()\n{\n  count=count+1.83;\n  if (count >= (75+1.83))\n  {\n     clearInterval(counter);\n     //counter ended, do something here\n     return;\n  }\n  \n  msg.payload=count.toFixed(1);\n  node.send(msg);\n  global.set(\"Ramp\",msg.payload);\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":300,"wires":[["2a669a19.4c3bc6","be75e17d.24934"]]},{"id":"5b15088.c3f9ef8","type":"ui_button","z":"74f91b50.a099c4","name":"","group":"cf1b24f4.be83c8","order":7,"width":0,"height":0,"passthru":false,"label":"start ramp","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":80,"y":300,"wires":[["2d7a4dfe.6622f2"]]},{"id":"2a669a19.4c3bc6","type":"ui_gauge","z":"74f91b50.a099c4","name":"","group":"cf1b24f4.be83c8","order":2,"width":0,"height":0,"gtype":"gage","title":"Current SetPoint","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":460,"y":360,"wires":[]},{"id":"477ae18e.50741","type":"debug","z":"74f91b50.a099c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":560,"wires":[]},{"id":"e61a811a.16bb7","type":"change","z":"74f91b50.a099c4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"PID","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1190,"y":280,"wires":[["deae283b.abb9f8"]]},{"id":"be75e17d.24934","type":"change","z":"74f91b50.a099c4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"setpoint","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":300,"wires":[["deae283b.abb9f8","1a534b3b.860fb5"]]},{"id":"cf1b24f4.be83c8","type":"ui_group","z":"","name":"uColumn Ramp","tab":"c705970.1805b68","order":1,"disp":true,"width":"12","collapse":false},{"id":"bca839cb.ac5688","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"c705970.1805b68","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Updated the code so the user can enter max temp and ramp time. the image below runs to 150c in 90 second and is somewhat close, I still need to work on tuning. At the end of the ramp it set the set point back to 30c which is just above ambient(25c)

[{"id":"74f91b50.a099c4","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"deae283b.abb9f8","type":"ui_chart","z":"74f91b50.a099c4","name":"","group":"cf1b24f4.be83c8","order":0,"width":"12","height":"10","label":"Heating Graph","chartType":"line","legend":"true","xformat":"auto","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"200","removeOlder":"100","removeOlderPoints":"","removeOlderUnit":"1","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#ff0000","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1780,"y":160,"wires":[[]]},{"id":"59ad1117.8c652","type":"inject","z":"74f91b50.a099c4","name":"delete graph","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[]","payloadType":"json","x":750,"y":160,"wires":[["deae283b.abb9f8"]]},{"id":"1a534b3b.860fb5","type":"PID","z":"74f91b50.a099c4","name":"","setpoint":"30","pb":"10","ti":"10","td":"0","integral_default":".1","smooth_factor":"3","max_interval":"1","enable":1,"disabled_op":0,"x":1110,"y":420,"wires":[["d5a3f26d.b21c1","adef209.b5b30e"]]},{"id":"ea301f53.b298e","type":"inject","z":"74f91b50.a099c4","name":"enable","repeat":"","crontab":"","once":false,"topic":"enable","payload":"true","payloadType":"bool","x":650,"y":420,"wires":[["1a534b3b.860fb5"]]},{"id":"bdd755b6.4f3f48","type":"inject","z":"74f91b50.a099c4","name":"disable","repeat":"","crontab":"","once":false,"topic":"enable","payload":"false","payloadType":"bool","x":650,"y":460,"wires":[["1a534b3b.860fb5"]]},{"id":"d5a3f26d.b21c1","type":"timeprop","z":"74f91b50.a099c4","name":"","cycleTime":"1","deadTime":"0","triggerPeriod":"0.1","invert":false,"x":1320,"y":420,"wires":[["77186146.50a44"]]},{"id":"f05004d5.760f18","type":"inject","z":"74f91b50.a099c4","name":"Setpoint 30","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.1","topic":"setpoint","payload":"30","payloadType":"num","x":750,"y":200,"wires":[["1a534b3b.860fb5"]]},{"id":"77186146.50a44","type":"rpi-gpio out","z":"74f91b50.a099c4","name":"","pin":"11","set":"","level":"0","freq":"","out":"out","x":1540,"y":420,"wires":[]},{"id":"56800358.ae70bc","type":"serial in","z":"74f91b50.a099c4","name":"","serial":"bca839cb.ac5688","x":730,"y":100,"wires":[["df523cf6.1dfb7","1a534b3b.860fb5","5a1730fc.f2ba6"]]},{"id":"df523cf6.1dfb7","type":"ui_gauge","z":"74f91b50.a099c4","name":"","group":"cf1b24f4.be83c8","order":2,"width":0,"height":0,"gtype":"gage","title":"Real Time Temp","label":"units","format":"{{value}}","min":"20","max":"200","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":960,"y":60,"wires":[]},{"id":"266f8ee4.fa2592","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Proportional band","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"prop_band","format":"{{value}}","min":0,"max":"100","step":"1","x":670,"y":620,"wires":[["1a534b3b.860fb5"]]},{"id":"933585cc.b0bea8","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Integral time","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"t_integral","format":"{{value}}","min":0,"max":"2000","step":"1","x":670,"y":660,"wires":[["1a534b3b.860fb5"]]},{"id":"be612735.acd788","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Derivative time","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"t_derivative","format":"{{value}}","min":0,"max":"2000","step":"1","x":660,"y":700,"wires":[["1a534b3b.860fb5"]]},{"id":"94387bbf.1a0478","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"prop_band","payload":"18","payloadType":"num","x":390,"y":620,"wires":[["266f8ee4.fa2592"]]},{"id":"ac6d9561.516298","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"t_integral","payload":"10","payloadType":"num","x":380,"y":660,"wires":[["933585cc.b0bea8"]]},{"id":"8dd4d550.4598a8","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"t_derivative","payload":"0","payloadType":"num","x":390,"y":700,"wires":[["be612735.acd788"]]},{"id":"7bc48198.6c43c","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Max sample interval","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"max_interval","format":"{{value}}","min":0,"max":"100","step":".1","x":660,"y":740,"wires":[["1a534b3b.860fb5"]]},{"id":"3bdb46fe.57766a","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"max_interval","payload":"1","payloadType":"num","x":380,"y":740,"wires":[["7bc48198.6c43c"]]},{"id":"5a1730fc.f2ba6","type":"change","z":"74f91b50.a099c4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1370,"y":100,"wires":[["deae283b.abb9f8"]]},{"id":"adef209.b5b30e","type":"range","z":"74f91b50.a099c4","minin":"0","maxin":"1","minout":"0","maxout":"25","action":"scale","round":false,"property":"payload","name":"","x":1250,"y":280,"wires":[["e61a811a.16bb7"]]},{"id":"2d7a4dfe.6622f2","type":"function","z":"74f91b50.a099c4","name":"","func":"var count= 30;\nvar RampStep=((global.get(\"MaxTemp\")-30)/(global.get(\"RampTime\")));\n\nvar counter=setInterval(timer, 1000); //1000 will  run it every 1 second\n\n    function timer()\n{\n  count=count+RampStep;\n  if (count > (global.get(\"MaxTemp\") + RampStep))\n  {\n     \n     clearInterval(counter);\n     count=30;\n     msg.payload=count.toFixed(1);\n     node.send(msg);\n     return ;\n  }\n  msg.payload=count.toFixed(1);\n  node.send(msg);\n  global.set(\"Ramp\",msg.payload);\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":300,"wires":[["2a669a19.4c3bc6","be75e17d.24934"]]},{"id":"5b15088.c3f9ef8","type":"ui_button","z":"74f91b50.a099c4","name":"","group":"cf1b24f4.be83c8","order":7,"width":0,"height":0,"passthru":false,"label":"start ramp","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":300,"y":300,"wires":[["2d7a4dfe.6622f2"]]},{"id":"2a669a19.4c3bc6","type":"ui_gauge","z":"74f91b50.a099c4","name":"","group":"cf1b24f4.be83c8","order":2,"width":0,"height":0,"gtype":"gage","title":"Current SetPoint","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":680,"y":360,"wires":[]},{"id":"477ae18e.50741","type":"debug","z":"74f91b50.a099c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1150,"y":560,"wires":[]},{"id":"e61a811a.16bb7","type":"change","z":"74f91b50.a099c4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"PID","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1410,"y":280,"wires":[["deae283b.abb9f8"]]},{"id":"be75e17d.24934","type":"change","z":"74f91b50.a099c4","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"setpoint","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":300,"wires":[["deae283b.abb9f8","1a534b3b.860fb5"]]},{"id":"71e82668.55c658","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Enter Max Temp ","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"prop_band","format":"{{value}}","min":0,"max":"200","step":"1","x":320,"y":180,"wires":[["306ad9fe.c3e0b6"]]},{"id":"2852c287.432eae","type":"ui_numeric","z":"74f91b50.a099c4","name":"","label":"Enter Ramp Time","tooltip":"","group":"cf1b24f4.be83c8","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"prop_band","format":"{{value}}","min":0,"max":"200","step":"1","x":320,"y":220,"wires":[["eac6d4ee.04ba98"]]},{"id":"306ad9fe.c3e0b6","type":"function","z":"74f91b50.a099c4","name":"MaxTemp","func":"global.set(\"MaxTemp\",msg.payload);","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":180,"wires":[[]]},{"id":"eac6d4ee.04ba98","type":"function","z":"74f91b50.a099c4","name":"RampTime","func":"global.set(\"RampTime\",msg.payload);","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":220,"wires":[[]]},{"id":"ec12a1af.76784","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"150","payloadType":"num","x":150,"y":180,"wires":[["71e82668.55c658"]]},{"id":"4c0daae4.b83184","type":"inject","z":"74f91b50.a099c4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"90","payloadType":"num","x":150,"y":220,"wires":[["2852c287.432eae"]]},{"id":"cf1b24f4.be83c8","type":"ui_group","z":"","name":"uColumn Ramp","tab":"c705970.1805b68","order":1,"disp":true,"width":"12","collapse":false},{"id":"bca839cb.ac5688","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"c705970.1805b68","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

The max_interval won't have any effect unless you make it too small. It is a protection against the temperature measurements failing. If there is a gap between samples > max interval then it locks the integral, so when you are seeing integral locked flashing that is because it thinks the gaps between the samples is too big. I think it sets the output to the manual setting but not sure. Whatever, you should set it a value larger than you ever expect between samples.
Integral default only has an effect on node-red restart or full deploy, it sets the initial ouput if you happened to switch on right at the setpoint. After that it has no effect.
That graph suggests that maybe the integral should be down at about 15 seconds.
When tuning stick to the step change in setpoint (or power up) as it is much easier to see what effect the tuning has.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.