You are on page 1of 19

AIN SHAMS UNIVERSITY

FACULTY OF ENGINEERING
MECHATRONICS ENGINEERING DEPARTMENT
Credit Hours Programs

Spring Semester, 2018


MCT 456: Dynamic Modeling and Simulation
Lab. 05: Modeling of Mechanical Systems Using Simscape Multibody (Simmechanics)
Second Generation

Contents*

1- Introduction to Simscape Language


2- Explore Simscape Foundation Library
3- Essential Steps for Constructing a Physical Models
Step 1: Create New Model
Step 2: Assemble Physical Network
Step 3: Adjust Block Parameters and Variable Targets
Step 4: Add Sources
Step 5: Add Sensors
Step 6: Connect to Simulink with Interface Blocks
Step 7: Simulate Model
Step 8: View Simulation Results (Simscape Results Explorer and variables and states viewer)
4- Introduction to simmechanics and multibody 2nd generation

5- Simmechanics first generation vs second generation.

6- Simscape Multibody Background (Frames, Transforms (translation and rotation), Inertia, joints, etc.).

7- Explore second generation block library.

8- Build mechanical models.

Background

Simscape™ enables you to rapidly create models of physical systems within the Simulink® environment. With Simscape,
you build physical component models based on physical connections that directly integrate with block diagrams and other
modeling paradigms. You model systems such as electric motors, bridge rectifiers, hydraulic actuators, and refrigeration
systems, by assembling fundamental components into a schematic. Simscape add-on products provide more complex
components and analysis capabilities. These add-on products include Simscape multibody, Simscape Fluids, Simscape
Electronics and Simscape Driveline.

Simscape helps you develop control systems and test system-level performance. You can create custom component
models using the MATLAB® based Simscape language, which enables text-based authoring of physical modeling
components, domains, and libraries. You can parameterize your models using MATLAB variables and expressions, and
design control systems for your physical system in Simulink.

1. Exercise 1: Creating a simple mass-spring-damper using Simscape™ physical networks.

 Description: In this exercise, you model a simple mass-spring-damper using Simscape™ physical networks.
The Simscape model uses physical connections, which permit a bidirectional flow of energy between
components. The following schematic represents a simple model of a car suspension. It consists of a spring and
damper connected to a body (represented as a mass), which is agitated by a force. You can vary the model
parameters, such as the stiffness of the spring, the mass of the body, or the force profile, and view the resulting
changes to the velocity and position of the body.

*
Parts of this lab sheet are based on the Simscape Multibody documentation, provided b Mathworks
 Build Model
To create an equivalent Simscape diagram, follow these steps:

1. Create a new Simulink model using the Blank Model template. The software creates an empty model in
memory and displays it in a new model editor window.
2. Open the Simulink® Library Browser.

Note: Alternately, you can type ssc_new at the MATLAB® Command prompt, to create a new model
prepopulated with certain required and commonly used blocks.

3. Open the Simscape > Foundation Library > Mechanical > Translational Elements library.
4. Drag the Mass, Translational Spring, Translational Damper, and two Mechanical Translational Reference
blocks into the model window.
5. Orient the blocks as shown in the following illustration. To rotate a block, select it and press Ctrl+R.

6. Connect the Translational Spring, Translational Damper, and Mass blocks to one of the Mechanical
Translational Reference blocks as shown in the next illustration.

Page 2 of 19
7. To add the representation of the force acting on the mass, open the Simscape > Foundation Library >
Mechanical > Mechanical Sources library and add the Ideal Force Source block to your diagram.

To reflect the correct direction of the force shown in the original schematic, flip the block by selecting
Diagram > Rotate & Flip > Flip Block > Up-Down from the top menu bar of the model window. Connect
the block's port C (for "case") to the second Mechanical Translational Reference block, and its port R (for
"rod") to the Mass block, as shown below.

8. Add the sensor to measure speed and position of the mass. Place the Ideal Translational Motion Sensor
block from the Mechanical Sensors library into your diagram and connect it as shown below.

