Effects
Tips

# Introduction: Simscape Modeling

In this section, we alternatively show how to build the Train System from the Introduction: Simulink Modeling page using the physical modeling blocks of the Simscape extension to Simulink. The blocks in the Simscape library represent actual physical components; therefore, complex multi-domain models can be built without the need to build mathematical equations from physical principles as was done above by applying Newton's laws. Recall the following diagram of the train system: ## Physical setup

As described in the previous page, the mass of the engine and the car are represented by M1 and M2, respectively. The engine and the car are connected by a coupling of stiffness k. The Force F represents the force generated between the engine wheel and the track and mu is the coefficient of rolling resistance. The system parameters are as follows:

`(M1)    Engine Mass                  1 kg`
`(M2)    Car Mass                     0.5 kg`
`(k)     Spring Constant              1 N/m`
`(mu)    Friction Coefficient         0.02`
`(F)     Force                        1 N`
`(g)     Acceleration due to gravity  9.8 m/s^2`

Open a new Simscape model by typing ssc_new in the MATLAB command window. A new model, as shown below, opens with a few commonly used blocks already in the model. The elements of the model are:

1. Solver configuration block
3. Scope connected to PS-Simulink block

The PS-Simulink and Simulink-PS blocks define the boundary between Simulink input/output models where the blocks are evaluated sequentially and Simscape models where the equations are evaluated simultaneously.

## Create the model

To create the model, a number of blocks need to be added.

1. Use Quick Insert to add the blocks. Click in the diagram and type the name of the block. A list of blocks will appear and you can select the block you want from the list.
2. After the block is entered, a prompt will appear for you to enter a parameter.
3. To rotate a block or flip blocks, right-click on the block and select the desired option from the Rotate & Flip menu.
4. To show the parameter below the block name, see Set Block Annotation Properties in the Simulink documentation.

• 2 Mass blocks (rename them "M1" and "M2")
• 1 Translational Spring block (rename this "spring")
• 1 Mechanical Translational Reference block
• 2 Translational Damper blocks (rename them "M1 friction" and "M2 friction")

Assign the parameter values listed at the beginning of this page to each of these blocks. In this case, we use the Translational Damper blocks to model the viscous friction in the system. Specifically, we assign the Damping coefficient of each block to be the friction coefficient multiplied by the normal force (mu*mass*g). If we desired a more sophisticated friction model, we could use Translational Friction blocks instead. Connect the blocks as shown to develop the model and rename the scope "Velocity". Now add the following elements to the model:

• An Ideal Force Source block (rename it "Force Source")
• A Signal Generator block (rename it "Force input")
• A Translational Motion Sensor block

In the Signal Generator block, choose the Waveform to be "square" with an Amplitude of "-1" and a Frequency of "0.001 Hz". To open the Configuration Parameters dialog, type CTRL-E. Then choose Type to be "Variable-step" and the Solver to be "auto". Also set the simulation Stop time to "1000". Connect the blocks as shown below to finish the model. ## Results

Run the simulation (type CTRL-T or press the green arrow run button) and open the Scope to examine the velocity output. The force input was a square wave with two steps, one positive and one negative. The Scope shows that the engine first went forward when the positive force was applied, then in the opposite direction some time after the negative force was applied. The velocity output identically matches the results of the Simulink model developed in the Introduction: Simulink Modeling page. You can download the final Simscape model created here by right-clicking here and then selecting Save link as .... 