-
Notifications
You must be signed in to change notification settings - Fork 4
Control system
cflurin edited this page Sep 3, 2018
·
7 revisions
The control system can be used to control a value like the temperature in a case. In this example it will cool a case containing e.g a Raspberry Pi or a 3D-Printer.
It isn't an on/off neither a PID-control, it uses the fuzzy logic
idea with the goal to simplify the setup and the fine-tuning.
The setpoint (target) is defined by the value hot = 28 and cool = 26, the actual setpoint is the average value = 27.
The input is the temperature from a ds1820 sensor and the output controls a fan [0-100].
{
"currentState": "running",
"states": {
"stopped": {
"on": "running"
},
"running": {
"off": "stopped"
}
},
"data": {
"hot": 28,
"cool": 26,
"min": 0,
"max": 100
},
"methods": {
"on": [
"sm.fill = 'green';",
"sm.text = 'on';",
"output = false;"
],
"off": [
"sm.fill = 'grey';",
"sm.text = 'off';",
"output = false;"
],
"setHot": [
"sm.data.hot = msg.payload;",
"sm.fill = 'grey';",
"sm.text = 'hot = '+sm.data.hot;"
],
"setCool": [
"sm.data.cool = msg.payload;",
"sm.fill = 'grey';",
"sm.text = 'cool = '+sm.data.hot;"
],
"default": [
"if(sm.currentState === 'running') {",
" sm.temp = Math.round(msg.payload*10)/10;",
" if(msg.payload > sm.data.hot) {",
" msg.payload = sm.data.max;",
" sm.fill = 'yellow';",
" } else if (msg.payload < sm.data.cool) {",
" msg.payload = sm.data.min;",
" sm.fill = 'blue';",
" } else {",
" sm.inr = sm.data.hot - sm.data.cool;",
" sm.outr = sm.data.max - sm.data.min;",
" sm.rel = msg.payload - sm.data.cool;",
" msg.payload = Math.round(sm.rel * sm.outr / sm.inr);",
" sm.fill = 'green';",
" }",
" sm.text = 'temp '+sm.temp+' [ '+sm.data.cool+'-'+sm.data.hot+' ] pwm '+msg.payload;",
" output = true;",
"} else {",
" sm.fill = 'grey';",
" sm.text = 'off';",
" output = false",
"}"
],
"status": {
"fill": {
"get": "sm.fill"
},
"shape": "dot",
"text": {
"get": "sm.text;"
}
}
}
}
[{"id":"b2dc6ea6.cc2e1","type":"dsm","z":"12f1321f.454d1e","name":"control system","sm_config":"{\n \"currentState\": \"running\",\n \"states\": {\n \"stopped\": {\n \"on\": \"running\"\n },\n \"running\": {\n \"off\": \"stopped\"\n }\n },\n \"data\": {\n \"hot\": 28,\n \"cool\": 26,\n \"min\": 0,\n \"max\": 100\n },\n \"methods\": {\n \"on\": [\n \"sm.fill = 'green';\",\n \"sm.text = 'on';\",\n \"output = false;\"\n ],\n \"off\": [\n \"sm.fill = 'grey';\",\n \"sm.text = 'off';\",\n \"output = false;\"\n ],\n \"setHot\": [\n \"sm.data.hot = msg.payload;\",\n \"sm.fill = 'grey';\",\n \"sm.text = 'hot = '+sm.data.hot;\" \n ],\n \"setCool\": [\n \"sm.data.cool = msg.payload;\",\n \"sm.fill = 'grey';\",\n \"sm.text = 'cool = '+sm.data.hot;\" \n ],\n \"default\": [\n \"if(sm.currentState === 'running') {\",\n \" sm.temp = Math.round(msg.payload*10)/10;\",\n \" if(msg.payload > sm.data.hot) {\",\n \" msg.payload = sm.data.max;\",\n \" sm.fill = 'yellow';\",\n \" } else if (msg.payload < sm.data.cool) {\",\n \" msg.payload = sm.data.min;\",\n \" sm.fill = 'blue';\",\n \" } else {\",\n \" sm.inr = sm.data.hot - sm.data.cool;\",\n \" sm.outr = sm.data.max - sm.data.min;\",\n \" sm.rel = msg.payload - sm.data.cool;\",\n \" msg.payload = Math.round(sm.rel * sm.outr / sm.inr);\",\n \" sm.fill = 'green';\",\n \" }\",\n \" sm.text = 'temp '+sm.temp+' [ '+sm.data.cool+'-'+sm.data.hot+' ] pwm '+msg.payload;\",\n \" output = true;\",\n \"} else {\",\n \" sm.fill = 'grey';\",\n \" sm.text = 'off';\",\n \" output = false\",\n \"}\"\n ],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.fill\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.text;\"\n }\n }\n }\n}","x":370,"y":3400,"wires":[["bb43d63.faf2328","e407fd84.4db5a"]]},{"id":"21b7224a.01224e","type":"rpi-ds18b20","z":"12f1321f.454d1e","topic":"","array":false,"name":"","x":130,"y":3400,"wires":[["7a8b6b3c.f5ca64","b2dc6ea6.cc2e1"]]},{"id":"a1008e50.a595a","type":"inject","z":"12f1321f.454d1e","name":"","topic":"","payload":"temp","payloadType":"str","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":3340,"wires":[["21b7224a.01224e"]]},{"id":"e407fd84.4db5a","type":"rpi-gpio out","z":"12f1321f.454d1e","name":"","pin":"12","set":"","level":"0","freq":"2","out":"pwm","x":580,"y":3400,"wires":[]},{"id":"f9002866.ea77d8","type":"inject","z":"12f1321f.454d1e","name":"","topic":"","payload":"100","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":3500,"wires":[["e407fd84.4db5a"]]},{"id":"efc22b60.c35d68","type":"inject","z":"12f1321f.454d1e","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":3460,"wires":[["e407fd84.4db5a"]]},{"id":"7a8b6b3c.f5ca64","type":"ui_chart","z":"12f1321f.454d1e","name":"","group":"7000e44.637b11c","order":1,"width":0,"height":0,"label":"temp","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"2","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#ff9300","#ff9300","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":330,"y":3340,"wires":[[],[]]},{"id":"bb43d63.faf2328","type":"ui_chart","z":"12f1321f.454d1e","name":"","group":"7000e44.637b11c","order":2,"width":0,"height":0,"label":"pwm","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"2","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#929292","#1f77b4","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":570,"y":3340,"wires":[[],[]]},{"id":"d14ee8df.1b1158","type":"inject","z":"12f1321f.454d1e","name":"on","topic":"on","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":3460,"wires":[["b2dc6ea6.cc2e1"]]},{"id":"8db0fd09.983cd","type":"inject","z":"12f1321f.454d1e","name":"off","topic":"off","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":3500,"wires":[["b2dc6ea6.cc2e1"]]},{"id":"fb747522.3a6e08","type":"inject","z":"12f1321f.454d1e","name":"","topic":"setHot","payload":"28","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":3540,"wires":[["b2dc6ea6.cc2e1"]]},{"id":"c13d1e4a.90dd3","type":"inject","z":"12f1321f.454d1e","name":"","topic":"setCool","payload":"24","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":3580,"wires":[["b2dc6ea6.cc2e1"]]},{"id":"7000e44.637b11c","type":"ui_group","z":"","name":"Charts","tab":"9100a436.63c6f8","order":1,"disp":true,"width":"6","collapse":false},{"id":"9100a436.63c6f8","type":"ui_tab","z":"","name":"Control System","icon":"dashboard","order":2}]