Page 3 of 19
9. Now you need to add the sources and scopes. They are found in the regular Simulink libraries. Open the
Simulink > Sources library and copy the Signal Builder block into the model. Then open the Simulink >
Sinks library and copy two Scope blocks. Rename one of the Scope blocks to Velocity and the other to
Position.

10. Every time you connect a Simulink source or scope to a Simscape diagram, you have to use an appropriate
converter block, to convert Simulink signals into physical signals and vice versa. Open the Simscape >
Utilities library and copy a Simulink-PS Converter block and two PS-Simulink Converter blocks into the
model. Connect the blocks as shown below.

Page 4 of 19
11. Each topologically distinct physical network in a diagram requires exactly one Solver Configuration
block, found in the Simscape > Utilities library. Copy this block into your model and connect it to the
circuit by creating a branching point and connecting it to the only port of the Solver Configuration block.
Your diagram now should look like this.

12. Your block diagram is now complete. Save it as mech_simple.

 Modifying Initial Settings

After you have put together a block diagram of your model, as described in the previous section, you need to
select a solver and provide the correct values for configuration parameters.
To prepare for simulating the model, follow these steps:
1. Select a Simulink solver. On the top menu bar of the model window, select Simulation > Model
Configuration Parameters. The Configuration Parameters dialog box opens, showing the Solver node.
- Under Solver options, set Solver to ode23t (mod. stiff/Trapezoidal).
- Expand Additional options and set Max step size to 0.2.

Page 5 of 19
Also note that Simulation time is specified to be between 0 and 10 seconds. You can adjust this setting
later, if needed.

Figure 1: Configuration Simulation Parameters

2. Click OK to close the Configuration Parameters dialog box. Save the model.

 Running the Simulation

After you've put together a block diagram and specified the initial settings for your model, you can run the
simulation.

1. The input signal for the force is provided by the Signal Builder block. The signal profile is shown in the
illustration below. It starts with a value of 0, then at 4 seconds there is a step change to 1, and then it
changes back to 0 at 6 seconds. This is the default profile.

Page 6 of 19
2. The Velocity scope outputs the mass velocity, and the Position scope outputs the mass displacement as a
function of time. Double-click both scopes to open them.

3. To run the simulation, click in the model window toolbar. The Simscape solver evaluates the model,
calculates the initial conditions, and runs the simulation.
4. Once the simulation starts running, the Velocity and Position scope windows display the simulation
results, as shown in the next illustration.

In the beginning, the mass is at rest. Then at 4 seconds, as the input signal changes abruptly, the mass
velocity spikes in the positive direction and gradually returns to zero. The mass position at the same time
changes more gradually, on account of inertia and damping, and stays at the new value as long as the force
is acting upon it. At 6 seconds, when the input signal changes back to zero, the velocity gets a mirror
spike, and the mass gradually returns to its initial position.

You can now adjust various inputs and block parameters and see their effect on the mass velocity and
displacement.

 Adjusting the Parameters

After running the initial simulation, you can experiment with adjusting various inputs and block parameters.
Try the following adjustments:

Changing the Force Profile


This example shows how a change in the input signal affects the force profile, and therefore the mass
displacement.
1. Double-click the Signal Builder block to open it.
2. Click the first vertical segment of the signal profile and drag it from 4 to 2 seconds, as shown below. Close
the block dialog.

3. Run the simulation. The simulation results are shown in the following illustration.

Page 7 of 19
Changing the Model Parameters
In our model, the force acts on a mass against a translational spring and damper, connected in parallel. This
example shows how changes in the spring stiffness and damper viscosity affect the mass displacement.
1. Double-click the Translational Spring block. Set its Spring rate to 2000 N/m.
2. Run the simulation. The increase in spring stiffness results in smaller amplitude of mass displacement, as
shown in the following illustration.

3. Next, double-click the Translational Damper block. Set its Damping coefficient to 500 N/(m/s).
4. Run the simulation. Because of the increase in viscosity, the mass is slower both in reaching its maximum
displacement and in returning to the initial position, as shown in the following illustration.

Changing the Mass Position Output Units


