# Basics of Control Design and Simulation

Publish Date: Mar 13, 2015 | 18 Ratings | 3.78 out of 5 | Print

## Overview

This tutorial provides an introduction to the LabVIEW Control Design and Simulation Module and its use with the LabVIEW MathScript RT Module. A second order system is used to introduce the use of the software for analysis and simulation of a simple system. A more in-depth tutorial is available for further study: Introduction to LabVIEW in 3 Hours for Control Design and Simulation.

### Control System Analysis With Graphical LabVIEW

1. Create a new VI.
2. Save the VI as My Controls Example VI.
3. Right-click on the block diagram and navigate to Control Design & Simulation»Control Design»Model Construction and drag the CD Construct Special TF Model VI onto the block diagram.

1. See the figure below.  Left-click on the polymorphic VI selector of the CD Construct Special TF Model VI in the block diagram and select 2nd Order Model.  The second order model can be used to describe a mass-spring-damper system or an RLC circuit.

1. On the front panel, right-click to display the Controls palette.  Navigate to Modern»Numeric»Horizontal Pointer Slide and drag a Horizontal Pointer Slide onto the front panel.  While the name of the slide is highlighted, change it to Damping Ratio.  Follow the same procedure to create another slide and make its name Natural Frequency.
2. On the front panel, click on the maximum number for the Damping Ratio slide and change it to 1.  Change the maximum number for the Natural Frequency slide to 5.
3. On the block diagram, wire the Damping Ratio and the Natural Frequency slides to the Damping Ratio and Natural Frequency inputs respectively of the CD Construct Special TF VI.
4. Navigate to Control Design & Simulation»Control Design»Time Response and drag the CD Step Response VI onto the block diagram.  The polymorphic instance of the CD Step Response VI will show SS for state space but this will change after the next step.
5. Wire the Transfer Function Model output of the CD Construct Special TF VI to the State-Space Model input of the CD Step Response VI.  The polymorphic instance of the CD Step Response VI will automatically change to TF.
6. Right-click on the Step Response Graph output of the CD Step Response VI and select Create»Indicator.
7. Go to Programming»Structures»While Loop and place a While Loop on the diagram around the existing code.
8. Hover over the Loop Condition terminal at the bottom right of the loop, right-click, and select Create Control to put a Stop button on the front panel for the VI.
9. The block diagram of your VI should look like this:

1. Run the VI after putting in nonzero values for Damping Ratio and Natural Frequency on the front panel.  Adjust the parameters on the front panel and observe the system response.  Your front panel should be similar to this:

### Control System Analysis With LabVIEW MathScript RT Module

1. Save My Controls Example VI as My Controls Example With MathScript VI.
2. Delete CD Construct Special TF VI, CD Step Response VI, and Step Response Graph from the block diagram.
3. Go to Programming»Structures and place a MathScript Node on the diagram inside of the While Loop.

1. Right-click on the left-hand side of the MathScript Node and select Add Input.  Name the input zeta.
2. Right-click again on the left-hand side of the MathScript Node and select Add Input.  Name the input wn.
3. Wire the Damping Ratio slide to the zeta input of the MathScript Node.
4. Wire the Natural Frequency slide to the wn input of the MathScript Node.
5. Inside the MathScript Node, type in the following:

num = wn*wn;

den = [ 1 2*zeta*wn wn*wn];

sys = tf(num,den);

t = 0:0.01:5;

stepresp = step(sys, t);

1. Right-click the right-hand side of the MathScript Node and select Add Output»stepresp.
2. Right-click the stepresp output of the MathScript Node and select Choose Data Type»All Types» 1D-Array»DBL 1D.
3. On the front panel of the VI, right-click to display the Controls palette.  Navigate to Modern»Graph and drag a Waveform Graph onto the front panel.  While the name of the graph is highlighted, change it to Step Response.
4. Wire the stepresp output of the MathScript Node to the Step Response graph.
5. The block diagram of your VI should look like this:

1. Run the VI after putting in nonzero values for Damping Ratio and Natural Frequency on the front panel.  Adjust the parameters on the front panel and observe the system response.  Your front panel should look like this (depending upon the values you have chosen):

### Dynamic System Simulation in LabVIEW

1. Go back to My Controls Example VI and save as My Control and Simulation Example VI
2. Right-click on the block diagram and navigate to Control Design & Simulation»Simulation and drag a Control & Simulation Loop onto the block diagram beneath the While Loop.  The Control & Simulation Loop can be set for precise timing like the Timed Loop in LabVIEW.  However, the Control & Simulation Loop has built in ODE solver capability.

1. Navigate to Control Design & Simulation»Simulation»Continuous Linear Systems and drag a Transfer Function inside the Control & Simulation Loop.
2. Double-click on the Transfer Function to open the Transfer Function Configuration dialog box as shown below. Select the Terminal option for the Parameter source.

1. Wire the Transfer Function Model output of the Construct Special TF Model VI in the While Loop to the Transfer Function input of the Transfer Function block in the Control & Simulation Loop.
2. Select a Step Signal from the Control Design & Simulation »Simulation»Signal Generation subpalette and place it on the diagram.  Double-click on the Step Signal block to open the configuration page and change the step time to be 0.
3. Wire the output of the Step Signal to the Input of the Transfer Function.
4. Select a Simulation Time Waveform from the Control Design & Simulation»Simulation»Graph Utilities subpalette and place it on the diagram.
5. Wire the output of the Transfer Function to the input of the Simulation Time Waveform.
6. Double-click on the leftmost side of the Control & Simulation Loop to display the Configure Simulation Parameters dialog box.  Select Solver Method» Runge-Kutta 1 (Euler).  Set Simulation Time»Final Time to 30.

1. Click OK to close the Configure Simulation Parameters dialog box.
2. The block diagram should now look like the one below.  The resulting VI starts with a model creation and analysis/design loop and, when the stop button is pressed, moves into a simulation loop.

1. Run the VI.  Adjust the damping and natural frequency during the design process and then press the stop button to begin the simulation process.  The Step Response Graph should match the Simulation plot since they both show the same type of input.  The LabVIEW Control Design and Simulation Module can simulate continuous or discrete-time models with more complex input signals and can include many other effects such as nonlinearities and signal noise.  Also, the LabVIEW Real-Time Module and flexible NI I/O can be used with the LabVIEW Control Design and Simulation Module to prototype and implement control systems as well as hardware-in-the-loop simulations.
2. For further study, open and run the Forward Dynamics for Puma 560 VI in the Robotics»Robotic Arm shipping examples folder.  A Control & Simulation Loop is used to simulate a Puma 560 robot collapsing under gravity.

### Ratings

Rate this document