Hi!
I'm facing a problem with node-red-contrib-pid and hope someone could help.
Trying to set prop_band, t_integral and t_derivative dynamically with sliders, but it always return NaN.
Already tried to use function using parseFloat(), parseInt() and Number(), but nothing seems to work.
Tried to change topics respectively and nothing. Changing setpoint this way works flawlessly, like github's instructions. (https://github.com/colinl/node-red-contrib-pid)
Am I missing something?
Here goes my flow:
[
{
"id": "3f34ddb2.94b5d2",
"type": "PID",
"z": "e333e368.cd6728",
"name": "",
"setpoint": "{{msg.setpoint}}",
"pb": "20",
"ti": "18",
"td": "5",
"integral_default": "0",
"smooth_factor": "0",
"max_interval": 600,
"enable": "1",
"disabled_op": "0",
"x": 870,
"y": 520,
"wires": [
[
"65d53a91.d558d4",
"d02b8ccf.486458"
]
]
},
{
"id": "9e63b7e.becbd48",
"type": "change",
"z": "e333e368.cd6728",
"name": "",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "op",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1240,
"y": 740,
"wires": [
[
"44cba9ee.7d461"
]
]
},
{
"id": "b3f10dab.14a9a8",
"type": "change",
"z": "e333e368.cd6728",
"name": "",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "pv",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1340,
"y": 280,
"wires": [
[
"3fd987a3.1ebde",
"d899a640.cbaaf"
]
]
},
{
"id": "65d53a91.d558d4",
"type": "range",
"z": "e333e368.cd6728",
"minin": "0",
"maxin": "1",
"minout": "0",
"maxout": "100",
"action": "clamp",
"round": false,
"property": "payload",
"name": "Scale power",
"x": 1065.5,
"y": 740,
"wires": [
[
"9e63b7e.becbd48"
]
]
},
{
"id": "ed31425b.8d2ae",
"type": "inject",
"z": "e333e368.cd6728",
"name": "Clear chart on deploy",
"topic": "",
"payload": "{\"data\":[]}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": true,
"x": 1080,
"y": 520,
"wires": [
[
"10c04cdd.5e9aa3"
]
]
},
{
"id": "10c04cdd.5e9aa3",
"type": "change",
"z": "e333e368.cd6728",
"name": "",
"rules": [
{
"t": "move",
"p": "payload.data",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1330,
"y": 520,
"wires": [
[
"3fd987a3.1ebde",
"410a9153.40665",
"d899a640.cbaaf",
"f73ad641.28df9"
]
]
},
{
"id": "b2b4bc76.24d538",
"type": "mqtt in",
"z": "e333e368.cd6728",
"name": "",
"topic": "FW_32778_Raspi",
"qos": "0",
"datatype": "utf8",
"broker": "a033e667.fd62",
"x": 600,
"y": 280,
"wires": [
[
"b3f10dab.14a9a8",
"3f34ddb2.94b5d2"
]
]
},
{
"id": "410a9153.40665",
"type": "ui_chart",
"z": "e333e368.cd6728",
"name": "",
"group": "c85e2ebf.4c9d3",
"order": 0,
"width": "6",
"height": "6",
"label": "PWM",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "0",
"ymax": "100",
"removeOlder": "3",
"removeOlderPoints": "",
"removeOlderUnit": "60",
"cutout": 0,
"useOneColor": false,
"colors": [
"#1f77b4",
"#cf0005",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"useOldStyle": false,
"outputs": 1,
"x": 1690,
"y": 740,
"wires": [
[]
]
},
{
"id": "d899a640.cbaaf",
"type": "ui_chart",
"z": "e333e368.cd6728",
"name": "",
"group": "61a0933f.100cc4",
"order": 1,
"width": "6",
"height": "6",
"label": "Temperatura",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "0",
"ymax": "100",
"removeOlder": "3",
"removeOlderPoints": "",
"removeOlderUnit": "60",
"cutout": 0,
"useOneColor": false,
"colors": [
"#1f77b4",
"#cf0005",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"useOldStyle": false,
"outputs": 1,
"x": 1610,
"y": 400,
"wires": [
[]
]
},
{
"id": "3fd987a3.1ebde",
"type": "ui_gauge",
"z": "e333e368.cd6728",
"name": "",
"group": "61a0933f.100cc4",
"order": 1,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "Temperatura",
"label": "ºC",
"format": "{{value}}",
"min": 0,
"max": "100",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 1890,
"y": 400,
"wires": []
},
{
"id": "f8cbb9ef.053458",
"type": "rpi-gpio out",
"z": "e333e368.cd6728",
"name": "",
"pin": "40",
"set": "",
"level": "0",
"freq": "{{msg.payload}}",
"out": "pwm",
"x": 1700,
"y": 800,
"wires": []
},
{
"id": "f73ad641.28df9",
"type": "ui_gauge",
"z": "e333e368.cd6728",
"name": "",
"group": "c85e2ebf.4c9d3",
"order": 1,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "Resistência",
"label": "%",
"format": "{{value}}",
"min": 0,
"max": "100",
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 1710,
"y": 680,
"wires": []
},
{
"id": "44cba9ee.7d461",
"type": "function",
"z": "e333e368.cd6728",
"name": "",
"func": "var valor=msg.payload;\nvar potencia=valor.toFixed(2);\nmsg.payload=potencia;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1420,
"y": 740,
"wires": [
[
"f73ad641.28df9",
"410a9153.40665",
"f8cbb9ef.053458"
]
]
},
{
"id": "ae4c27f7.ef9968",
"type": "ui_slider",
"z": "e333e368.cd6728",
"name": "temperatura",
"label": "Temp. alvo",
"tooltip": "",
"group": "9d458ea9.7be468",
"order": 1,
"width": "4",
"height": "1",
"passthru": true,
"outs": "end",
"topic": "setpoint",
"min": 0,
"max": "100",
"step": 1,
"x": 170,
"y": 680,
"wires": [
[
"b2d06217.1bb6a8",
"2d50b265.062dc6",
"3f34ddb2.94b5d2",
"2b995adf.2b3cc6",
"c2b2fa1e.edc8c8"
]
]
},
{
"id": "b2d06217.1bb6a8",
"type": "ui_text",
"z": "e333e368.cd6728",
"group": "9d458ea9.7be468",
"order": 5,
"width": "2",
"height": "1",
"name": "",
"label": "",
"format": "{{msg.payload}}ºC",
"layout": "row-spread",
"x": 380,
"y": 680,
"wires": []
},
{
"id": "2d50b265.062dc6",
"type": "change",
"z": "e333e368.cd6728",
"name": "",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "setpoint",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 400,
"y": 560,
"wires": [
[]
]
},
{
"id": "4daa4ae8.640eb4",
"type": "change",
"z": "e333e368.cd6728",
"name": "",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "t_derivative",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 1080,
"wires": [
[
"3f34ddb2.94b5d2",
"2b995adf.2b3cc6",
"c2b2fa1e.edc8c8"
]
]
},
{
"id": "91d060cd.f01cc",
"type": "ui_slider",
"z": "e333e368.cd6728",
"name": "ki",
"label": "Ki",
"tooltip": "",
"group": "9d458ea9.7be468",
"order": 3,
"width": "0",
"height": "0",
"passthru": true,
"outs": "end",
"topic": "",
"min": 0,
"max": "100",
"step": "1",
"x": 150,
"y": 960,
"wires": [
[
"6feb38f2.73ed28"
]
]
},
{
"id": "14bf9a99.61b215",
"type": "ui_slider",
"z": "e333e368.cd6728",
"name": "kp",
"label": "Kp",
"tooltip": "",
"group": "9d458ea9.7be468",
"order": 2,
"width": "0",
"height": "0",
"passthru": true,
"outs": "end",
"topic": "prop_band",
"min": 0,
"max": "100",
"step": "1",
"x": 150,
"y": 880,
"wires": [
[
"3f34ddb2.94b5d2",
"2b995adf.2b3cc6",
"c2b2fa1e.edc8c8"
]
]
},
{
"id": "1a23d6ff.5a9349",
"type": "ui_slider",
"z": "e333e368.cd6728",
"name": "kd",
"label": "Kd",
"tooltip": "",
"group": "9d458ea9.7be468",
"order": 4,
"width": "0",
"height": "0",
"passthru": true,
"outs": "end",
"topic": "t_derivative",
"min": 0,
"max": "100",
"step": "1",
"x": 150,
"y": 1080,
"wires": [
[
"4daa4ae8.640eb4"
]
]
},
{
"id": "d02b8ccf.486458",
"type": "debug",
"z": "e333e368.cd6728",
"name": "Always NaN! WTF?",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 1100,
"y": 620,
"wires": []
},
{
"id": "6feb38f2.73ed28",
"type": "function",
"z": "e333e368.cd6728",
"name": "",
"func": "var temperaturaLida=global.get(\"temperaturaLida\")\nvar valor=parseFloat(msg.payload);\n\nmsg.topic=\"t_integral\";\nmsg.payload=parseInt(temperaturaLida);\nmsg.t_integral=valor;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 310,
"y": 960,
"wires": [
[
"3f34ddb2.94b5d2",
"2b995adf.2b3cc6",
"c2b2fa1e.edc8c8"
]
]
},
{
"id": "2b995adf.2b3cc6",
"type": "PID",
"z": "e333e368.cd6728",
"name": "Trying1",
"setpoint": "{{msg.setpoint}}",
"pb": "{{msg.prop_band}}",
"ti": "{{msg.t_integral}}",
"td": "{{msg.t_derivative}}",
"integral_default": "0",
"smooth_factor": "0",
"max_interval": 600,
"enable": "1",
"disabled_op": "0",
"x": 860,
"y": 840,
"wires": [
[
"f2440e5f.c854c8"
]
]
},
{
"id": "c2b2fa1e.edc8c8",
"type": "PID",
"z": "e333e368.cd6728",
"name": "Trying2",
"setpoint": "{{msg.setpoint}}",
"pb": "{{msg.payload}}",
"ti": "{{msg.payload}}",
"td": "{{msg.payload}}",
"integral_default": "0",
"smooth_factor": "0",
"max_interval": 600,
"enable": "1",
"disabled_op": "0",
"x": 860,
"y": 940,
"wires": [
[
"d04c1a8d.13b808"
]
]
},
{
"id": "f2440e5f.c854c8",
"type": "debug",
"z": "e333e368.cd6728",
"name": "Still NaN!",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 1030,
"y": 840,
"wires": []
},
{
"id": "d04c1a8d.13b808",
"type": "debug",
"z": "e333e368.cd6728",
"name": "Still NaN 2!",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 1040,
"y": 940,
"wires": []
},
{
"id": "a2d1f55d.778e",
"type": "change",
"z": "e333e368.cd6728",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "temperaturaLida",
"tot": "global"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 920,
"y": 1080,
"wires": [
[]
]
},
{
"id": "bc19fd08.656a",
"type": "mqtt in",
"z": "e333e368.cd6728",
"name": "",
"topic": "FW_32778_Raspi",
"qos": "0",
"datatype": "utf8",
"broker": "a033e667.fd62",
"x": 700,
"y": 1080,
"wires": [
[
"a2d1f55d.778e"
]
]
},
{
"id": "a033e667.fd62",
"type": "mqtt-broker",
"z": "",
"name": "Raspberry pi",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "c85e2ebf.4c9d3",
"type": "ui_group",
"z": "",
"name": "Resistência (PWM)",
"tab": "403987b2.90d07",
"order": 2,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "61a0933f.100cc4",
"type": "ui_group",
"z": "",
"name": "Temperatura",
"tab": "403987b2.90d07",
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "9d458ea9.7be468",
"type": "ui_group",
"z": "",
"name": "PID / Temp. alvo",
"tab": "403987b2.90d07",
"order": 3,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "403987b2.90d07",
"type": "ui_tab",
"z": "",
"name": "PID",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]