Você está na página 1de 18

How to Create a System Simulation using LabVIEW 8.

2
Eric Shaffer and Michael Kleinigger, RPI Undergraduate Engineering Students Dr. Kevin Craig, Professor of Mechanical Engineering RPI Mechatronics Laboratory
This tutorial describes the process necessary to use LabVIEW to simulate the response of a given dynamic system based on a mathematical model, i.e., a set of differential equations, derived from the physical model of the actual physical system. The physical system used in this tutorial is the spring-pendulum dynamic system. The mathematical analysis, in this case the numerical solution of the nonlinear coupled differential equations and resulting predicted dynamic response, is part of the Engineering System Investigation Process, the cornerstone of modern engineering practice.

+r m

&2 kr Ft + mg cos = m r (l + r ) && && & & mgsin = m ( l + r ) + 2r


Physical Model Parameters: m = pendulum mass = 1.815 kg = unstretched spring length = 0.333 m
2

mspring = spring mass = 0.1445 kg k = spring constant = 172.8 N/m Ft = 5.71 N = pre-tension of spring rd = dynamic spring stretch

g = acceleration due to gravity = 9.81 m/s rs = static spring stretch, i.e., rs = (mg-Ft)/k = 0.070 m r = total spring stretch = rs + rd

LabVIEW Simulation of the Spring-Pendulum Dynamic System Mathematical Model Shown below is the final simulation diagram (Figure 1) along with plots of r vs. t and vs. t for a given set of initial conditions (Figure 2).

Figure 1

Figure 2

LabVIEW Simulation of the Spring-Pendulum Dynamic System Mathematical Model Step 1 First, open LabVIEW 8.2. Once the Getting Started screen has appeared (Figure 3), under the New menu select Blank VI. You are now presented with a blank front panel and behind it, an empty block diagram (Figure 4).

Figure 3

Figure 4

Step 2 Select the block diagram window. To do this you may either click the window to bring it into focus or press the Ctrl key and E simultaneously. This shortcut can also be used to switch back to the front panel. Step 3 We first need to add a simulation loop within which our equations will be diagrammed. Right click in an empty space on the block diagram screen (at this point, anywhere). You will be presented with the LabVIEW functions palette (Figure 5).

Figure 5

If youd like, click the thumbtack in the top left corner of this window to fix it in place. Next click Control Design and Simulation, then click Simulation and finally click the Simulation Loop. Your cursor will change its icon and you can then click and drag to place the simulation loop onto the block diagram. If at a later time you wish to adjust the size of the loop, you may click to select it, then click and drag the boxes which appear to adjust the size. Figure 6 shows our simulation loop. Figure 6

Note: Everything inside of a simulation loop will be run according to simulation time. This loop is how LabVIEW designates what part of the block diagram defines a simulation. Step 4 Next, we will need to adjust our simulation parameters. Right-click on the thick black border of simulation loop and select Configure Simulation Parameters Figure 7 shows the Configure Simulation Parameters window. Figure 7 Here you may adjust the time duration of the simulation, the solver method used, and the time step. For this example, set the initial time to 0 seconds and the final time to 60 seconds. From the ODE Solver drop-down box, select RungeKutta 3. Finally, enter 0.005 as the time step. The smaller this value, the more accurate the simulation results will be. However, with smaller time steps, more processing time will be required. Click OK to close the Configure Simulation Parameters window. Note: The different ODE Solver Methods usually yield similar results but derive them differently. Some offer fixed-step solving methods while others use variable step sizes. It is important to try different methods because some are incompatible with certain equations. RungeKutta 1 (Euler), for example, does not work well for this system.

Step 5 Now we will add controls for the equation parameters we wish to change. Press Ctrl+E to switch back to the front panel. Just as in the block diagram, right-click on an empty space to bring up the controls palette. From the Modern group (which is opened by default), select Numeric Numeric Control and place this on the front panel (Figure 8).

You will see that the controls label is highlighted once you place it on the front panel. Type r initial then click on a blank part of the front panel to de-select. We will create another control for theta initial. To do this, hold the control key, then click and drag the numeric control (See Figure 9). You will see that doing this creates a copy of the control being selected. Double-click on the label for this control, which should read r initial 2 and rename it to theta initial. Your front panel should look similar to that of Figure 10 at this point.

