Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Using the LabVIEW PID Control Toolkit with the LabVIEW Control Design and Simulation Module

3 ratings | 3.67 out of 5
Print | PDF

Overview

Proportional Integral Derivative (PID) is one of the most common used control algorithm due its easy of use and no need of knowledge of the system or plant to be controlled. National Instruments provides ready-to-run, advanced (PID) control algorithms on the NI LabVIEW PID Control Toolkit. Combined with the LabVIEW Control Design and Simulation Module, the LabVIEW PID Control Toolkit can help you simulate and tune your PID controllers without implementing them in real-world systems, thus avoiding possible problems such as instability. In this tutorial, learn how to use the LabVIEW PID Control Toolkit with the LabVIEW Control Design and Simulation Module and design the PID gains for the position controller of a DC motor for a real-time system.

DC Motor modelling

We will design a velocity control for a DC motor. For the sake of simplicity consider a simplified transfer function for a DC motor where effect such as friction and disturbances are being considered:

Where

Ф(s) is the angular velocity (rad/sec)

V(s) is applied voltage (V)

J is the rotor inertia (9.64E-6)

R is the rotor resistance (3.3 Ώ)

K is the torque constant (0.028 N-m\A)

L is the Inductance ( 4.64E-3 H)

B is the Friction Torque Constant (1.8E-6 N-m-s)

 

If you replace the numeric values, you get the following transfer function:

Your goal is to implement a PID algorithm that is going to run on a real-time controller with a loop rate of 1000 Hz (0.001 period).

Start by opening the LabVIEW graphical development environment and going to the block diagram. In the function palette, go to Control Design and Simulation->Simulation->Simulation Loop and click and extend to create a simulation loop.

 

Figure 1. Create a simulation loop.

Again on the Control and Simulation subpalette, go to Continuous Linear Systems and click once on Transfer Function and once inside the simulation loop you created previously. Double-click to input the transfer function parameters.

              

 

Figure 2. Input transfer function parameters.

Now implement the PID algorithm. In the function palette, go to the Control Design and Simulation->PID subpalette and drag and drop the PID.vi. Because the PID algorithm is going to run on a real-time computer-based  controller with fixed loop rate, right-click on the PID.vi and select SubVI Node Setup…. to bring up a parameter pane. You can use this pane to tell the simulation loop how to handle timing with this particular VI. Assume the controller is going to run at a 1000 Hz loop rate, so select discrete with a period value of 0.001.

 

Figure 3. Tell the simulation loop how to handle timing with the PID.vi.

The “d” that appears on the PID.vi indicates that it is being handled as a discrete system.

Run the cursor over the PID.vi until you are on top of the PID Gains Terminal (you might hit CTRL+E to show the interactive help if you cannot find it). Right-click and select Create Control. This creates a control on the block diagram that you can use to change the PID gains interactively. Finally, right-click on the dt(s) terminal and right-click to create a constant. This should be the same as the digital period you created previously, 0.01

To create an input signal, use a step signal. From Control Design and Simulation->Simulation->Signal Generation, select Step Signal and drop it into the simulation loop. Leave parameters per default.

Figure 4. Create an input signal using a step signal.

Now insert the means to view the simulation results. First bundle the input (step signal) with the output from the motor transfer function into Build Array, which you can find on the Programming->Arrays subpalette. Collect these signals and plot them on a graph on the front panel. To do so, go to Control Design and Simulation->Simulation->Utilities and select and drop Collector. On the front panel, create an XY graph to graphically see the simulation results. Connect all the signals as shown in Figure 5.

 

Figure 5. Collect the signals.

If you rearrange the front panel elements and run with the default values, you end up with a graph similar to Figure 6:

Figure 6. View the simulation results graphically.

Fine-Tune the Simulation

Use LabVIEW native graphical capabilities to improve the simulation and fine-tune the PID gains.

  First change axis properties to have a better view of the simulation results. Right click over the graph and unckeck the “AutoScale X” property under X Scale option

Figure 7. Graph properties

Before making changes to the PID controller, make the simulation more efficient. As seen on Figure 6 there is no need to simulate the default 10 seconds; the plant is fast enough so that a final simulation time of 2 seconds is enought. Now modify the simulation parameters by double-clicking on the simulation-loop configuration pane and bringing up the configuration panel. Change the parameter as shown in Figure 7.

 

Figure 7. Change the simulation parameters.

 

PID Tunning

You now can run the VI continuously and change the PID gains until you are satisfied with the results.

A typical procedure to tune a PID controller would be

1.       1 Kc to 1 and Ti, Td to zero. Keep increasing/decreasing Kc until the response has some overshoot

2.       2 Modify Td to make the system faster and compensate the overshoot

3.       3 Modify Ti to remove any steady-state error on the step response

Figure 8. Simulation results with Kc=1.8, Ti=0.00026, and Td=0.000001.

Conclusion

You now know how to simulate a discrete-based PID controller with the continuous dynamic system behavior of a DC motor. You can apply this technique to any kind of hybrid system where continuous and discrete behavior is mixed. One of the benefits of the procedure shown is that the control algorithm you used is exactly the same as the one you would use in a real-time implementation, and you can take advantage of many of its features, such as integral antiwindup.

 

Downloads

pid_velocitycontrol.vi

3 ratings | 3.67 out of 5
Print | PDF

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).