Need Help? E-Mail Tech Support your Questions: support@xanalog.com If you haven’t already, you can get your own free copy of NL-SIM and MML. Part 7 can be found here. Now that you’ve worked through building a simple model, it’s time to move on to a more complex one. The model simulates the motion of a motor vehicle. In building this model you will learn to: - Use the gain and expression blocks
- Test a model
Your completed model will look like this: The vehicle model represents a second-order system with negative feedback. The force import block acts like an accelerator, simulating the force on the vehicle’s accelerator pedal. The mass constant block represents the vehicle’s mass, and the drag constant block represents the amount of resistance to motion. The first integral block, Vx, represents the speed of the vehicle and the second integral block, x, is the distance travelled by the vehicle. This model also introduces the sum block and the expression block. The sum block lets you add up to three signals. The expression block lets you create equations in algebraic format, producing custom functions. - To start a new model, select Edit from the Model menu (or press F3) and type in motor_vehicle for the new model’s name.
- Choose Picture (Block Diagram) from the New Model Metaphor window, then maximize the block diagram editing window.
- Drag two gain icons onto the work area. Change their names to drag and mass, respectively, as shown in the Gain Setup window below. Click on the default value of 0 in the lower right of the Matrix(1,1) area and enter values 0.01 for the drag, and 1000 for mass.
 |