In our model, we have used the PS-Simulink Converter block in its default parameter configuration, which
does not specify units. Therefore, the Position scope outputs the mass displacement in the default length units,
that is, in meters. This example shows how to change the output units for the mass displacement to millimeters.
1. Double-click the PS-Simulink Converter1 block. Type mm in the Output signal unit combo box and
click OK.
2. Run the simulation. In the Position scope window, click to autoscale the scope axes. The mass
displacement is now output in millimeters, as shown in the following illustration.
Page 8 of 19
3. Save the model.

 If you replace the signal builder in the previous model with a step input, identify the system response: is
it overdamped or underdamped system?

Page 9 of 19
Simmechanics and Multibody 2nd generation Background

Simmechanics provides a multibody simulation environment for 3D mechanical systems, such as robots, vehicle
suspensions, construction equipment, and aircraft landing gear. You model the multibody system using blocks
representing bodies, joints, constraints, and force elements, and then Simmechanics formulates and solves the equations
of motion for the complete mechanical system. Models from CAD systems, including mass, inertia, joint, constraint,
and 3D geometry, can be imported into Simmechanics. An automatically generated 3D animation lets you visualize the
system dynamics.

Simscape™ Multibody™ (previously Simmechanics) software contains two technologies: first generation and second
generation. First-generation technology includes the block library and visualization utility found in Simmechanics
releases prior to R2012a. Latest-generation technology introduces a simpler modeling paradigm with a new block
library, a new computational engine, an advanced visualization utility based on OpenGL® computer graphics, and
tighter integration with other Simscape modules.

Simscape Multibody first- and second-generation technologies have different sets of capabilities. Which technology to
use depends on the effects you need to model. The second Simscape Multibody generation is recommended for all
models except those requiring time-varying constraints or variable mass.

The table summarizes the differences in functionality between the two Simscape Multibody generations.

Feature First Generation Second Generation


Mass/Inertia Calculation Manual only Automatic or manual
Solid Geometry No Yes
Animation Replay No Yes
3-D Model Exploration Limited Yes
Initial State Targets Limited Yes
Simscape Logging No Yes
Code Generation Yes Yes
CAD Import Yes Yes
Motion Actuation Yes Yes
Force/Torque Sensing Yes Yes
Complex Constraints1 Yes Yes2
Variable Mass/Gravity Yes Yes3
Gravitational Fields No Yes
1
Point-on-curve, gear, velocity, and screw constraints
2
All except velocity constraints
3
Variable gravity only

Page 10 of 19
2. Exercise 2: Creating a simple link using 2nd generation elements.

 Description: In this exercise, you model a simple link with two end frames that you can later connect to joints.
Rigid Transform blocks provide the end frames, while a Solid block provides geometry, inertia, and color. For
simplicity, the model assumes the link has a brick shape (cuboid).

 Build Model

1. At the MATLAB® command line, enter smnew


The Simscape™ Multibody™ block library and a model template with commonly used blocks open up.

2. Make a copy of the Rigid Transform block and paste it in the model. The Rigid Transform blocks enable
you to create new frames to which you can connect joints during multibody assembly.

3. Delete the blocks Simulink-PS Converter, PS-Simulink Converter, and Scope. You do not need these
blocks in this tutorial.

4. Connect the remaining blocks as shown in the figure. Ensure that the base frame ports (B) of the Rigid
Transform blocks both face the Solid block frame port. Since each Rigid Transform block applies a spatial
transformation with respect to its base frame, switching port connections generally changes the spatial
relationship between the two frames.

5. Double click the Solid block dialog box, specify the following parameters. Later, you define the
MATLAB variables shown using a Subsystem block that contains the Solid and Rigid Transform blocks.
Among its advantages, this approach enables you to update variables used in multiple blocks from a single
place—the Subsystem block dialog box.

Parameter Value Units


Geometry > Dimensions [L W H] Change to cm
Inertia > Density rho Default units
Graphic > Visual Properties > Color rgb Not applicable
6. In the dialog boxes of the Rigid Transform and Rigid Transform1 blocks, specify the following
parameters. These parameters encode the offset between the base and follower port frames of the Rigid
Transform blocks, located at the link ends, with respect to the Solid reference port frame.

