ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PID with LabVIEW model

Hi. Actually I'm not sure if this is related to LabVIEW, but I have no idea where to ask this question. So please help me if it's possible, or remind me if I should remove this thread.

I'm trying to create a LabVIEW subVI, which simulate level of a water tank.

meihk_0-1598010130667.png

(the SimulateInlet's range is between 0-100, which will increase the level of tank if Inlet's value is true; the ControlValve's range is between 0-100, which will decrease the level)

The subVI above is used inside a while loop in main VI, and execute every 3 seconds:

meihk_1-1598010378223.png

 

I also have a code in C language like this:

float error=Level - levelsetpoint; (the levelsetpoint is fixed at 30, for example)
sum_error+=error;
controlvalve=Kp*error+Ki*sum_error+Kd*(error-previouserror);
previouserror=error;

(the code is run every 3 seconds)

The problem is, I don't know how to find the value of Kp, Ki and Kd.

 

 

 

 

 

 

Download All
0 Kudos
Message 1 of 4
(2,377 Views)

Also, I have tried to use Matlab Simulink, like this:

meihk_0-1598013112764.png

I think this is supposed to be exactly the same with my LabVIEW and C project, if I set the sample rate of MATLAB Simulink 3 seconds.

Then, in order to find Kp, Ki, Kd using Zieggler Nichols, I set the Kp=50, Ki=0, Kd=0, but the result looks like this, while I want it to be a sinusoid respond, right?

meihk_1-1598013259373.png

So, can you suggest me some way to find Kp, Ki, Kd? Or should I modify my LabVIEW model?

Thank you so much

P/S: I add this to the comment to separate the question, because I think it is easier to understand. 

 

0 Kudos
Message 2 of 4
(2,375 Views)

Hi meihk,

 


@meihk wrote:

I also have a code in C language like this:

float error=Level - levelsetpoint; (the levelsetpoint is fixed at 30, for example)
sum_error+=error;
controlvalve=Kp*error+Ki*sum_error+Kd*(error-previouserror);
previouserror=error;

(the code is run every 3 seconds)

The problem is, I don't know how to find the value of Kp, Ki and Kd.


You find the PID gains in LabVIEW in the same way as you would find them in C or MATLAB.

Ever heard of Ziegler-Nichols?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 4
(2,369 Views)

Hi GerdW,

Thank you for replying. 

Actually I have tried to use Ziegler-Nichols to calculate gains for my PID controller in MATLAB Simulink (I mentioned it in the comment, sorry for not being clear). But when I set Ki=0 and Kd=0, and adjust Kp, the respond always shows a straight line instead of a sinusoids (may be my plant is not correct).

I will try the PID in LabVIEW, thank you for recommending that.

 

0 Kudos
Message 4 of 4
(2,330 Views)