hj91 / node-red-contrib-easy-pid-controller

This Node-RED node provides a PID (Proportional-Integral-Derivative) controller functionality. It utilizes the simple-pid-controller package to perform the control logic.
GNU General Public License v3.0
1 stars 1 forks source link

Integral windup or `value` is not output. #2

Open hotswapster opened 10 months ago

hotswapster commented 10 months ago

It may be my lack of understanding with this node, and I'm happy to be corrected. But my assumption was the value control signal (0-10v or 4-20mA), on the output of the node, would be used to drive the actuator.

  1. I have observed that value follows the PV only, and has no PID control applied.

    • Expected behaviour: This would be the output of the PID node and have PID calculation applied to the signal.
    • Observed behaviour: This is a scaled valve of the input PV and has no PID applied. Is this just a scale representation of the input PV?
  2. output appears to have the PID applied to it as the response changes with proportional and integral settings. However the integral drives this signal past the outputs limits.

    • Expected behaviour: The output is limited to a range (say 0-100%). I thought this would be value signal and used to control the process.
    • Observed behaviour: The output signal looks like the output from the PID algorithm, and not particularly the output of a PID block used in process control. This signal will suffer from "integral windup" where the output saturates and may not return to a controllable range of 0-100%. Is output the signal to use for controlling the process? If so, why is the output wider than 0-100% and how is integral windup prevented?

This picture shows value follows PV and that PID is not applied to Value. pid3

Happy to provide any more information, or accept any guidance from mis-understandings.

hj91 commented 10 months ago

Greetings. How did you test it? Can you share details of your simulation or real setup?

hotswapster commented 10 months ago

Hi Hj, I am using a simulation because I wanted to see it working before implementing, and it wasn't clear to me whether value or output should be used to drive the process output.

Here is my test setup: PIDnodeflow Process used to test:

  1. Set controller to MAN
  2. Change PID settings in node
  3. Deploy changes
  4. set SV to 27
  5. set PV to 27
  6. Set AUTO.

Proportional Testing

To test the proportional control I did it with kp1, ki0, kd0 Dt 5 seconds. Followed by kp2, ki0, kd0. Teh results are here: PID kp1 ki0 kd0 PIV kp2 ki0 kd0 Here you can see upon a PV change, value proportional does not change betweeh kp1 and kp2 however, the output changes by double (expected behaviour). This says to me that value is the input, not the output. and Output is the to be used to control the process.

Integral Testing

kp1, ki100, kd0 To test the integral I did a similar test, I introduced an error by changing the PV from 27 to 35. value changed byt the same amout as the input. For output, upon a PV change, the proportional reacted immediately, and then repeated at the Dt time later (expected behaviour). This leads me to believe that output1 should be used to control the process. However, it also suffers from integral windup and does not appear to have a "range". It is possible to do a range with a separate node, but that doesn't fix the windup. As you can see from the pic below, the windup can end up making output well over 10000 when it should never exceed 100% (or 100 or full scale of the output).

PID windup

a. What is the purpose of value? and can you provide an example when to use it please? b. Is output intended to be used to drive the process output? c. How is integral windup managed?

hj91 commented 10 months ago

Ok, before proceeding - let me add few points

  1. Do not use inject node to manually test easy-pid-controller. The feedback mechanism logic will not work properly
  2. I use a valve simulator to test this node - it basically uses mqtt to receive SV from this node and in turn processes it to get PV which is then fed back to this node. It uses mqtt broker to get and receive values from multiple locations.
  3. Refer the flow provided in examples/ use it with the simulator
  4. Please check this code - https://github.com/hj91/simple-pid-controller/blob/main/mqtt-pid.js which will prove as start point to write your own simulator using nodejs - modify and enhance it as per your requirement.
hj91 commented 10 months ago

Screenshot from 2023-08-07 22-27-23 This is how the SV vs PV response looks when we test it with simulator

hj91 commented 10 months ago

Remember - the PV in real life application does not directly jump from one value to other - it either gradually increases or decreases as per PID parameters and the saturation that you are seeing is due to the lack of correct response from system - it tries to correct the error but that type of PV is never possible in real scenarios.

hotswapster commented 10 months ago

So I hooked it up in my loop. I have a fermenter which has an exothermic reaction on the inside, as well as the heat from the environment, then this PID loop reads the temperature inside the fermenter and adjusts the glycol cooling water flow.

I used msg.payload.output with a range node to control the loop, not msg.payload.value. Using msg.payload.output I can see the P and I functions working. The example you have provided in examples/easy-pid-controller.json appears to suggest msg.payload.value should be used to control the loop.

Lines 82-98 of easy-pid.js appear to me to just map the input to a range and then set that as value. Therefore value is just the input value to the PID block and not the output. README.md also says:

Value: The mapped control signal according to the sensor type (0-10V or 4-20mA).

I interpret this as the output signal.

So my questions are: a. What is the purpose of value? (Is it to describe the input to the PID block or the output?) b. Is output intended to be used to drive the process output? (Where as the example shows that value should be used).

Remember - the PV in real life application does not directly jump from one value to other - it either gradually increases or decreases as per PID parameters and the saturation that you are seeing is due to the lack of correct response from system - it tries to correct the error but that type of PV is never possible in real scenarios.

I understand this but there can still be occurrences where integral windup can be experienced. For example, in my setup, if my glycol chiller can't provide enough cooling, or there are multiple days in a row over 40degreesC followed by a cold day of 20, it's possible the integral component of this loop won't recover quick enough due to integral windup.

hj91 commented 10 months ago

Hi. Can you share the characteristic data screenshot you obtained from the process?

Log all parameters coming from the node into influxdb and use grafana to visualize it.

hj91 commented 10 months ago

Let's delve into the code to clarify these concerns:

Lines 82-98: if (node.sensor_type === "0-10V") { signal = scaledOutput 10; // Map to [0, 10] value = mapToRange(node.currentValue, node.range_min, node.range_max, 0, 10); // Map current value to [0, 10] } else { signal = 4 + scaledOutput 16; // Map to [4, 20] value = mapToRange(node.currentValue, node.range_min, node.range_max, 4, 20); // Map current value to [4, 20] } From the above:

signal is derived directly from the PID's output (called pidOutput) and is then scaled to either 0-10V or 4-20mA depending on the node.sensor_type. This represents the output from the PID block.

value is a mapping of the current process value (node.currentValue, which is essentially the current temperature of the fermenter in your scenario) into either the 0-10V or 4-20mA scale. This represents the scaled input to the PID block.

Now, addressing your specific questions:

a. What is the purpose of value? value represents the current process variable (e.g., the temperature inside the fermenter) mapped to the appropriate sensor range (0-10V or 4-20mA). It provides a perspective on the current state of the process in the context of the sensor range. While this could be useful for visualization or diagnosis purposes, it's not the "control" signal.

b. Is output intended to be used to drive the process output? (Whereas the example shows that value should be used). Yes, the output (represented as signal in the code) is the scaled control signal derived from the PID's computations. This should drive your actuator, such as the valve controlling the glycol cooling water flow. Given its derivation directly from the PID computation, it would be the appropriate field to use for actuating changes in the process.

In summary:

Use output to control your loop. value can be used for diagnostic or visualization purposes to see the mapped input to the PID block