Parameter Rigid Transform1 Rigid Transform Units


Translation > Method Standard Axis Standard Axis Not applicable
Translation > Axis +X +X Not applicable
Translation > Offset L/2 L/2 Change to cm
 Generate Subsystem

1. A Select the Solid block and the two Rigid Transform blocks.

Page 11 of 19
2. Right-click the highlighted region and select Create Subsystem from Selection. Simulink® adds a new
Subsystem block containing the Solid and Rigid Transform blocks. At the end of the tutorial, this will be a
custom block representing the simple link rigid body.

3. Right-click the Subsystem block, and select Mask > Create Mask. A mask editor opens up, enabling you
to specify the numerical values of the MATLAB variables you entered in the Solid and Rigid Transform
block dialog boxes (L, W, H, rho, rgb).

4. In the Parameters & Dialog tab of the Mask Editor window, drag and drop five edit fields to the
Parameters folder. You can find this folder in the Dialog box pane. In the edit fields, specify the
following parameters and click OK. Prompt is the desired text for each parameter in the Subsystem block
dialog box. Name is the MATLAB variable associated with each Subsystem block parameter.

5. Double-click the Subsystem block dialog box and enter the following numerical values. These are the
values of the MATLAB variables that you entered in the Solid and Rigid Transform block dialog boxes.

Parameter Value
Length (cm) 20
Width (cm) 1
Thickness (cm) 1
Density (kg/m^3) 2700
Color [R G B] [0.25 0.40 0.70]
6. Don’t forget to save your file!

Page 12 of 19
 Visualize your model

1. From the Simulation Update the block diagram. You can do this by selecting, in the Simulink menu bar,
Simulation > Update Diagram. Mechanics Explorer opens with a front view of the simple link model.

In the Mechanics Explorer toolstrip, select the isometric view button to obtain the 3-D view shown
below

2. View the frames present in the model—including those you created using the Rigid Transform blocks—
select View > Show Frames in the Mechanics Explorer menu bar. Select the Solid.
Note that the frames are highlighted when they are selected in the mechanics explorer window

Run the model. . Guess why the model doesn’t move? What modifications are required in the model to let the
solid part drop under its own weight in the gravity direction? (try a 6-DoF joint and comment on the results)
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………
……………………………………………………………………………………………………
The simscape multibody has variatey of joints which allows some degrees of freedoms (DoFs) and restrict
others. The following table shows the function of some of these joints:

Page 13 of 19
Where: Px, Py, and Pz are the translations in x, y and z respectively, Rx, Ry, and Rz are rotations around x, y
and z axes respectively, S is spherical which allows rotation about any 3-D axis, and T and R are the
translation and rotation respectively.

3. Exercise 2: Modeling a simple pendulum

 Description: The pendulum is the simplest mechanical system you can model. This system contains two rigid
bodies, a link and a fixed pivot, connected by a revolute joint. In this tutorial, you model and simulate a
pendulum using the custom link block you created in Exercise 1. A Revolute Joint block provides the
rotational degree of freedom between the link and the world frame.

 Build Model

1. At the MATLAB® command prompt, enter smnew. The Simscape™ Multibody™ block library and a
model template with commonly used blocks open up.
2. Delete blocks Simulink-PS Converter, PS-Simulink Converter, Scope, and Rigid Transform. You do not
need them in this tutorial.
3. Drag the Simple Link custom block you created in Exercise 1 into the model.
4. Drag a Revolute Joint block into the model. You can find this block in the Simscape > Multibody >
Joints library. This block provides one rotational degree of freedom between its port frames. Unlike the 1st
generation, this rotational degree of freedom is always about the +Z axis direction.
5. Connect the blocks as shown in the figure. The port orientation of the Revolute Joint block becomes
important when you specify joint actuation inputs, or sense joint dynamic variables. The Revolute Joint
block interprets each quantity as that applied to the follower frame with respect to the base frame, so
switching the port connections can affect model assembly and simulation.

