07 - Matlab Simmechanics 1
07 - Matlab Simmechanics 1
R2016a
How to Contact MathWorks
Phone: 508-647-7000
v
Save Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23
vi Contents
1
Simscape Multibody helps you develop control systems and test system-level
performance. You can parameterize your models using MATLAB® variables and
expressions, and design control systems for your multibody system in Simulink®. You
can integrate hydraulic, electrical, pneumatic, and other physical systems into your
model using components from the Simscape family of products. To deploy your models to
other simulation environments, including hardware-in-the-loop (HIL) systems, Simscape
Multibody supports C-code generation.
Key Features
• Single environment for simulating 3D mechanical systems together with multidomain
physical systems and control algorithms in Simulink
• Part definition tools, including standard geometry, extrusions defined in MATLAB,
and STEP files
• Mechanical joints and constraints covering standard and custom kinematic
relationships
• Simulation modes for analyzing motion and calculating forces
• 3D animation of multibody system dynamics
• Simscape Multibody Link utility, for interfacing to PTC Creo™ (Pro/ENGINEER®),
SolidWorks®, and Autodesk Inventor®; XML Schema, for interfacing with other CAD
platforms
• Support for C-code generation (with Simulink Coder™)
1-2
Required and Related Products
You can improve your speed and graphics resolution by adding a graphics accelerator
hardware card to your system. Animation of simulations is sensitive to central processor
and graphics card speed and memory. Experiment with graphics hardware and system
settings to find a reasonable compromise between quality and speed for your system.
Related Products
You can extend the capability of Simscape Multibody using other physical modeling
products found in the Simscape family. Each physical modeling product gives you a set
of block libraries with which you can model common components found in industry and
academia: rigid bodies, gears, valves, solenoids, etc.
With the physical modeling products, you can model not only mechanical systems, but
also electrical, hydraulic, and power systems. You can model each system separately,
and then integrate the systems into a single multiphysics model where you can analyze
combined system performance.
1-3
1 Introduction to Simscape Multibody Software
1-4
Open Simscape Multibody Model Template
See “Model Simple Link” on page 1-15 for an example on how to model a body using
the Simscape Multibody model template. See “Model Simple Pendulum” on page 1-20
for an example on how to assemble bodies into a simple mechanism.
1-5
1 Introduction to Simscape Multibody Software
1-6
Creating a Multibody Model
1-7
1 Introduction to Simscape Multibody Software
In this section...
“Basic Model Components” on page 1-8
“Model Actuation” on page 1-10
“Dynamical Sensing” on page 1-12
At its core, a multibody system is a set of bodies linked through joints and bound by
kinematic constraints such as gears. Forces and torques of various types enable you to
actuate the various bodies, while sensors enable you to sense the resulting motion. In
Simscape Multibody software, you use blocks to directly represent these components.
1-8
Multibody Model Anatomy
The body subsystems in turn consist of Solid blocks interconnected through Rigid
Transform blocks. The Solid blocks provide the solid properties, including geometry,
inertia, color, and frames—axis triads that encode all position and orientation
information in a model. The Rigid Transform blocks rotate and translate the solids to
ensure proper body assembly.
The figure shows the underlying block diagram for a binary link body subsystem. This
diagram includes three Solid blocks, representing the central and distal portions of the
binary link. Two Rigid Transform blocks translate the distal solids to their proper
locations near the ends of the central solid. The diagram includes a strictly optional
Reference Frame block.
1-9
1 Introduction to Simscape Multibody Software
Model Actuation
You can actuate a model by applying a force or torque to a rigid body or to a joint. To
represent forces and torques acting on a rigid body, Simscape Multibody provides a
Forces and Torques library. Drag a block from this library and connect it to the rigid
body frame(s) that you want to apply the force or torque to.
Block Function
External Force and Torque General force and/or torque originating
outside of the multibody model
Internal Force General force pair between two arbitrary
frames
Spring and Damper Force Spring-damper force pair between two
arbitrary frames
1-10
Multibody Model Anatomy
Block Function
Inverse Square Law Force Force pair with inverse dependence on the
square distance between two arbitrary
frames (e.g., Coulomb electrostatic forces)
Gravitational Field Gravitational pull of a point mass on all
rigid bodies as a function of their distances
to the point mass itself
The figure shows a four-bar model with an External Force and Torque block for force and
torque prescription at a crank link frame.
To specify the force or torque acting at a joint, Simscape Multibody provides a selection of
actuation inputs directly in the joint blocks. Each joint primitive—the basic component of
a joint block—provides a selection of actuation inputs specific to that primitive.
1-11
1 Introduction to Simscape Multibody Software
The figure shows a four-bar model with an actuation torque acting at a revolute joint.
Dynamical Sensing
You can sense various dynamical variables between frame pairs, e.g., for analysis or
control design. Sensing outputs can be of two types:
• Motion — Compute and output the relative position, velocity, or acceleration between
two Simscape Multibody frames. You can sense motion between joint frames, by
1-12
Multibody Model Anatomy
using the sensing capability of joint blocks, or between arbitrary frames, by using the
Transform Sensor block.
• Force or torque — Compute and output the forces and torques acting between two
Simscape Multibody frames. You can sense force and torque between the port frames
of certain Forces and Torques blocks, such as the Inverse Square Law Force block, or
between the port frames of a joint block.
Joint blocks enable you to sense different types of forces and torques between their
respective port frames, including:
The figure shows a four-bar model with a Transform Sensor block for trajectory
coordinate sensing between a coupler link frame and the world frame.
1-13
1 Introduction to Simscape Multibody Software
Related Examples
• “Model Simple Link” on page 1-15
• “Model Simple Pendulum” on page 1-20
1-14
Model Simple Link
Model Overview
Mechanical links are common building blocks in linkages, mechanisms, and machines.
The simple pendulum is an example with one link. In this tutorial, 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.
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.
1-15
1 Introduction to Simscape Multibody Software
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 In 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.
1-16
Model Simple Link
follower port frames of the Rigid Transform blocks, located at the link ends, with
respect to the Solid reference port frame.
Generate Subsystem
1 Select the Solid block and the two Rigid Transform blocks.
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.
1-17
1 Introduction to Simscape Multibody Software
4 In the Parameters & Dialog tab of the Mask Editor window, add 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.
Prompt Name
Length (cm) L
Width (cm) W
Thickness (cm) H
Density (kg/m^3) rho
Color [R G B] rgb
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]
Visualize Model
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. To 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.
1-18
Model Simple Link
1-19
1 Introduction to Simscape Multibody Software
In this section...
“Model Overview” on page 1-20
“Build Model” on page 1-21
“Specify Gravity” on page 1-22
“Set Pendulum Starting Position” on page 1-22
“Configure Solver” on page 1-22
“Assemble Model” on page 1-22
“Simulate Model” on page 1-23
“Save Model” on page 1-23
Model Overview
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 “Model
Simple Link” on page 1-15. A Revolute Joint block provides the rotational degree of
freedom between the link and the world frame.
1-20
Model Simple Pendulum
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 the tutorial “Model Simple Link”
on page 1-15 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.
5 Connect the blocks as shown in the figure. The port orientation of the Revolute
Joint block becomes important when you specify joint state targets, prescribe
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.
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.
1-21
1 Introduction to Simscape Multibody Software
Specify Gravity
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].
Configure Solver
1 In the Simulink Editor menu bar, select Simulation > Model Configuration
Parameters.
2 In the Solver tab, set the Solver parameter to ode15s (stiff/NDF). This solver
is the recommended choice for physical models.
3 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.
Assemble Model
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.
1-22
Model Simple Pendulum
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 .
Simulate Model
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.
Save Model
Save the model in a convenient folder under the name simple_pendulum. You reuse this
model in the tutorial “Analyze Simple Pendulum” on page 1-24.
1-23
1 Introduction to Simscape Multibody Software
Overview
In this tutorial, 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 “Model Simple
Pendulum” on page 1-20. By adding forces and torques to this model, you incrementally
1-24
Analyze Simple Pendulum
change the pendulum from undamped and free to damped and driven. The forces and
torques that you apply include:
• 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.
• Joint damping (Fb) — Internal torque, between the pendulum and the joint fixture,
that you parameterize in terms of a linear damping coefficient. You specify this
parameter using the Revolute Joint block that connects the pendulum to the joint
fixture.
• 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.
• Position
• Velocity
The block exposes two additional physical signal ports, labeled q and w, that output
the angular position and velocity of the pendulum with respect to the world frame.
3 Drag the following blocks into the model. You use them to output the joint position
and velocity to the MATLAB base workspace.
1-25
1 Introduction to Simscape Multibody Software
5 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.
1-26
Analyze Simple Pendulum
3 Plot the joint angular velocity with respect to the angular position, e.g., by entering
the following code at the MATLAB command prompt.
figure;
Plot(q.data, w.data);
The result, shown in the figure, is the phase plot of the joint corresponding to a
starting position of zero degrees with respect to the horizontal plane.
1-27
1 Introduction to Simscape Multibody Software
Try simulating the model using different starting angles. You can change the
starting angle in the State Targets > Position menu of the Revolute Joint block
dialog box. The figure shows a compound phase plot for starting angles of -80, -40, 0,
40, and 80 degrees.
1-28
Analyze Simple Pendulum
figure;
hold on;
plot(q);
plot(w);
The figure shows the resulting plot. Note that the pendulum oscillations decay with
time due to damping. At larger damping values, the pendulum becomes overdamped,
and the oscillations disappear altogether.
1-29
1 Introduction to Simscape Multibody Software
5 Plot the joint phase plot. To do this, at the MATLAB command prompt, you can enter
this code:
figure;
plot(q.data, w.data);
The figure shows the resulting plot.
1-30
Analyze Simple Pendulum
Try simulating the model using different starting angles. You can change the
starting angle in the State Targets > Position menu of the Revolute Joint block
dialog box. The figure shows a compound phase plot for starting angles of -240, -180,
-120, -60, 0, and 60 degrees.
1-31
1 Introduction to Simscape Multibody Software
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
Simulinik-PS Converter block converts the Simulink signal to a Simscape physical
signal compatible with Simscape Multibody blocks.
3 Connect the blocks as shown in the figure.
1-32
Analyze Simple Pendulum
4 In the Sine Wave block dialog box, set Amplitude to 0.06. This amplitude
corresponds to an actuation torque oscillating between -0.06 N and 0.06 N.
5 In the Revolute Joint block dialog box, ensure that State Targets > Position >
Value is set to 0 deg.
6 Run the simulation.
7 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);
The figure shows the resulting plot.
1-33
1 Introduction to Simscape Multibody Software
8 Plot the joint phase plot. To do this, at the MATLAB command prompt, you can enter
this code:
figure;
plot(q.data, w.data);
The figure shows the resulting plot.
1-34
Analyze Simple Pendulum
1-35
1 Introduction to Simscape Multibody Software
The table summarizes the differences in functionality between the two Simscape
Multibody generations.
1
Point-on-curve, gear, velocity, and screw constraints
1-36
Simscape Multibody Technology Comparison
2
All except velocity constraints
3
Variable gravity only
1-37