0

I'm trying to implement a PID controller following http://en.wikipedia.org/wiki/PID_controller

The mechanism I try to control works as follows: 1. I have an input variable which I can control. Typical values would be 0.5...10. 2. I have an output value which I measure daily. My goal for the output is roughly at the same range.

The two variables have strong correlation - when the process parameter goes up, the output generally goes up, but there's quite a bit of noise.

I'm following the implementation here: http://code.activestate.com/recipes/577231-discrete-pid-controller/

Now the PID seems like it is correlated with the error term, not the measured level of output. So my guess is that I am not supposed to use it as-is for the process variable, but rather as some correction to the current value? How is that supposed to work exactly?

For example, if we take Kp=1, Ki=Kd=0, The process (input) variable is 4, the current output level is 3 and my target is a value of 2, I get the following:

error = 2-3 = -1 PID = -1

Then I should set the process variable to -1? or 4-1=3?

Jonas
  • 121,568
  • 97
  • 310
  • 388
nickb
  • 882
  • 3
  • 8
  • 22
  • The diagram at the top of the [Wikipedia page](http://en.wikipedia.org/wiki/PID_controller) pretty much spells it all out - you calculate the new input variable using the combined P+I+D terms derived from the error term. – Paul R Feb 02 '14 at 21:10
  • That would mean setting the process variable to -1 in the above example, but this is counter-intuitive, because it is proportional to the error, not the output - and I know the input variable is strongly correlated with the output, so I would expect the solution to eventually be around the target output value (2). I guess I'm looking for some formulation of PID variables to incorporate this relation between input ant output somehow. – nickb Feb 02 '14 at 21:29
  • You're assuming that a value of 1 for Kp would be correct for your process, but it almost certainly isn't. Also without an I or D term you may need to add a bias value, depending on the nature of your system. – Paul R Feb 02 '14 at 21:45
  • Your nomenclature is a bit confusing -- The 'process' variable is normally the output of the system you are trying to control by manipulating an input to the controlled system. The input to the PID controller algorithm is the errors between the process outputs and the process target, while the output of the PID controller is the setting for the physical process input. – Dave X May 15 '15 at 16:34

1 Answers1

0

You need to think in terms of the PID controller correcting a manipulated variable (MV) for errors, and that you need to use an I term to get to an on-target steady-state result. The I term is how the PID retains and applies memory of the prior behavior of the system.

If you are thinking in terms of the output of the controller being changes in the MV, it is more of a 'velocity form' PID, and the memory of prior errors and behavior is integrated and accumulated in the prior MV setting.

From your example, it seems like a manipulated value of -1 is not feasible and that you would like the controller to suggest a value like 3 to get a process output (PV) of 2. For a PID controller to make use of "The process (input) variable is 4,..." (MV in my terms) Ki must be non-zero, and if the system was at steady-state, whatever was accumulated in the integral (sum_e=sum(e)) would precisely equal 4/Ki, so:

Kp= Ki = 1 ; Kd =0 
error = SV - PV = 2 - 3 = -1
sum_e = sum_e + error = 4/Ki -1


MV = PID =  -1(Kp) + (4/Ki -1)Ki  = -1Kp + 4 - 1*Ki = -1 +4 -1 = 2  

If you used a slower Ki than 1, it would smooth out the noise more and not adjust the MV so quickly:

Ki = 0.1 ; 
MV = PID =  -1(Kp) + (4/Ki -1)Ki  = -1Kp + 4 - 1*Ki = -1 +4 -0.1 = 2.9  

At steady state at target (PV = SV), sum_e * Ki should produce the steady-state MV:

PV = SV 
error =  SV - PV = 0
Kp * error = 0 
MV = 3 = PID = 0 * Kp + Ki * sum_e

A nice way to understand the PID controller is to put units on everything and think of Kp, Ki, Kd as conversions of the process error, accumulated error*timeUnit, and rate-of-change of error/timeUnit into terms of the manipulated variable, and that the controlled system converts the controller's manipulated variable into units of output.

Dave X
  • 4,831
  • 4
  • 31
  • 42