Figure 8

Figure 9

Figure 10

Step 6 Switch back to the block diagram and you will see two input blocks which correspond to the two controls you just created. Bring up the functions palette (by right-clicking in a blank area) and select Control Design and Simulation Simulation Continuous Linear Systems Integrator (Figure 11).

Figure 11

Create three copies of this block by holding the control key while dragging the block. Now, connect the output of one integrator block to the input of another. To do this, click once on the output terminal of one block, then move your cursor to the input terminal of the next block and click once. See Figure 12. Figure 12

Follow the same procedure to connect the other two blocks. This is called wiring the blocks. Your block diagram should appear similar to that of Figure 13.

Figure 13 Note: There are two sets of two linked integrator blocks. One set will be used in the differential equation for r, and the other for . The outputs of the rightmost blocks represent r and . The & , and the inputs to the leftmost blocks represent r & and && wires between the blocks represent r & & and , respectively.

Step 7 Now right-click one of the second integrator blocks (one on the right, whose input terminal is connected) and select Configuration. Under parameters, Initial Condition should already be selected. In the drop-down dialog box on the right, select Terminal as the parameter source. Click OK to close this window. Repeat this procedure for the other integrator block whose input is wired. This adds a terminal to the integrator block which allows the initial values to be controlled from the block diagram. See Figure 14.

Figure 14 Step 8 Now connect the r initial block (from the control we created earlier) to one of the integrators which now has an initial condition terminal. Connect the theta initial block to the other integrators initial condition terminal. Note: In order to model higher-order differential equations, you need only add more integrator blocks. Since this is a second-order system, we require two integrations. N-order systems will require N integrator blocks. Step 9 At this point you may label the inputs to the first integrator blocks as r acceleration and theta acceleration respectively. To add a label, double-left-click on a blank space in your block diagram and type your label. You may label the wires connecting the integrator blocks as r velocity and theta velocity. The outputs from the final integrator blocks may be labeled r and theta. See Figure 15.

Figure 15

Step 10 Now we will begin to diagram our equations within LabVIEW. Before we move too far, go ahead and save your progress by clicking the File menu and Save. While LabVIEW doesnt crash too often, when it does, youll be happy you saved often.
& . By using LabVIEWs basic mathematical We will start with the equation for r acceleration, & r blocks, we can connect values to form the equation in block diagram fashion. First, bring up the functions palette once more and select Programming (opened by default) Numeric Add (Figure 16). Place this onto the block diagram. Wire one of the input terminals to r, the output of the second integrator block. See Figure 19. Right-click the other input terminal and select Create Constant. Here, enter the value for the unstretched length of the spring, 0.333 m. The output from this block represents our (l + r) term, used three times within our equations. Its output can be wired into multiple different blocks.

10

Figure 16 Step 11 & 2 term. Open the functions palette again and select Numeric Now we will model the Square. Connect the input of this block to the theta velocity wire created in step 6, which connects two integrator blocks. From the functions palette, select Numeric Multiply. When adding these blocks to the diagram, try to arrange them so that its easy to see the flow of the equation from left to right. Wire one of the inputs of the multiply block to the output from the square block. Wire the other input to the addition block you created in step 10. This & 2 term. completes the (l + r) Step 12 Use the same procedure to create the remaining three parts of this equation, (k/m)r, Ft/m, and g[cos()]. To keep things simple, you may want to compute the result of (k/m) by hand and wire the result as a numeric constant (also found on the Numeric palette shown in Figure 16) to a multiplication block along with r. The same method can be used for the Ft/m term. However, if youd like to be able to adjust these values easily, you may wire them as separate constants to a

11

division block, which can also be found within the Numeric group. The cosine function can be found under Express Arithmetic and Comparison Express Math Express Trigonometric Functions cos as shown in Figure 17.

Figure 17

Figure 18

Step 13 Once you have created these parts of the equation, open the functions palette and select Control Design and Simulation Simulation Signal Arithmetic Summation (Figure 18). By default this block has a positive input terminal, a negative input terminal, and an output.

12

