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.
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. We will begin to construct the model simply from the expressions:
Sum(forces on M1)=M1*x1’’
Sum(forces on M1)=M1*x1’’
3. Constructing the Model
This set of system equations can now be represented graphically, without further manipulation. Begin by creating a Simulation Loop, from the Simulation section of the Control Design & Simulation palette.
First, we will construct two copies (one for each mass) of the expressions sum_F=Ma or a=1/M*sum_F. Drag two Summation blocks (from the Signal Arithmetic section of the Simulation palette) into the Simulation Loop. Double-click in an empty part of the block diagram to create labels. Label these Summation blocks "Sum F1" and "Sum F2".
Figure 1: Summation Blocks
The outputs of each of these Summation blocks represent the sum of the forces acting on each mass. Multiplying by 1/M will give us the acceleration. Drag two Gain blocks into your model (from the Signal Arithmetic section of the Simulation palette). Attach each one with a wire to the outputs of the Summation blocks.
These Gain blocks should contain 1/M for each of the masses. We will be entering these values externally. Double-click on each Gain block, and change the Parameter Source from Configuration Dialog Box to Terminal.
Label these two Gain blocks "a1" and "a2".
Figure 2: Gain Blocks
The outputs of these gain blocks will be the accelerations of each of the masses. We are interested in both the velocities and the positions of the masses. Since velocity is the integral of acceleration, and position is the integral of velocity, we can generate these signals using integrator blocks.
Drag two Integrator blocks (from the Linear Systems section of the Simulation palette) into your model for each of the two accelerations. Connect them with wires in two chains as shown below. Label these integrators "v1", "x1", "v2", and "x2", since these are the signals these integrators will generate.
Figure 3: Integrator Blocks
Now, drag two SimTime Waveform blocks from the Graph Utilities section of the Simulation palette, and connect them to the outputs of these integrators. Name them "x1 output" and "x2 output".
Figure 4: Waveform Graphs
Now we are ready to add in the forces acting on each mass. First, you need to adjust the inputs on each Sum block to represent the proper number (we will worry about the sign later) of forces. There are a total of 3 forces acting on M1 – double-click on the Sum F1 block and configure it to have 3 inputs (+ + +).
There are only 2 forces acting on M2, so we can leave Sum F2 alone for now.
Figure 5: Summation with 3 Inputs
The first force acting on M1 is the input force, F. Insert a Signal Generator block from the Signal Generation section of the Simulation palette, and connect it to the uppermost input of the Sum F1 block. Label the Signal Generator "F".
Figure 6: Signal Generator
The next force acting on M1 is the friction force. This force is equal to:
F (friction 1) = mu*g*M1*v1
To generate this force, we can tap off the velocity signal and multiply by a gain, mu*g*M1. Drag a Gain block into your model window. Find the wire coming from the v1 integrator and connect it to the input of the Gain block. Connect the output of the Gain block to the second input of Sum F1. Configure the Gain block so that it uses a Terminal for the Parameter Source instead of the Configuration Dialog Box. Name this block Friction 1.
The gain of this Gain block will be mu*g*M1. To achieve this, switch to the front panel and create 3 Numeric Controls. Name them mu, g, and M1.
On the block diagram, use a Compound Arithmetic VI from the Numeric palette to multiply these 3 variables. Wire the output to the new Gain block. Also, use the Reciprocal VI to invert M1, and wire this inverted output to the terminal of a1.
Figure 7: Add Friction 1 and Numeric Controls
This force, however, acts in the negative x1-direction. Therefore, it must connect to the Sum F1 block with a negative sign. Double-click on the Sum F1 block, and change the signs to + - +.
Figure 8: Configure Summation Block Directions
The last force acting on M1 is the spring force between masses. This is equal to k*(x1-x2).
First, we need to generate (x1-x2) which we can then multiply by k to generate the force. Insert a Summation block below the rest of your model. Label it "(x1-x2)" and change its list of signs to - +.
Since this summation comes from right to left, we need to flip the block around. Right-click the block and select “Reverse Terminals”.
Figure 9: Reversed Summation Block
Now, tap off the x2 signal and connect it to the negative input of the (x1-x2) Summation block. Tap off the x1 signal and connect it to the positive input.
Figure 10: Connections to Reversed Summation Block
Now, we can multiply this position difference by the spring constant to generate the spring force. Insert a Gain block into your model to the left of the Summation blocks. Configure the Gain block so that its Parameter Source is a Terminal.
On the front panel, create a Numeric Control and name it k. On the block diagram, connect this control to the Gain block that you just created. Label the Gain block "spring".
Connect the output of the (x1-x2) block to the input of the spring block, and connect the output of the spring block to the third input of Sum F1. Change the third sign of Sum F1 to negative (+ - -).
Figure 11: Spring Gain
Now, we can apply forces to M2. For the first force, we will use the same spring force we just generated, except that it adds in with positive sign. Simply tap off the output of the spring block and connect it to the first input of Sum F2.
Figure 12: Spring Output Connection
The last force to add is the friction on M2. This is done in the exact same manner as the friction on M1: tapping off v2, multiplying by a gain of mu*g*M2 and adding to Sum F2 with negative sign. You will need to create a Numeric Control for M2 as well.
You should now have the following:
Figure 13: Friction on M2
Now the model is complete. We simply need to supply the proper input and view the proper output.
The input of the system will be the force, F, provided by the engine. We already have placed the function generator at the input. The output of the system will be the velocity of the engine. Insert another SimTime Waveform block into the Simulation Loop, from the Graph Utilities section of the Simulation palette. Connect a wire from the output of the "v1" integrator block to this new Waveform Graph, to view the output.
Figure 14: Finished Model (Download)
You can download the completed model here.
4. Running the Model
Before running the model, we need to assign numerical values to each of the variables used in the model. For the train system, use the following values:
M1 = 1 kg
M2 = 0.5 kg
k = 1 N/sec
F= 1 N
u = 0.002 sec/m
g = 9.8 m/s^2
Enter these values using the front panel controls.
Now, we need to give an appropriate input to the engine. Double-click on the Signal Generator (F block). Select a square wave with frequency .001Hz and amplitude -1 (positive amplitude steps negative before stepping positive).
Figure 15: Input Signal Configuration
The last step before running the simulation is to select an appropriate simulation time. To view one cycle of the .001Hz square wave, we should simulate for 1000 seconds. Double-click on the terminals located on the left side of the Simulation Loop. In the Simulation Timing section at the top of the dialog box, set the initial time to 0 seconds, and the final time to 1000 seconds. Close the dialog box.
Now, switch to the front panel. Right-click on the x-axis of each Waveform Graph, and select “Auto-Scale X”.
Run the simulation and look at the v1 output graph to examine the velocity output. The input was a square wave with two steps, one positive and one negative. Physically, this means the engine first went forward, then in reverse. The velocity output reflects this behavior.
Figure 16: Velocity Output (Download)