Drag an import icon into the left side of your work area. When the Import Setup window opens, change the import block’s name to force. Click on the square-wave button, set the amplitude to 300 and the period to 0. Setting the import parameters to be a square wave with a period of zero makes this import block act like a constant input force of 300. You will later attach a slider control to this block which will allow you to change the acceleration (force) while the model is running. Click on OK to continue. With the force import block added to the mass and drag gain blocks, your model should now look like this: Add two integrator blocks. In the Integration Setup dialog windows, change the names to Vx and x, respectively. Next, add the export blocks. Place them as shown below, and name them Vx_out and x_out. Add the sum (+) block to the right of the force input block. Drag an expression block onto the screen and center it. When the Expression Setup window opens, enter force into the Enter import name box and click Add import. Without leaving this setup window, type mass in Enter import name box, then click on Add import. In the Expression box, type force/mass You have now defined the relationship between force and mass. Click on OK to close the window. Add another expression block for the drag force algebraic expression to define the negative feedback. Enter the import names drag and Vx. In the expression box, enter the following expression: - drag * Vx * abs(Vx) Hint: Use spaces between variables and operators for clarity. At this point, you should have all the blocks in your work area that appear in the model shown at the beginning of this exercise. Before adding the connecting signal lines, you may want to spread the blocks out to make more room. To move any block in the work area, press the shift key and click on the block you wish to move. Drag the block to it’s new location (you needn’t hold the mouse button while dragging), then click and release the left mouse button to fix the block in place. Your blocks should now be positioned as shown below. You are now ready to define the model’s Data Flow by connecting the blocks. Move the mouse pointer around the perimeter of the force block (which changes to green) until you see the connect point that points towards the sum(+) block and click there. A black line will appear connected to the force block. Drag the line straight across to the sum block; when the green border and connection point appear, click to attach the signal as shown below: Move the mouse pointer just above the drag constant block until a connection point appears. Click on the connection point. A pick an Import or Export dialog window will appear. Select Output (the default selection) by clicking OK as shown below: Drag the signal line from the drag constant block to the drag force expression block directly above it. Click on the connection point when it appears, click on the import “drag” and click OK. Connect the drag force expression block to the sum block. When you click on the connection point on the expression block, the Pick and Import or Export dialog window will appear with output selected. Click OK. Then click to connect the signal to the sum block. Now connect the sum block output signal into the force/mass expression block. Be sure to select the output of the sum block and select the force input of the force/mass expression block. Your block model should now look like this: Connect the mass and force/mass block. Click on OK to select output from the Exports of the mass constant block and select the mass input of the force/mass expression block.Connect the Vx and the x block together. Because you are creating a state output signal, just click on OK in the Pick and Import or Export window. When you attempt to connect the Vx output to the x input connection point, you have a choice of three inputs. Those choices are time deriv, I/C (initial conditions), or local mode. Choose time deriv and click on OK. Connect the x and x_out block together. Select state output for the x block output. Because the output of Vx goes to two other blocks (Vx_out and the drag force expression block), you need a branch connection. To create the branch point, double click on the line connecting Vx to x. Then create and connect the lines to the drag force expression block and the Vx_out export block. Connect the force/mass expression to the Vx integral block. Select time deriv as the import for the Vx Integrator block. The model should now look like this: The model is now ready for testing. Save the model by selecting Save from the File Menu or press Ctrl-s. TESTING THE MODEL Click on Load in the Model menu to load the model (or press F4) and the Trace Form window will appear. To access your model’s block diagram, click on the purple leaf icon using the right mouse button. Now click on each of the export blocks, Vx_out and x_out. Both export blocks will be highlighted with a dotted blue line indicating their signals have been selected. The output of the Vx integrator block represents the speed or velocity of the vehicle, while x, the integral of Vx, represents distance traveled. HINT: To return to the Trace Form window, use the Window menu, or use the Model Menu and click on Open Model Traces. To Return to the block model window, simply close the trace tree window. In a real vehicle, you would have a speedometer and an odometer. In this model you create them by bringing digital displays into your model by selecting Digitals from the Display menu (or Alt-F7). Two digital readouts, one for each of the output signals you selected, Vx_out and x_out, will appear. Your screen should now look like this: Before running the model all the way through a cycle, try using the single-step capability of NL-SIM. There are two ways to run a model. You can press F9, which runs your model until a specified completion time (or indefinitely), or, as mentioned earlier, you can use single step mode by pressing F8. You can also activate single-step by selecting Single Step from the Model menu.Press F8, and notice that the numerical values in the Vx and x blocks change. With single-step mode, you can observe your simulations behavior in small increments. Single-step mode is particularly useful when you want to observe your model’s behavior as it approaches a critical point or debug an unstable system. Before running the model, select Run/Display Times from the Setup menu (or press F7). Select Run Indefinitely and change the Display Update Interval from 0.1 to 1. Also make sure that the start time is set to 0. In the Setup menu, click on Save Setup File. Under Dir/File Name: type in the name vehicle.svs when asked Create this file?, answer Yes. Press F9 to run the model. Watch the digital displays, particularly Vx_out. notice how it starts accelerating slowly, then more quickly, and eventually levels off. When it levels off, the input force and drag force will be equal. Stop the model with the Pause/Break Key. Now try running the model using a time plot to display the acceleration. Close the Vx_out and the x_out windows. With the left mouse button, click on the x_out and the Vx_out blocks, deselecting them (which removes the blue borders). With the left mouse button, click on the Vx integral, selecting it. Select Time Plots from the Display menu (or press Alt-F6). The Vx time plot will appear. Increase the size of the Vx time plot window so that it resembles the one below: Next deselect Vx and select the force import block. Select Digitals from the Display menu; the force digital display will appear. Hint: If the time plot disappears, select Displays on Top from the Display menu to recover it. Arrange the displays as shown below: Set the Vx time plot’s time scale (time to traverse the screen) to 10 seconds (2e3) by clicking several times on the up arrow. Next set the Vx time plot’s vertical scale to 200 (2e2) by first double clicking in the graph area, and then clicking on the up arrow of the Vx scale. First press F6 too reset the model, then press F9 to start the model. Notice again, that “Vx”, the speed, begins by increasing while the input force is greater than the drag force, then “Vx” levels off as input force and drag force become equal. Close the digital and time plot displays. CONGRATULATIONS You have completed the NL-SIM Getting Started Guides Part Six of Seven Continue on to the Final Part 7 |