# Node-red-contrib-pid components values

**URL:** <https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688>\
**Category:** General\
**Created:** [7 November 2023 14:50 UTC](https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688 "2023-11-07T14:50:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![avk999](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/avk999/32/84348_2.png) [@avk999](https://discourse.nodered.org/u/avk999)\
**Post date:** [7 November 2023 14:50 UTC](https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688/1 "2023-11-07T14:50:09Z")

</div>

I use node-red-contrib-pid module by colinl and while the node itself works fine the output values of the P,I,D components do not make much sense. When the temperature (PV) is lower than the setpoint the P component is negative, while the output increases (just as it should). Same goes for all 3 components. It looks like the sign is inverted when the components are output in the message properties.

As the author has explained at [[question] signs of components · Issue #25 · colinl/node-red-contrib-pid · GitHub](https://github.com/colinl/node-red-contrib-pid/issues/25) the component values should go down when the power should decrease (which makes sense) but I observe the opposite.

Again, the regulator operates perfectly fine, the question is only about the output component values.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d02ef4f975c3ddc4780c9cf62fc0ed077408b323.png)  
The filled area is the output of the regulator, the lines are the components.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 November 2023 15:51 UTC](https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688/2 "2023-11-07T15:51:49Z")

</div>

Sorry, I misread your original post on the issue you linked to. Lets try again.

Looking at the proportional term, conventionally in PID algorithms this is calculated by determining the error (which is PV - setpoint) and then scaling that by the proportional band or gain. That does indeed give a negative value when the process is low.

As you say, in order to generate the correct sign for the output power it is inverted and offset to give a power value in the range 0:1 by the line in pid.js:  
`power = -1.0/node.prop_band * (proportional + node.integral + node.derivative) + 0.5`

---

<div class="post-metadata">

**Author:** ![avk999](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/avk999/32/84348_2.png) [@avk999](https://discourse.nodered.org/u/avk999)\
**Post date:** [7 November 2023 16:11 UTC](https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688/3 "2023-11-07T16:11:29Z")

</div>

I always assumed error to be `setpoint-PV`, not the reverse (so that one can add PV+error and get a target value, like in statistical modelling).  
if you see error as PV-setpoint it becomes clear why the component values have counter-intuitive sign.  
Thank you for the claiifcation.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 November 2023 16:16 UTC](https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688/4 "2023-11-07T16:16:01Z")

</div>

It doesn't actually matter which way round it is of course, provided a correction is made to get the sign right at the end.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [7 November 2023 16:23 UTC](https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688/5 "2023-11-07T16:23:26Z")

</div>

It looks like I have been doing it all wrong for 50 years. Luckily it doesn't matter provided the final answer is correct.

> **[Proportional–integral–derivative controller](https://en.wikipedia.org/wiki/Proportional%E2%80%93integral%E2%80%93derivative_controller)**
>
> A proportional–integral–derivative controller (PID controller or three-term controller) is a control loop mechanism employing feedback that is widely used in industrial control systems and a variety of other applications requiring continuously modulated control. A PID controller continuously calculates an error value 
>   
>     
>       
> e
> (
> t
> )
>       
>     
> {\\displaystyle e(t)}
>   
> as the difference between a desired setpoint (SP) and a measured process variable (...

---

<div class="post-metadata">

**Author:** ![avk999](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/avk999/32/84348_2.png) [@avk999](https://discourse.nodered.org/u/avk999)\
**Post date:** [7 November 2023 19:02 UTC](https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688/6 "2023-11-07T19:02:58Z")

</div>

anyway your implementation which basically replaces coefficients with timing is crazy cool! I've never seen such PID algos.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 January 2024 19:03 UTC](https://discourse.nodered.org/t/node-red-contrib-pid-components-values/82688/7 "2024-01-06T19:03:23Z")

</div>

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