Double-click the summation block to open the Summation Configuration window. Change the number of inputs to 4 and change the sign of the inputs to +, +, -, - by clicking them. Click OK to close. Now wire the output of the positive terms of the equation to the positive terminals of this block and wire the output from the negative terms of the equation to the negative terminals. Finally, wire the output of the summation block to the first r integrator block. You have just created a block diagram representative of our first equation. See Figure 19 for an example of what your block diagram should now look like.

Note: The order of plusses and minuses in the summation block do not affect the performance or solution of the diagram. Their order depends mainly on the layout of the diagram, and the order which allows for the easiest and most aesthetically pleasing solution should be used.

Figure 19

To complete the VI, add and connect blocks for the second equation in the same manner & , you may want to use the compound arithmetic & described above. To compute the product 2r block, found under the Numeric palette (See Figure 16). Once you have placed this block, move your mouse over it and click and drag the grey box on the bottom so that there are three input terminals. Now right-click the block and select Change Mode Multiply.

13

Figure 20
Figure 20 shows the equation completely diagrammed. Some blocks have been rearranged in order to make the diagram more legible.

Note: To save space in the Block Diagram it is possible to use a Formula Block (located on the functions palette under Express Arithmetic & Comparison Formula). The formula block can take multiple inputs and is able to replace several mathematical operator blocks (see figure below). Even better than the Formula Express VI is the formula node (located on the functions palette under Programming Structures Formula Node). Use this if fast processing time is essential. In this case, however, our goal is to create a block diagram of our equations so that they can be easily understood and visualized.

14

Step 14 It is always a good idea to double check your diagram and verify that it is correct. An easy method to do this is by looking at the input of the first integrator block for rs acceleration. This & , and therefore it should equal the first equation. From the equation, input should be equal to & r & is equal to four terms added together. This is consistent with the diagram we know that & r because the output of a four-term summation block is the input to the integrator block. Work backwards from each terminal of the summation block to find out if terms are correct. For example, one addition terminal connects to a product block, which itself has two inputs, + r and & 2. This is correct and verifies that this section of the block diagram is equal to the equations. It is important to realize that a block diagram is simply a visual representation of an equation or set of equations. Step 15 Once you are satisfied with the arrangement of your equation diagram, open the functions palette once more and select Control Design and Simulation Simulation Graph Utilities SimTime Waveform. See Figure 21.

Figure 21

Figure 22

15

These blocks, shown in Figure 22, will allow us to plot r and versus simulated time as opposed to real time. Once you have placed the blocks on your diagram, create a copy of ONLY the Simulation Time Waveform block, not the waveform chart, by holding the control key and dragging the block. Now connect the input of one of the Simulation Time Waveform blocks to the r wire and connect the other to the wire. Click once on the wire connected to the new Waveform Chart and press the delete key to remove it. Right-click in a blank area of the block diagram to open the functions palette. Insert the Merge Signals block, which is located under Express Signal Manipulation. See Figure 23. Wire the output of this block to the waveform graph. Connect the inputs to the outputs from the Simulation Time Waveform blocks as shown in Figure 24.

Note: This Merge Signals block allows for and r to be graphed together on one chart. Without it only one value could be graphed on each chart.

Figure 24

Figure 23

16

Step 16 Switch back to your front panel (Ctrl+E), which should now look similar to Figure 25. Enter values for r Initial and theta Initial into your numeric controls. Right-click on your graph and select properties. Click the Format and Precision tab, and select Relative time from the type box. You may change the format as you wish. Click OK to close this dialog box.

Figure 25 Step 17 Now right-click on the graph and select Chart History Length. For this number, enter the result of dividing the total simulation time (60 seconds) by the time step (0.005 seconds). For our example this would be 12000 waveforms. Click OK to close. Next, double-click on the time shown in the far right of the graph (it should show 10 seconds). Change it to read 0:1:0, in accordance with our 60 second simulation time. You may also wish to expand the size of your waveform chart. To do this, move your mouse over the chart. You will see small grey boxes appear at the edges of the chart. Click and drag these to expand your chart. Note: The Chart History Length is the number of waveforms the chart will keep in memory. If this value is too small the chart will erase the oldest values (See Figure 27). Step 18 Finally, click the Run button on the front panel toolbar. LabVIEW may take a moment to compile the VI when it is first run. However, your output should appear and look identical to graph shown in Figure 26.

17

Figure 26

Figure 27

18

Você também pode gostar