LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW PID Code explained?

Hi NI Community,

 

I'm working on understanding the code behind the LabVIEW PID. First, let me say that YES I understand the theory of a classical PID control and understand how Kp, Ki, and Kd should affect my system. I'm interested in some of the underlying code behind the PID (DBL).vi in LabVIEW.

 

Specifically, integrator error in this VI is defined as


IntError = Error + LastError *(Kp/Ki)*0.5*(1/60)*dt + LastIntError

 

 

I'm simpliflying some of the logic but that's the meat of it. What are the 0.5 and 1/60 attempting to do in this equation? The dt is in units of seconds. Also, shouldn't this IntError be multiplied by Ki (e.g. Igain) at somepoint as well to follow the model of a Classical PID control?

 

 

These links were a great starting point but I'm trying to connect the dots between this theory and the actual code running in LabVIEW:

http://zone.ni.com/devzone/cda/tut/p/id/6440

http://zone.ni.com/devzone/cda/tut/p/id/3782#toc1

 

 

 

 

Thanks,

Craig

0 Kudos
Message 1 of 4
(5,869 Views)

Hello Craig,

 

The PID toolkit is based on the "academic" version of PID where it uses proportional gain affecting integral time and derivative time. Those time are in minutes instead of seconds, that is the reason you have 1/60 on the equation.

 

Also, during the process of discretization of the integrator (making the continuous integrator discrete), you have basically 3 ways to discretize it: forward, backward and trapezoidal (also known as bilinear or tustin). The best method is the trapezoidal, which is based on getting the following formula: (see page 2-2 on the PID manual - http://www.ni.com/pdf/manuals/372192d.pdf)

 

IntegralError (i) ={0.5* [error (i) - error (i-1)]} + IntegralError (i-1)

 

Then, by changing the time to minutes and making the integral gain = proportinal gain / integral time, then you would get to our current implementation.

 

Also, notice that there are in general 3 methods of representing PID algorithms, which we call: academic, parallel and series. See http://digital.ni.com/public.nsf/allkb/6E76EC47B831FAED86256E4E007347DC

http://zone.ni.com/reference/en-XX/help/371894D-01/lvctrldsgn/cd_pid_mdl_vi/

 

Please let me know if you have any more questions.

Barp - Control, Simulation, RTT and HIL - National Instruments
Message 2 of 4
(5,843 Views)

hi

can any1  please explain the code in farmula node: the file is attached here

 

regards

nofil

0 Kudos
Message 3 of 4
(5,776 Views)

I'm going to assume you understand how a formula node works, if you don't, see this

 

http://zone.ni.com/reference/en-XX/help/371361G-01/glang/formula_node/

 

and this

 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvhowto/formula_node_syntax/ .

 

This one in particular seems to perform some PID differential equation math. You might look at our article on PID theory http://zone.ni.com/devzone/cda/tut/p/id/3782 for further explination there.

0 Kudos
Message 4 of 4
(5,744 Views)