NI Tutorial 6435 En

download NI Tutorial 6435 En

of 4

Transcript of NI Tutorial 6435 En

  • 8/13/2019 NI Tutorial 6435 En

    1/41/4 www.ni.c

    1.

    2.

    3.

    4.

    5.

    Modeling a System

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

    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 developed by of the Mechanical Engineering department at the University of Michigan and of theControl Tutorials Professor Dawn Tilbury Professor Bill Messner

    Department of Mechanical Engineering at Carnegie Mellon University and were developed with their permission.

    Controls Tutorials Menu PID Control

    Table of Contents

    Train System

    Free Body Diagram and Newton's Law

    State-variable and Output Equations

    Transfer Function

    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 star

    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 b

    he 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

    he 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.

    http://www.library.cmu.edu/ctms/ctms/index.htmhttp://www-personal.umich.edu/~tilbury/http://www.me.cmu.edu/faculty1/messner/info.htmlhttp://zone.ni.com/devzone/cda/tut/p/id/6368http://zone.ni.com/devzone/cda/tut/p/id/6440http://www.ni.com/http://zone.ni.com/devzone/cda/tut/p/id/6440http://zone.ni.com/devzone/cda/tut/p/id/6368http://www.me.cmu.edu/faculty1/messner/info.htmlhttp://www-personal.umich.edu/~tilbury/http://www.library.cmu.edu/ctms/ctms/index.htm
  • 8/13/2019 NI Tutorial 6435 En

    2/42/4 www.ni.c

    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

    assumed. The transfer function should look like the one shown below.

    LabVIEW Graphical Approach

    If you choose to use the transfer function, create a blank VI and add the CD Construct Transfer Function Model VI to your block diagram. This VI is located in the Model Construction section of the

    Control Design palette.

    Click the drop-down box that shows SISO and select Single-Input Single-Output (Symbolic). To create inputs for this transfer function, right-click on the Symbolic Numerator terminal and select

    Create Control. Repeat this for the Symbolic Denominator and Variables terminals. These controls will now appear on the front panel.

    Figure 2: Create Transfer Function

    Next, add the CD Draw Transfer Function VI to your block diagram, located in the Model Construction section of the Control Design palette. Connect the Transfer Function Model output from the C

    Create Transfer Function Model VI to the Transfer Function Model input on the CD Draw Transfer Function VI.

    Finally, create an indicator from the CD Draw Transfer Function VI. To do this, right-click on the Equation terminal and select CreateIndicator.

    Figure 3: Display Transfer Function

    Now create a While Loop, located in the Structures palette, and surround all of the code in the block diagram. Next, right-click on the Loop Condition terminal in the bottom-right corner of the While

    Loop, and select CreateControl.

    Figure 4: Transfer Function with While Loop

    With this VI, you can now create a transfer function for the train system. Try changing the numerator and the denominator in the front panel, and observe the effects on the transfer function equatio

    ( )Figure 5: Transfer Function Front Panel Download

    5. State-Space Model

    Another method to solve the problem is to use the state-space form. Four matrices A, B, C, and D characterize the system behavior and will be used to solve the problem. The state-space form w

    is found from the state-variable and the output equations is shown below.

    ftp://ftp.ni.com/pub/devzone/tut/modeling_transfer-function.viftp://ftp.ni.com/pub/devzone/tut/modeling_transfer-function.vi
  • 8/13/2019 NI Tutorial 6435 En

    3/43/4 www.ni.c

    LabVIEW Graphical Approach

    To model the system using the state-space form of the equations, use the CD Construct State-Space Model VI with the CD Draw State-Space Equation VI.

    Figure 6: State-Space Model Block Diagram

    With this VI, you can now create a state-space model for the train system. Try changing the terms in the front panel, and observe the effects on the state-space model.

    ( )Figure 7: State-Space Model Front Panel Download

    Hybrid Graphical/MathScript Approach

    Alternatively, you can use a MathScript Node to create the state-space model. To do this, create a blank VI and insert a MathScript Node from the Structures palette. Copy and paste the following

    m-file code into the MathScript Node:

    A=[ 0 1 0 0;

    -k/M1 -u*g k/M1 0; 0 0 0 1;

    k/M2 0 -k/M2 -u*g];

    B=[ 0; 1/M1; 0; 0];

    C=[0 1 0 0];

    D=[0];

    sys= ss(A,B,C,D);

    Next, right-click on the left border of the MathScript Node and select Add Input. Name the input M1. Repeat this process to create inputs for M2, k, u, and g.

    Figure 8: MathScript Node

    Right-click on the right border of the MathScript Node and select Add Output to create an output called sys. After creating this output, right-click on it and select Choose Data Type Add-ons

    object.

    Next, right-click on each input and select Create Control.

    Figure 9: MathScript Node with Inputs

    Add the CD Draw State-Space Equation VI to the block diagram, and create an equation indicator. Connect the sys output from the MathScript Node to the State-Space Model input of the CD

    Draw State-Space Equation VI.

    Finally, create a While Loop around the code, and create a control for the Loop Condition terminal.

    ftp://ftp.ni.com/pub/devzone/tut/modeling_state-space-model.viftp://ftp.ni.com/pub/devzone/tut/modeling_state-space-model.vi
  • 8/13/2019 NI Tutorial 6435 En

    4/44/4 www.ni.c

    Figure 10: Using MathScript Node to Create State-Space Equation

    With this VI, you can now create a state-space model for the train system. Try changing the terms in the front panel, and observe the effects on the state-space model.

    ( )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, the open-loop and closed-loop system behavior can be

    studied.

    Controls Tutorials Menu PID Control

    ftp://ftp.ni.com/pub/devzone/tut/modeling_state-space-model-m.vihttp://zone.ni.com/devzone/cda/tut/p/id/6368http://zone.ni.com/devzone/cda/tut/p/id/6440http://zone.ni.com/devzone/cda/tut/p/id/6440http://zone.ni.com/devzone/cda/tut/p/id/6368ftp://ftp.ni.com/pub/devzone/tut/modeling_state-space-model-m.vi