You are on page 1of 4

# Modeling a System

Publish Date: Oct 10, 2012 | 6 Ratings | 4.33 out of 5

Overview
LabVIEW can be used to represent a physical system or a model. This tutorial shows how to enter a differential equation model into LabVIEW using the LabVIEW Control Design and Simulation Module. These tutorials are based on the Control Tutorials developed by Professor Dawn Tilbury of the Mechanical Engineering department at the University of Michigan and Professor Bill Messner of the Department of Mechanical Engineering at Carnegie Mellon University and were developed with their permission.

PID Control

1. Train System 2. Free Body Diagram and Newton's Law 3. State-variable and Output Equations 4. Transfer Function 5. State-Space Model

1. Train System
In this example, we will consider a toy train consisting of an engine and a car. Assuming that the train only travels in one direction, we want to apply control to the train so that it has a smooth start-up and stop, along with a constant-speed ride. The mass of the engine and the car will be represented by M1 and M2, respectively. The two are held together by a spring, which has the stiffness coefficient of k. F represents the force applied by the engine, and the Greek letter, mu (which will also be represented by the letter u), represents the coefficient of rolling friction.

2. Free Body Diagram and Newton's Law
The system can be represented by following Free Body Diagrams.

Figure 1: Free Body Diagrams From Newton's law, you know that the sum of forces acting on a mass equals the mass times its acceleration. In this case, the forces acting on M1 are the spring, the friction and the force applied by the engine. The forces acting on M2 are the spring and the friction. In the vertical direction, the gravitational force is canceled by the normal force applied by the ground, so that there will be no acceleration in the vertical direction. The equations of motion in the horizontal direction are the following:

3. State-variable and Output Equations
This set of system equations can now be manipulated into state-variable form. The state variables are the positions, X1 and X2, and the velocities, V1 and V2; the input is F. The state variable equations will look like the following:

Let the output of the system be the velocity of the engine. Then the output equation will be:

4. Transfer Function
To find the transfer function of the system, we first take the Laplace transforms of the differential equations.

The output is Y(s) = V1(s) = s X1(s). The variable X1 should be algebraically eliminated to leave an expression for Y(s)/F(s). When finding the transfer function, zero initial conditions must be

1/4

www.ni.com

zero initial conditions must be assumed. Finally. Figure 4: Transfer Function with While Loop With this VI. Figure 3: Display Transfer Function Now create a While Loop. Click the drop-down box that shows “SISO” and select “Single-Input Single-Output (Symbolic)”.The output is Y(s) = V1(s) = s X1(s). Four matrices A. Try changing the numerator and the denominator in the front panel. The state-space form which is found from the state-variable and the output equations is shown below. and select Create»Control. When finding the transfer function. These controls will now appear on the front panel. add the CD Draw Transfer Function VI to your block diagram. The variable X1 should be algebraically eliminated to leave an expression for Y(s)/F(s). right-click on the Equation terminal and select Create»Indicator. Next. create a blank VI and add the CD Construct Transfer Function Model VI to your block diagram. Connect the Transfer Function Model output from the CD Create Transfer Function Model VI to the Transfer Function Model input on the CD Draw Transfer Function VI. and observe the effects on the transfer function equation. create an indicator from the CD Draw Transfer Function VI. LabVIEW Graphical Approach If you choose to use the transfer function. you can now create a transfer function for the train system. located in the Structures palette. This VI is located in the Model Construction section of the Control Design palette. Figure 2: Create Transfer Function Next. located in the Model Construction section of the Control Design palette. right-click on the Loop Condition terminal in the bottom-right corner of the While Loop. State-Space Model Another method to solve the problem is to use the state-space form. To create inputs for this transfer function. To do this. right-click on the Symbolic Numerator terminal and select Create » Control. and D characterize the system behavior and will be used to solve the problem. 2/4 www. C.com . Repeat this for the Symbolic Denominator and Variables terminals. The transfer function should look like the one shown below. Figure 5: Transfer Function Front Panel (Download) 5. and surround all of the code in the block diagram. B.ni.

u.C. Connect the “sys” output from the MathScript Node to the “State-Space Model” input of the CD Draw State-Space Equation VI. k. Next. Finally. -k/M1 -u*g k/M1 0. k/M2 0 -k/M2 -u*g]. Figure 9: MathScript Node with Inputs Add the CD Draw State-Space Equation VI to the block diagram. use the CD Construct State-Space Model VI with the CD Draw State-Space Equation VI. 1/M1. 0.ni. C=[0 1 0 0].B. 3/4 www. D=[0].com . Copy and paste the following m-file code into the MathScript Node: A=[ 0 1 0 0. you can now create a state-space model for the train system.D). sys= ss(A. you can use a MathScript Node to create the state-space model. To do this. 0]. right-click on it and select Choose Data Type » Add-ons » SS object. After creating this output. Figure 7: State-Space Model Front Panel (Download) Hybrid Graphical/MathScript Approach Alternatively. and create a control for the Loop Condition terminal. right-click on the left border of the MathScript Node and select “Add Input”. create a While Loop around the code. Repeat this process to create inputs for M2. and g. right-click on each input and select Create » Control. Name the input “M1”. and observe the effects on the state-space model. Next. create a blank VI and insert a MathScript Node from the Structures palette.LabVIEW Graphical Approach To model the system using the state-space form of the equations. Try changing the terms in the front panel. Figure 6: State-Space Model Block Diagram With this VI. and create an equation indicator. B=[ 0. 0 0 0 1. Figure 8: MathScript Node Right-click on the right border of the MathScript Node and select “Add Output” to create an output called “sys”.

Figure 11: State-Space Equation Front Panel (Download) Continue Solving the Problem Once the differential equation representing the system model has been created in LabVIEW in the transfer function or state-space form.com .ni. and observe the effects on the state-space model. the open-loop and closed-loop system behavior can be studied.Figure 10: Using MathScript Node to Create State-Space Equation With this VI. Controls Tutorials Menu PID Control 4/4 www. you can now create a state-space model for the train system. Try changing the terms in the front panel.