Page 14 of 19
6. In the Solid block dialog box, specify the following parameters. This block connects rigidly to the World
frame and therefore has no effect on model dynamics. You can leave the inertia parameters in their default
values.

Parameter Value Units


Geometry > Dimensions [4 4 4] Change to cm
Graphic > Visual Properties > Color [0.80 0.45 0] Not applicable

 Specify Gravity

7. The Revolute Joint block uses the common Z axis of the base and follower frames as the joint rotation
axis. To ensure the pendulum oscillates under the effect of gravity, change the gravity vector so it no
longer aligns with the Z axis. To do this, in the Mechanism Configuration block dialog box, set the
Uniform Gravity > Gravity parameter to [0 -9.81 0].

 Set Pendulum starting position

8. You can specify the desired joint angle using the State Targets menu in the Revolute Joint block dialog
box. To do this, select State Targets > Position and enter the desired joint angle. For this tutorial, you can
leave the angle in its default value, which corresponds to a horizontal pendulum starting position.

 Configure the solver

9. In the Simulink® Editor menu bar, select Simulation > Model Configuration Parameters.
10. In the Solver tab, set the Solver parameter to ode15s (stiff/NDF). This solver is the recommended choice
for physical models (all Simscape models) by Mathworks.
11. Set Max step size to 0.01 and click OK. The small step size increases the simulation accuracy and
produces a smoother animation in Mechanics Explorer. Small step sizes can have a detrimental effect on
simulation speed but, in such a simple model, a value of 0.01 provides a good balance between simulation
speed and accuracy.

 Visualize your model

12. Update the block diagram. You can do this in the Simulink Editor menu bar, by selecting Simulation >
Update diagram. Mechanics Explorer opens with a 3-D view of the model in its initial configuration.
13. In the Mechanics Explorer toolstrip, check that the View convention parameter is set to Y up (XY Front).
This view convention ensures that gravity is vertically aligned on your screen. Select a standard view
button to refresh the Mechanics Explorer display. The figure shows a front view of the model. Save the
Visualization settings by clicking the Save explorer configuration to model button .

Page 15 of 19
 Simulate the model

14. Run the simulation. You can do this through the Simulink Editor menu bar, by selecting Simulation >
Run. Mechanics Explorer plays a physics-based animation of the pendulum model.
15. Save the model in a convenient folder under the name simple_pendulum. You reuse this model in the
next exercise.

4. Exercise 3: Analyzing a simple pendulum

 Description: In this Exercise, you explore the various forces and torques that you can add to a model. Then,
using blocks with motion sensing capability, you analyze the resulting dynamic response of the model. The
end result is a set of time-domain and phase plots, one for each combination of forces and torques. You create
these plots using MATLAB® commands with Simscape™ Multibody™ motion outputs as arguments.

Your starting point is the simple pendulum model that you built in the previous exercise. By adding forces and
torques to this model, you incrementally change the pendulum from undamped and free vibration to forced-
damped vibration driven by external forces. The internal and external forces and torques that can be applied to
the model:

o Gravitational force (Fg) — Global force, acting on every rigid body in direct proportion to its mass,
that you specify in terms of the acceleration vector g. You specify this vector using the Mechanism
Configuration block.

o Joint internal damping (friction) and stiffness (friction and restoring) (Fb) — Internal damping and
stiffness torques in the joint mechanics are parameterized in terms of a linear damping and stiffness
coefficients. You specify these parameters using the Revolute Joint block that connects the pendulum
to the joint fixture.

o Actuation torque (FA) — Driving torque, between the pendulum and the joint fixture, that you
prescribe directly as a Simscape physical signal. You prescribe this signal using the Revolute Joint
block that connects the pendulum to the joint fixture.

 Sense pendulum motion

1. Open the simple_pendulum model that you created in the Exercise 2.


2. In the Sensing menu of the Revolute Joint block dialog box, select the following variables:
a. Position
b. Velocity
3. The block exposes two additional physical signal ports, labelled q and w, that output the angular position
and velocity of the pendulum with respect to the world frame.
4. Drag the following blocks into the model. You use them to output the joint position and velocity to the
MATLAB base workspace.

