LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PID with cDAQ and DAQmx

I'm trying to control a pneumatic linear actuator using an electronic regulator and a position sensor for feedback. I want to use the cDAQ USB series of devices if possible. I've set up a test program with the PID function in the acquisition while loop. However I am getting a lot of steady state error, and no combination of Integral or Proportional gains seems to reduce it. I am wondering if something is wrong with my set up? Also, I have had trouble finding examples of using DAQmx and cDAQ with PID. The only example I've seen is one using Hardware-Timed Single point timing which my USB device is not capable of. Am I doing something noticeably wrong? I am using cDAQ 9174 with NI 9215 (analog input) and 9263 (analog output).

 

Ignore the "cycles", they are a placeholder for later functionality.

Download All
0 Kudos
Message 1 of 9
(3,720 Views)
0 Kudos
Message 2 of 9
(3,719 Views)

You appear to be at saturation.  I suspect you may also have integrator windup that needs to be reset.  Hard to tell whether your gains are reasonable.

 

Saturation: despite the graph that clearly shows a decreasing control output signal, there's no change at all in the measured response.  It's stuck at 100%.  Odds are that the device in question needs you to give it a considerably lower control signal in order to produce a response < 100%.   If you were to run for a long enough time, perhaps you'd start to see that happen.

 

Windup: the proportional term *ought* to be producing a negative term for your output.   The fact that your output is so far positive as to saturate the device suggests that the past PID history has built up a large windup in the integration term.  The decrease in the control output despite no change in the input or setpoint demonstrates that the integrator is active.  You'd decrease faster with a larger integration term, but then again you might only seem to need a larger integration term because of the past windup.

 

I don't do enough with PID to recognize that function by sight, but I'd look for ways to reset the integrator and to set a saturation limit on it.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 9
(3,699 Views)

I'm not sure what's going on in that first front panel screenshot, I probably should have chosen a better example. I've attached another screenshot. Right now it appears that the integrator is doing very little to change the PV regardless of gain. What makes you think it is saturated? I would think the output pressure would need to be 65 psi for saturation? I also tried wiring a reinitialize control to the PID (and the integrator) but after "reset" the PV seems to correct as slowly as before.

Download All
0 Kudos
Message 4 of 9
(3,678 Views)

Make sure that you are comparing apples to apples.  Your process variable, setpoint, output range and output should all have the same units.  You seem to be expecting output in psi when your inputs are in %.  If you want the PID VI to operate with engineering units, you need to supply all of your inputs in the desired engineering units as well.  Your instantaneous error is the instantaneous difference between the setpoint and the process variable.  The proportional output will be your proportional gain multiplied by that error.  So, if you have your setpoint at 90% (per your front panel image), and your process variable input is 100%, the instantaneous error is +10%, and the proportional output at your proportional gain of 0.45 will be 0.45*10%*-1 (because the error is positive)=-4.5%.  So, your PID wants to send a -4.5% output, but instead of +/- 100% output range, you have set your output to range from 0% to 65% (same units as your process variable). Your -4.5% is being coerced to zero as a result of your range setting, so the PID output should be zero.

 

I see you are taking that % output from the PID VI and writing it via NI-DAQmx as though it were a voltage signal.  Obviously that is going to cause problems.  The PID inputs and outputs need to be all %, all psi, or all Volts, in order to behave as expected.

 

Once you get your units sorted out, to tune the system, turn the integral and differential gains off, and make step changes to your setpoint with proportional only gain and watch how it behaves.  Once you have approximated the desired behaviour, then add integral to zero out the error.

Message 5 of 9
(3,617 Views)

First caveat: I was working from small clues and could be wrong.  My thought on "saturation" was due to seeing a measured value that seemingly was stuck at a constant "saturation point" of 100% despite a varying control output signal.

 

Your later screenshots give clues that point elsewhere.  The step response has the most to offer.

 

I agree that the long-lingering presence of steady state error suggests little or no integrator contribution.  As to the "regardless of gain", both screenshots use the same gain values so I've got no info there.  The responsiveness suggests a pretty decent proportional term, the overshoot and oscillation (in absence of much integrator) suggest it may be a bit high.  But probably in the right ballpark.

 

The "zn method" comment on the front panel suggests some use of analytical tools.  That makes me further guess that the units involved in the analytic method may not be the same as the units for the particular PID function in question, at least not for the integration term (and thus probably also the presenty unused derivative term).  They may well be right for the proportional term.

 

Some PID formulations are based on something like Kp*(1 + Ki/s + Kd*s) while others are based on something like (Kp + Ki/s + Kd*s).  I think I've seen some where the correct value for the integral and derivative gain terms depend on the sample interval.

 

Very carefully work through a comparison between the analytics and your specific PID implementation with a special focus on units and other scaling factors. 

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 6 of 9
(3,670 Views)

Your units don't match.  Setpoint, process variable, output range and output in the PID VI must all be %, or psi, or Volts.  You can't mix and match.  The output range settings only perform coercion - they don't rescale.

 

 

Message 7 of 9
(3,664 Views)

Hi CFER,

 

Your units don't match.  Setpoint, process variable, output range and output in the PID VI must all be %, or psi, or Volts.  You can't mix and match. 

Wrong, you surely can "mix'n match"!

All my PID loop do get e.g. temperature values and output heating power in % or pump speed in rpm…

 

All you need is to correct the P gain to do the right scaling… (With NIs PID implementation the I and D gain are in time units, while P gain is responsible to "scale" the PID output to the right values/units.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 9
(3,659 Views)

I misunderstood how the integral gain worked. A smaller term (0.01 for example) was able to eliminate the steady state error for the most part. 

0 Kudos
Message 9 of 9
(3,652 Views)