colinl / node-red-contrib-pid

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

Persisting state on NodeRed deploy/restart #15

Closed henrikssn closed 4 years ago

henrikssn commented 4 years ago

Currently, the component resets the integral part when nodered deploys new flow or restarts. This is a problem when the integral part is very long (in my case 24 hours for a heating system).

Would it be possible to add an option to persist the integral state under these circumstances?

colinl commented 4 years ago

I am away from my desk at the moment, but if my memory is correct the setting initial_integral is used to initialise that. That can be set by using msg.integral_default (check the help text to make sure my memory is correct). If you know the approximate power required to control at the setpoint then you can set that in the node's config. If that is variable then if you remember the output power in persistent memory and feed that back in on startup as msg.integral_default (before or with the first process value) then it will use that value. That assumes that the process is in control close to the setpoint when you stop node red of course.

henrikssn commented 4 years ago

Thanks - I managed to get that working.

It wasn't trivial through, mostly because I had to build a small state machine that prevents other messages to reach the PID node before it is initialized (otherwise it would emit a "wrong" integral value that would mess with the process / persistence layer).

colinl commented 4 years ago

Would an inject node set to fire once on startup, feeding the context variable in, have done the job? I would have thought that that would be bound to get in before any sensor had got round to feeding in data.