Library Block Quantity


Simscape > Utilities PS-Simulink Converter 2
Simulink > Sinks To Workspace 2
Double click on PS-Simulink, you can change the output signal units. E.g.: deg or rad for angle and
deg/sec or rad/sec for angular velocity. The default 1 is equivalent to rad.

5. Change the Variable name parameters in the “To Workspace” blocks dialog box to q and w. These
variables make it easy to identify the joint variables that the “To Workspace” blocks output during
simulation—position, q, and velocity w.
Note that the “To Workspace” is used to create a variable in the MATLAB workspace with the specified
name. The variable will contain a vector that represents the change of the indicated variable with time.
6. Connect the blocks as shown in the figure. Ensure that the To Workspace block with variable name q
connects, through the PS-Simulink Converter block, to the Revolute Joint block port q, and that the To
Workspace block with variable name w connects to the Revolute Joint block port w.
Note that the “PS-Simulink” converter is required between any sensed physical signal in the 2 nd generation
and any Simulink block.

Page 16 of 19
7. Save the model under a different name, e.g., simple_pendulum_analysis, in a convenient folder.

 Analyze the undamped pendulum

8. Run the simulation. You can do this in the Simscape Multibody Editor menu bar by selecting Simulation
> Run. Mechanics Explorer opens with a 3-D animation of the simple pendulum model.
9. Plot the joint position and velocity with respect to time, e.g., by entering the following code at the
MATLAB command prompt:
figure; % Open a new figure
hold on;
plot(q); % Plot the pendulum angle
plot(w); % Plot the pendulum angular velocity
10. The figure shows the resulting plot.

Note: The units for angle and angular velocity in this graph are rad and rad/s respectively

Calculate the nature frequency of a pendulum and compare it to the signal frequency obtained in the previous
figure.

…………………………………………………………………………………………………………………….
……………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………….

𝑔
Consider the nature frequency of a pendulum equal to √ where g is the gravity constant and L is the bar
𝐿
length given in Exercise 1. The signal frequency is the inverse of the periodic time.

Page 17 of 19
 Analyze the damped pendulum

11. In the Revolute Joint block dialog box, set Internal Mechanics > Damping to 8e-5 (N*m)/(deg/s). The
damping coefficient causes energy dissipation during motion, resulting in a gradual decay of the pendulum
oscillation amplitude.
12. Ensure that State Targets > Position > Value is set to 0 deg.
13. Run the simulation.
14. Plot the joint position and velocity with respect to time. To do this, at the MATLAB command prompt,
you can enter this code:
figure;
hold on;
plot(q);
plot(w);
15. The figure shows the resulting plot. Note that the pendulum oscillations decay with time due to damping.
This response is for the underdamped system, while at larger damping values, the pendulum becomes
overdamped, and the oscillations disappear altogether.

 Analyze the damped and driven pendulum

16. In the Revolute Joint block dialog box, set Actuation > Torque to Provided by Input. And don’t change
the motion settings. The block exposes a physical signal input port that you can use to prescribe the joint
actuation torque.
17. Drag these blocks into the model.

Library Block
Simscape > Utilities Simulink-PS Converter
Simulink > Sources Sine Wave
The Sine Wave block provides a periodic torque input as a Simulink® signal. The Simulink-PS Converter
block converts the Simulink signal to a Simscape physical signal compatible with Simscape Multibody
blocks.
Don’t forget to change the Simulink-PS converter units to N*m (Newton meter).

Page 18 of 19
18. Connect the blocks as shown in the figure.

19. In the Sine Wave block dialog box, set Amplitude to 0.06. This amplitude corresponds to an actuation
torque oscillating between -0.06 Nm and 0.06 Nm.
20. In the Revolute Joint block dialog box, ensure that State Targets > Position > Value is set to 0 deg.
21. Run the simulation and note the movement of the pendulum in the model explorer window.
22. Plot the joint position and velocity with respect to time. To do this, at the MATLAB command prompt,
you can enter this code:
figure;
hold on;
plot(q);
plot(w);
23. The figure shows the resulting plot.

Page 19 of 19

You might also like