soloam / ha-pid-controller

PID Controller to Home Assistant
MIT License
97 stars 12 forks source link

Document units #29

Open lukepighetti opened 1 year ago

lukepighetti commented 1 year ago

It would be very helpful if we could document the units of P/I/D and also what the defaults are (P of 0 appears to be ∞, not 0 for example)

https://www.youtube.com/watch?v=IB1Ir4oCP5k

soloam commented 1 year ago

In PID there are no defaults! The values are the bases of the PID system, and it's value is the part that they take on the system.

I'm working on a auto runner, that should be OK for determination of the bases of the values. It's still a work in progress.

hannut commented 1 year ago

Are the i and d seconds as in the example or measurement points?

apazureck commented 1 year ago

Hi,

I think @hannut has a legitimate question here, I was asking myself. As I want to control my central heating, the P and Ds are more in the range of an hour or two. So I tried to set them as seconds here and did not connect the output to my target flow temperature (I hope that's the correct english word for the German "Vorlauftemperatur"). So the controller does not actually set the value. Then this happened:

grafik

Those are my settings:

platform: pid_controller
name: ETA PID Vorlauf Controller

set_point: "{{state_attr('climate.wohnzimmer_master', 'temperature') | float}}"
entity_id: sensor.ts_wohnzimmer_temperature
precision: 1
sample_time: 60
maximum: 70
unit_of_measurement: °C
p: 2
i: 10800 // Seconds
d: 2700 // Seconds

So I will now convert them to multiples of the ´sample_time´ value and see what happens.

soloam commented 1 year ago

The P, I and D, are fractions of the output value! They are the parts that are incremented or decreased when the value is processed! P is incremented based on the difference between the input value and the reference value, I and D are related with the delta of the error. All 3 summed give the output!

apazureck commented 1 year ago

Hi, thanks for the fast response. My knowledge is very limited on that regard, as it is about ten years I had cybernetics.

So I took your manual readme and tried to reproduce everything. This is what I understood:

  1. Get the values from the step response of the system (so the value from the sensor): grafik

So I figured the fist chart is the head (25 °C) So in the case the target value was 25, the overshoot (difference between peak (30) and target value) 5.

Then I took the time from the peak until the system goes back down to the target value (I called it $t_0$).

Calculate P:

$P = 2 x Overshoot$

Next to i:

From the documentation:

To set the i value we will double the time of the overshoot of the first phase, in our example 22 (11*2)

So to me: $i = 2 t_0 = 2 11 = 22$

Then to d:

... add some Derivate, to calculate this we can set half the overshoot time measured in phase 1, in our case 5 (11/2)

$d = t_0 / 2 = 11 / 2 = 5.5 \approx 5$

So the x units in the chart are seconds. So when reading my chart I calculate from hours to seconds.

Is that correct?

lukepighetti commented 1 year ago

I get that the p, i, and d coefficients are not unitless because they act on a specific set of units, for example

p (process_output_units / process_input_units) * error (process_input_units) + i (process_output_units / (process_input_units * time_units) * error_integral (process_input_units * time_units) + d (process_output_units / (process_input_units / time_units)) * error_derivative (process_input_units/time_units)

To use a temperate set point and a duty cycle PWM output example it would substitute to be

p (% / f) * error (f) + I (% / f-sec) * error_integral (f-sec) + d (% / f/sec) * error_derivative (f/sec)

Since these coefficients are unit mirrors of each error component they are often left off because they can be deduced from the following form

p(f) * i(f-sec) * d(f/sec) = %

Another way to ask the question is: is this acting in time domain or sample domain. What is the sample window for I, what is the sample window for D, and what is the acting window for both?

apazureck commented 1 year ago

Short answer from the sources:

it is in the time domain using:

https://www.geeksforgeeks.org/python-time-monotonic-method/

So basically in seconds with a millisecond part, like 15.23 s