colinl / node-red-contrib-pid

A node-red PID loop controller node intended for the control of real world processes
Apache License 2.0
26 stars 18 forks source link

node-red-contrib-pid

A Node-RED node which operates as a PID loop controller node intended for the control of real world processes.

Install

Run the following command in the root directory of your Node-RED install

npm install node-red-contrib-pid

Usage

Pass the node a process value in msg.payload at regular intervals and configure (or pass in via a message) a setpoint and tuning parameters and the algorithm will generate a required power output between 0 and 1 in msg.payload using a Proportional+Integral+Derivative algorithm.

Any message received with a msg.topic other than those defined below is assumed to contain the current process value in msg.payload and the control algorithm will be run, passing on the required power in msg.payload.

The properties below can also be set using msg.---. For example, to change the setpoint you can set the message attribute msg.setpoint to the required value. Using this method, it is possible to set multiple PID properties using the same message. When using this method to set the properties msg.payload should contain the process value.

Any other message properties will be passed through unchanged.

Example and Tuning Guide

A sample flow demonstrating usage is available at http://flows.nodered.org/flow/42f125b56a00dd5d1433c2f8023263e9

A tuning guide that walks through a simple tuning procedure using the above flow is available at http://blog.clanlaw.org.uk/pid-loop-tuning.html

Configuration

Status

The status text will normally be empty. In unusual conditions it will show the following values.

Persistence

In order to reduce the impact of restarts or redeploys, you can save the integral value in a persistent storage location and feed it back in to the node as it starts. The integral value is available in msg.integral in the output messages. In order to feed it back in set the integral_default value to 0.5 -(cached_integral/prop_band) before the first process value is passed in.

Usage with a cooling process

If the process is a cooling process so that when power is applied to the process the process value decreases rather than increases this can be dealt with very easily by passing the output from the node to a Range node configured to convert the range 0:1 to 1:0.

Alternatively if a node-red-contrib-timeprop node is used to generate a time proportioned signal then it is merely necessary to flip the state of the Invert checkbox to achieve the same result.

Usage with a heat/cool process

If the process has both heating and cooling devices then it is necessary to split the output of node-red-contrib-pid to provide a heat output and a cool output. There is a sample flow that demonstrates this at https://flows.nodered.org/flow/4271d6617c89544ad318e7ab17211ba0 This allows for independent adjustment of heat/cool gain and also for heat/cool overlap if required.