LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PID toolkit to control valves

Hello,

 

This is my first time using the PID toolkit and I am attempting to regulate the water level in a tank.  There is an input and output valve for the tank that operate according to a sent voltage from an NI module (0-5 V representing fully closed and fully open).  I want to be able to control the valves so that the program will open and close the valves as needed to reach the desired set point.  I have looked at the examples given, but I am having trouble since the examples use a simulation instead of an actual tank.  My main problem is determinging how to use the PID controller to control the valves.  Any help would be appreciated.  I have attached what I have so far, although it is barely anything. 

0 Kudos
Message 1 of 8
(3,737 Views)

Where's the code to drive the analog output? The first thing I would do is make sure that you can read the tank level and control the valve manually (by typing in a value) before you add the PID. If you can control the valve, then you actually have most of what you need in that VI - you just need to take the PID output and send it to the valve. However, there are a couple of things you should fix. You should NOT set the dt (s) input. You will need a control for the tuning parameters. Make sure you set the Output Range appropriately: if your valve expects a 0-5V signal, then that's what the output range should be, instead of the 0.8-2.5 range you have now.

 

EDIT: and one more important note!  Put a timer or Wait (ms) function inside your loop. All loops that could run indefinitely in LabVIEW should have a wait of some sort. Otherwise those loops run as fast as possible, consuming all processor time and slowing everything else on the computer.

 

The PID toolkit manual is fairly good. Look in Program Files\National Instruments\LabVIEW [version]\manuals\PID_User_Manual.pdf.

0 Kudos
Message 2 of 8
(3,724 Views)

For some reason, it will not allow be to post as blollar.  Thank you for the reply though, I have fixed the code and it will now can control the valve. I have also eliminated the dt(s) input as you said, and set the output range as needed.    However, it acts as just an on/off switch.  It either opens the valve fully or closes completely depending on if the actual tank level is below or above the desired setpoint.  Obviously I need logic built in so that it only opens or closes some (say from 2.5 to 2.3) when the tank level is near the desired set point to keep the tank at a steady state level.  How do I go about adding the logic?  Thanks again. 

0 Kudos
Message 3 of 8
(3,681 Views)

@vlollar wrote:

However, it acts as just an on/off switch.  It either opens the valve fully or closes completely depending on if the actual tank level is below or above the desired setpoint.


This usually indicates that the controller parameters are incorrect. Did you tune the controller, and if so, using what method? What are the gain values?

0 Kudos
Message 4 of 8
(3,671 Views)

I have tuned the controller with values that were used by the previous PI controller.  I am having to write a new one in LabView.  The values used are P = .011 and I = .0003 and D=0.  I think the problem comes from the high rate of data acquisition and output.  The data must be sampled at a high rate (1000 Hz) because the signal will give extraneous values.  The output will change many times per second and I think this is the main source of error.  My code is attached, hopefully that will show what I am doing.  Thanks for the help.

0 Kudos
Message 5 of 8
(3,629 Views)

If your data is very noisy, you may want to read multiple points of data per loop cycle, average (filter) them, and feed the filtered value to the PID loop.

 

How did you determine those PID gains? I doubt that an I value of 0.0003 will work well; that's a very short integral time. Note that in the LabVIEW PID algorithm, the I value is integral time, which is the reciprocal of the integral gain divided by the proportional gain.

Message 6 of 8
(3,625 Views)

I am taking 1000 points per second and then averaging 100 of those to get 10 per second.  How would I go about only getting one value per second?  The gains were from the old PI controller that was functional.  However, I have found another PI controller that was used and its gains were P = .0056 and I = .7135.  Do those values sound better?

0 Kudos
Message 7 of 8
(3,621 Views)

Sorry, hadn't looked at the VI prior to that reply. I see you are doing some filtering. You could easily get it to 1 value per second by reading 1000 points at a time instead of 100, although I don't know if that will be advantageous. Depends on how fast your system responds.

 

There are several different ways to set up a PID controller; while the algorithm is the same, the way the gains are used varies. You can't take the gains from one controller and use them in another controller unless you know that they're set up the same way. If the old controller was also the LabVIEW PID block then the gains should transfer; if it was something else, they may not. You should really tune the system properly.

0 Kudos
Message 8 of 8
(3,618 Views)