07 - Matlab Simmechanics 2
07 - Matlab Simmechanics 2
User's Guide
R2016a
How to Contact MathWorks
Phone: 508-647-7000
Multibody Modeling
Spatial Relationships
1
Working with Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Frame Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Frame Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Frame Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
v
Translation Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29
Specifying Translation . . . . . . . . . . . . . . . . . . . . . . . . . 1-29
Cartesian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29
Standard Axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30
Cylindrical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-31
Rigid Bodies
2
Creating Body Subsystems . . . . . . . . . . . . . . . . . . . . . . . . 2-2
vi Contents
Solid Inertia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Inertial Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Blocks with Inertia . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Inertia in a Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
Inertia Parameterizations . . . . . . . . . . . . . . . . . . . . . . 2-24
Custom Inertia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24
Moments and Products of Inertia . . . . . . . . . . . . . . . . 2-25
Complex Inertias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
vii
Define Solid Properties . . . . . . . . . . . . . . . . . . . . . . . . 2-59
Visualize Solid Model . . . . . . . . . . . . . . . . . . . . . . . . . 2-60
Multibody Systems
3
Assembling Multibody Systems . . . . . . . . . . . . . . . . . . . . 3-2
viii Contents
Assembling Multibody Models . . . . . . . . . . . . . . . . . . . . . 3-8
Model Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
Connecting Joints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
Orienting Joints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9
Guiding Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
Verifying Model Assembly . . . . . . . . . . . . . . . . . . . . . . 3-11
ix
Model Rack and Pinion . . . . . . . . . . . . . . . . . . . . . . . . . . 3-45
Model Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-45
Model Pinion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-47
Model Rack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-49
Add Rack and Pinion Constraint . . . . . . . . . . . . . . . . . 3-52
Actuate Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-53
Simulate Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-55
Open Complete Model . . . . . . . . . . . . . . . . . . . . . . . . . 3-56
x Contents
Build Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11
Configure Simulation Parameters . . . . . . . . . . . . . . . . 4-16
Simulate Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17
Add Remaining Planets . . . . . . . . . . . . . . . . . . . . . . . . 4-18
Sensing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Sensing Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Variables You Can Sense . . . . . . . . . . . . . . . . . . . . . . 4-35
Blocks with Sensing Capability . . . . . . . . . . . . . . . . . . 4-35
Sensing Output Format . . . . . . . . . . . . . . . . . . . . . . . . 4-35
xi
Measuring Rotation . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-46
Axis-Angle Measurements . . . . . . . . . . . . . . . . . . . . . . 4-46
Quaternion Measurements . . . . . . . . . . . . . . . . . . . . . 4-47
Transform Measurements . . . . . . . . . . . . . . . . . . . . . . 4-49
xii Contents
Sense Total Forces . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-92
Simulation
5
Update and Simulate a Model . . . . . . . . . . . . . . . . . . . . . 5-2
xiii
Visualization and Animation
6
Simscape Multibody Visualization Utilities . . . . . . . . . . 6-2
Visualization Overview . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Solid Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Body and Multibody Visualization . . . . . . . . . . . . . . . . . 6-3
xiv Contents
Show and Hide Bodies and Multibody Subsystems . . . 6-23
Visualization Filtering . . . . . . . . . . . . . . . . . . . . . . . . . 6-23
Open Example Model . . . . . . . . . . . . . . . . . . . . . . . . . 6-24
Update Example Model . . . . . . . . . . . . . . . . . . . . . . . . 6-24
Hide Half-Cylinder Subsystem . . . . . . . . . . . . . . . . . . 6-25
Show Solid in Hidden Subsystem . . . . . . . . . . . . . . . . 6-26
Show Only Piston Subsystem . . . . . . . . . . . . . . . . . . . 6-27
Show Everything . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-28
CAD Import
xv
Translated Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
xvi Contents
Deployment
Code Generation
8
Code Generation Applications . . . . . . . . . . . . . . . . . . . . . 8-2
Code Generation Overview . . . . . . . . . . . . . . . . . . . . . . 8-2
Simulation Acceleration . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Model Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
xvii
Multibody Modeling
1
Spatial Relationships
Frames form the foundation of multibody modeling. These constructs encode the
relative position and orientation of one rigid body with respect to another. In Simscape
Multibody, every rigid body contains at least one frame.
Consider a double pendulum with two links. Each link has a set of physical properties
that affect its dynamic behavior and appearance—geometry, inertia, and color. Yet, none
of these properties contain information about the spatial arrangement of the links. To
position and orient one link with respect to another, you need frames.
You relate two rigid bodies in space by connecting two frames together. In the double
pendulum, you connect the end frame of one link to the end frame of another link using a
1-2
Working with Frames
joint. In turn, each link contains a local reference frame against which you define the two
end frames. You can make two frames coincident, translate them, or rotate them with
respect to each other.
Frames
Frames have one origin and three axes. The origin defines the local zero coordinate of
the frame. This is the point with respect to which you measure the translational distance
between two frames. The axes define the directions in which the components of a 3-D
vector are resolved. For example, if you measure the translation vector between two
frame origins, you can resolve the vector components along the axes of the base frame.
For more information, see “Measurement Frames” on page 4-59.
Frame Types
A multibody model generally contains two frame types: global and local. The global frame
represents the world. It is inertial and defines absolute rest in a model. In Simscape
Multibody, you represent the global frame with the World Frame block. This block is
available in the Frames and Transforms library. The World frame is uniquely defined in
every model. You can add multiple World Frame blocks to a model, but they all represent
the same frame.
A local frame represents a position and orientation in a rigid body. It can move with
respect to the World frame, but not with respect to the rigid body itself. Because it
can move with respect to the World frame, a local frame is generally non-inertial. To
add a local frame to a rigid body, you use the Rigid Transform block. You can add
multiple local frames to a rigid body—to define the position and orientation of joints, to
1-3
1 Spatial Relationships
apply an external force or torque, or to sense motion. For more information, see “Frame
Transformations” on page 1-17.
Frame Transforms
To separate two frames in space, you apply a frame transformation between them. In
Simscape Multibody, two frame transformations are possible: rotation and translation.
Rotation changes the relative orientation of two frames. Translation changes their
relative position.
Rigid transformations fix spatial relationships for all time. When you rigidly connect
two frames, they move as a single unit. They cannot move with respect to each other. In
Simscape Multibody, you apply a rigid transformation with the Rigid Transform block.
Note: Frame transformations are important in multibody models. The Rigid Transform
block is among the most commonly used in Simscape Multibody.
You can also relate to frames with a time-varying transformation. In this case, the
rotation, translation, or both, can vary as a function of time. One example is the
connection between two links in a double-pendulum. Two frames, one on each link,
connect with a joint that allows their spatial relationship to vary with time.
To add a time-varying transformation, you use joint blocks. These blocks allow frame
transformations to vary with time. The transformations can arise from model dynamics
and joint actuation inputs, the latter of which include force, torque, and motion variables.
1-4
Working with Frames
Frame Networks
Rigid body subsystems generally have multiple frames. For example, a binary link—
one with two connection points—contains two frames, each identifying a connection
point. More complex rigid bodies may have yet more frames. In fact, Simscape Multibody
imposes no limit on the number of frames a rigid body can have. You can add as many
frames as your application requires.
The set of frames that belong to a rigid body form a frame network. Like other networks,
it is often convenient to organize frames hierarchically. You can, for example, organize
the frames of a binary link such that its two joint frames are defined with respect to
the geometry center frame. In this simple example, the frame network contains two
hierarchical levels: a top level containing the geometry center frame, and a lower level
containing two joint frames. More complex rigid bodies generally have more hierarchical
levels.
The top hierarchical level contains the parent frame. Lower hierarchical levels contain
children frames. Children frames can in turn contain their own children frames. All
frames in a frame network depend, directly or indirectly, on the parent frame. This
dependence exists because the sequence of frame transformations used to define a frame
must ultimately reference the parent frame.
More About
• “Frame Transformations” on page 1-17
• “Representing Frames” on page 1-6
• “Motion Sensing” on page 4-41
1-5
1 Spatial Relationships
Representing Frames
In this section...
“Identity Relationships” on page 1-7
“Translation and Rotation” on page 1-8
“Interpreting a Frame Network” on page 1-8
You represent frames with frame ports, lines, and nodes. Each of these frame entities
represents one frame. You connect one frame entity to any other using a connection
line. When you do so, you apply a spatial relationship between the two frames. Spatial
relationships that you can specify include:
The figure illustrates these spatial relationships. Letters B and F represent the two
frames between which you apply a spatial relationship.
A frame port is any port with the frame icon . A frame line is any connection line that
joins two frame ports. A frame node is the junction point between two or more frame
lines. You can connect one frame entity only to another frame entity. Connecting frame
ports, lines, or nodes to other types of ports, lines, or nodes is invalid. For example, you
cannot connect a frame port to a physical signal port.
1-6
Representing Frames
Identity Relationships
To make two frames coincident in space, connect the corresponding frame entities with a
frame line. The frame line applies a rigid identity relationship between the two frames.
During simulation, the two frames can move only as a single unit. They cannot move
with respect to each other. The figure shows three ways to make two frames coincident.
Alternatively, use the Weld Joint block to make two frames coincident for all time.
The Weld Joint block fixes the relative positions and orientations of frames belonging to
different rigid bodies.
1-7
1 Spatial Relationships
Note: Ensure each joint frame port connects rigidly to a Solid or Inertia block. The
connection can be direct, through a connection line, or indirect, through one or more
Rigid Transform blocks. Joint frame ports not rigidly connected to components with
inertia (those containing at least one Solid or Inertia block) can cause a degenerate-mass
error during simulation.
You can apply an offset distance between two frame origins, a rotation angle between the
frame axes, or both. Two frames that you connect using a Rigid Transform block behave
as a single entity. If you specify neither translation or rotation, the Rigid Transform
block represents the identity relationship. The two frames become coincident in space.
In the figure, a Rigid Transform block applies a rigid transformation between two solid
reference frames.
1-8
Representing Frames
To represent the binary link, the Compound Body subsystem contains three Solid blocks.
The blocks represent the main, peg, and hole sections. Three frames provide the position
and orientation of the three solids according to the guidelines that section “Identity
Relationships” on page 1-7 introduces. Each group of frame ports, lines, and nodes
that directly connect to each other represents one frame. The figure shows the three
frames in the block diagram.
1-9
1 Spatial Relationships
Two Rigid Transform blocks represent the spatial relationships between the three
frames. One block translates the hole frame with respect to the reference frame along the
common -X axis. The other block translates the peg frame with respect to the reference
frame along the common +X axis. The figure shows these two blocks.
More About
• “Working with Frames” on page 1-2
• “Frame Transformations” on page 1-17
• “World and Reference Frames” on page 1-11
• “Find and Fix Frame Issues” on page 1-33
1-10
World and Reference Frames
Two preset frames are available in Simscape Multibody: World and Reference. These
are standalone frames with respect to which you can define other frames in a model.
New frames can in turn serve as the basis to define yet other frames. However, directly
or indirectly, all frames depend on either World or Reference frames. Both frames are
available as blocks in the Frames and Transforms library.
World Frame
The World frame represents the external environment of a mechanical system. It is
always at absolute rest, and therefore experiences zero acceleration. As a consequence,
centripetal and other pseudo-forces are not present in the world frame, and it is said
to be inertial. Rigidly connecting any frame to the World frame makes that frame also
inertial. To add the World frame to a model, use the World Frame block.
The World frame is the ultimate reference frame. Its position and orientation are
predefined and do not depend on any other frame. This property makes the World frame
1-11
1 Spatial Relationships
invaluable. You can always apply a transform to the World frame and obtain a new
frame. Applying a transform to the resulting frame in turn yields more new frames, all
indirectly related to the World frame. The result is a frame tree with the World frame at
the root. The figure shows such a frame tree for a double-pendulum system.
The double-pendulum block diagram is based on this frame tree. The World Frame
block identifies the root of the frame tree. A Revolute Joint block applies the variable
transform that relates the World frame to the binary link peg frame. A second Revolute
Joint block applies a similar variable transform between the hole and peg frames of
adjoining binary links. The figure shows this block diagram.
1-12
World and Reference Frames
The World frame is present in every model. However, the World Frame block is strictly
optional. If you do not add this block to a model, Simscape Multibody assigns one of the
existing frames as the World frame. This implicit World frame connects to the rest of the
model via an implicit 6-DOF joint, which in the absence of counteracting forces allows a
machine to fall under gravity.
You can connect multiple World Frame blocks to a model. However, all World Frame
blocks represent the same frame. In this sense, the World frame is unique. You can
add multiple World Frame blocks to simplify modeling tasks, e.g., sensing motion with
respect to the World frame. The figure shows the model of a double-pendulum with two
World Frame blocks. Both World Frame blocks represent the same frame.
1-13
1 Spatial Relationships
Reference Frame
The Reference frame represents the root of a rigid body or multibody subsystem. Within
a subsystem, it denotes the frame against which all remaining frames are defined. To
add a Reference frame, use the Reference Frame block. Use this block to mark the top
level of a subsystem frame tree.
Applying a transform to the Reference frame yields other frames. Applying transforms to
these other frames yields still more frames. The overall set of frames forms a frame tree
with the Reference frame at the root. The figure shows such a frame tree for one of the
binary links used in the double-pendulum system.
1-14
World and Reference Frames
The block diagram of the binary link subsystem is based on this frame tree. The following
figure shows the binary link block diagram. The Reference Frame block identifies
the root of the frame tree. Rigid Transform block to_hole adds the hole frame. Rigid
Transform block to_peg adds the peg frame. It is a simple task to add the main, peg, and
hole solids once these frames are defined.
1-15
1 Spatial Relationships
The distinguishing feature of the Reference frame is that it can move with respect to
other frames. Depending on the dynamics of a model, a Reference frame can accelerate,
giving rise to pseudo-forces that render this frame non-inertial. Rigidly connecting any
frame to a non-inertial Reference frame makes that frame also non-inertial.
The Reference frame is present in every subsystem. However, the Reference Frame block
is strictly optional. If you do not add this block to a subsystem, Simscape Multibody
assigns one of the existing frames as the Reference frame.
More About
• “Working with Frames” on page 1-2
• “Frame Transformations” on page 1-17
• “Representing Frames” on page 1-6
1-16
Frame Transformations
Frame Transformations
In this section...
“Rigid and Time-Varying Transformations” on page 1-17
“Rigid Transformation Example” on page 1-19
“Reversing Rigid Transformations” on page 1-22
To place a solid in space, with a given position and orientation, you use frames. By
connecting the solid reference frame to another frame, you resolve its position and
orientation within the model. For example, connecting the solid reference frame directly
to the World frame causes their origins and axes to coincide. However, if the model does
not yet contain the desired frame, you must first add it.
Adding a frame is the act of defining its position and orientation. Because these
properties are relative, you must always define a frame with respect to another frame.
Every model starts with one of two frame blocks you can use as reference: World Frame
or Reference Frame. As a model grows, so does the number of frames that you can use as
a reference.
1-17
1 Spatial Relationships
Frame transformations can also vary with time. In this case, the two frames that the
transformation applies to can move with respect to each other. In Simscape Multibody,
joint blocks provide the degrees of freedom that allow motion between two frames.
Depending on the joint block, frames can move along or about an axis. For example, the
Revolute Joint block allows two frames to rotate with respect to each other about a
common +Z axis. Likewise, the Prismatic Joint block allows two frames to rotate with
respect to each other along a common +Z axis. For more information about joints, see
“Modeling Joint Connections” on page 3-3.
You can apply two rigid transformations: rotation and translation. Rotation changes the
orientation of the follower frame with respect to the base frame. Translation changes
1-18
Frame Transformations
the position of the follower frame with respect to the base frame. A third, implicit,
transformation is available—identity. This transformation is marked by the absence
of both frame rotation and translation, making base and follower frames coincident in
space.
Every rigid transformation involves two frames: a base and a follower. The base frame
is a reference, the starting point against which you define the new frame. Any frame can
act as the base frame. When you apply a rigid transformation, you do so directly to the
base frame. The follower frame is the new frame — the transformed version of the base
frame. The Rigid Transform block identifies base and follower frames with frame ports B
and F, respectively.
1-19
1 Spatial Relationships
When modeling the binary link, the goal is to place the peg at one end of the link, and
the hole section at the other end. The proper approach is to apply a rigid transformation
between the main peg and peg reference frames, and main body and hole section
reference frames. The transformations specify the separation distance and rotation
angle, if any, between each pair of frames. Because the transformations are rigid, they
constrain the solids to move as a single unit — a rigid body. The rigidly connected solids
can move together with respect to the World frame, but never with respect to each other.
The figure shows the set of transformations used to model the binary link. These include
translation, rotation, and identity. No Rigid Transform block is required to apply an
identity transformation. See “Representing Frames” on page 1-6.
1-20
Frame Transformations
The block diagram, shown in the following figure, reflects the structure of the binary
link. Three Solid blocks represent the main body, peg, and hole sections. Their R ports
identify the respective reference frames. Two Rigid Transform blocks, named to_hole and
to_peg apply the rigid transformations that relate the solid pairs main–hole and main–
peg.
1-21
1 Spatial Relationships
Consider the binary link system. In the original configuration, rigid transformations
translate the peg to the right of the main body and the hole to the left. To accomplish
this, the main body frame connects to the base port frame of the corresponding Rigid
Transform blocks, while the hole and peg frames connect to the follower port frames.
When you switch base and follower frame ports, the transformations instead translate
the main body to the right of the peg and to the left of the hole.
1-22
Frame Transformations
While in the first case the peg translated to the right of the main body, in the second case
the peg translated to the left. The same principle applies to the hole. The figure shows
the effect of switching base and follower frames in both Rigid Transform blocks of the
binary link block diagram.
1-23
1 Spatial Relationships
1-24
Rotation Methods
Rotation Methods
In this section...
“Specifying Rotation” on page 1-25
“Aligned Axes” on page 1-25
“Standard Axis” on page 1-26
“Arbitrary Axis” on page 1-27
You can specify frame rotation using different methods. These include aligned axes,
standard axis, and arbitrary axis. The different methods are available through the Rigid
Transform block. The choice of method depends on the model. Select the method that is
most convenient for the application.
Specifying Rotation
Rotation is a relative quantity. The rotation of one frame is meaningful only with respect
to another frame. As such, the Rigid Transform block requires two frames to specify a
transformation: base and follower. The transformation operates on the base frame. For
example, a translation along the +Z axis places the follower frame along the +Z axis from
the base frame. Reversing frame ports is allowed, but the transformation is reversed: the
base frame is now placed along the +Z axis from the follower frame.
Aligned Axes
Rotate two frames with respect to each other by aligning any two axes of one with any
two axes of the other. The figure illustrates the aligned axes method.
1-25
1 Spatial Relationships
Standard Axis
Rotate frames with respect to each other about one of the three base frame axes: X, Y, or
Z.
1-26
Rotation Methods
Arbitrary Axis
Rotate two frames with respect to each other about an arbitrary axis resolved in the base
frame.
1-27
1 Spatial Relationships
1-28
Translation Methods
Translation Methods
In this section...
“Specifying Translation” on page 1-29
“Cartesian” on page 1-29
“Standard Axis” on page 1-30
“Cylindrical” on page 1-31
You can specify frame translation using different methods. These include Cartesian,
standard axis, and cylindrical. The different methods are available through the Rigid
Transform block. The choice of method depends on the model. Select the method that is
most convenient for the application.
Specifying Translation
Translation is a relative quantity. The translation of one frame is meaningful only with
respect to another frame. As such, the Rigid Transform block requires two frames to
specify a translation: base and follower. The transformation operates on the base frame.
For example, a translation along the +Z axis places the follower frame along the +Z
axis from the base frame. Reversing frame ports is allowed, but the transformation is
reversed: the base frame is now placed along the +Z axis from the follower frame.
Cartesian
Translate follower frame along arbitrary Cartesian vector resolved in the base frame.
1-29
1 Spatial Relationships
Standard Axis
Translate follower frame along one of the three axes of the base frame.
1-30
Translation Methods
Cylindrical
Translate follower frame along cylindrical axes resolved in the base frame.
1-31
1 Spatial Relationships
1-32
Find and Fix Frame Issues
If your model contains an invalid frame connection, Simscape Multibody issues an error
and the model does not simulate. Possible error sources include:
Rigidity Loops
A rigidity loop is a closed loop of Rigid Transform blocks. The loop contains one
redundant Rigid Transform block that over-constrains the subsystem. If a rigidity loop
is present, Simscape Multibody issues an error and the model does not simulate.
To remove the simulation error, disconnect one Rigid Transform block. This step
removes the redundant constraint, and allows the model to simulate. The following figure
shows a rigidity loop. The loop contains four Rigid Transform blocks directly connected to
each other.
1-33
1 Spatial Relationships
More About
• “Representing Frames” on page 1-6
• “Frame Transformations” on page 1-17
1-34
2
Rigid Bodies
2-2
Creating Body Subsystems
2-3
2 Rigid Bodies
In this section...
“Rigid Body Essentials” on page 2-4
“Rigid Body Properties” on page 2-5
“Rigid Body Frames” on page 2-6
“Rigid Body Delimitation” on page 2-7
“Simple and Compound Rigid Bodies” on page 2-9
In a Simscape Multibody model, all bodies are rigid. They are idealizations in
which internal strains always equal zero. True rigid bodies do not exist in nature
but, under normal operating conditions, many engineered components behave as
approximately rigid bodies—that is, with negligible deformation. In general, the
rigid-body approximation provides accurate modeling results whenever the expected
deformation is much smaller than the characteristic length of the modeled system.
2-4
Simscape Multibody Bodies
To specify the solid properties of a rigid body, you use the blocks in the Body Elements
library. The library contains three blocks, of which Solid is the most frequently used.
This block enables you to specify all the solid properties of a rigid body in a single place.
The remaining blocks, Inertia and Graphic, serve special cases, such as visualizing
certain frames and modeling mass disturbances.
The table summarizes the primary purposes of the Body Elements blocks.
Block Purpose
Solid Specify the solid properties—geometry,
inertia, graphic—of a simple rigid body or
of part of a compound rigid body.
Inertia Specify the inertial properties of a mass
element, such as a mass disturbance
present in rigid bodies.
Graphic Select a graphical icon to visualize any
Simscape Multibody frame in a model.
2-5
2 Rigid Bodies
• Connect joints and constraints between rigid bodies. For example, you always connect
a revolute joint between two frames in separate rigid bodies (or, alternatively,
between a rigid body frame and the world frame).
• Apply forces and torques to or between rigid bodies. For example, you always apply an
external force and torque to a single frame in a rigid body.
• Sense motion, forces, and torques between rigid bodies. For example, you always
sense the relative position coordinates between two frames on different rigid bodies
(or, alternatively, between a rigid body frame and the world frame).
The Solid block, the main component of any body subsystem, provides a reference frame
through frame port R. You can create additional frames in the Solid block dialog box
using its frame-creation interface. This interface is accessible from the Frames area of
the Solid block dialog box. The Solid block adds a frame port for every frame that you
create.
Drawing a frame connection line between frame ports on different Solid blocks makes
the port frames coincident in space. You can translate and rotate these frames relative to
each other by adding a Rigid Transform block to the connection line. This block enables
you to specify the pose of the follower frame relative to the base frame.
The figure shows an example of a rigid body subsystem in Mechanics Explorer. The rigid
body is a binary link with three frames, each associated with a solid section of the link—
hole, main, and peg. Rigid transforms specify the translational offset between each pair
of frames.
2-6
Simscape Multibody Bodies
In the binary-link block diagram, Rigid Transform blocks specify the translation
transforms between the three frames. A total of two such blocks are needed, one between
each pair of frames. The following figure shows the binary link block diagram. To view
this subsystem, at the MATLAB command prompt, enter smdoc_binary_link_a.
If you connect two halves of a rigid body using a Weld Joint block, the Simscape
Multibody model treats the two halves as rigidly connected but independent rigid bodies.
Any Gravitational Field blocks in your model then exert a gravitational force at the
2-7
2 Rigid Bodies
center of mass of each half. This strategy enables you to account for gravitational torques
acting on a rigid component, such as an asteroid orbiting the Sun.
The figure shows a simple-pendulum model. In this model, a subsystem block neatly
encapsulates each rigid body. The model contains two rigid bodies: a pivot mount and a
binary link. A joint block separates the mount and the link.
The following figure shows the same model without subsystem blocks. The model treats
the blocks on either side of the Revolute Joint block as separate rigid bodies. The blocks
to the left of the joint block represent the pivot mount, while the blocks to the right of the
joint block represent the binary link.
If you connect a Weld Joint block between the Main and Rigid Transform1 blocks, the
Simscape Multibody model recognizes three rigid bodies:
2-8
Simscape Multibody Bodies
The following figure shows the modified model with the Weld Joint block. The
Mechanism Configuration, World Frame, and Solver Configuration blocks are omitted to
conserve space.
Consider a binary link, the basic component of mechanical linkages such as the double
pendulum and the four-bar mechanism. Depending on the level of detail you want to
incorporate in your model, you can treat the binary link as a simple rigid body or as a
compound rigid body:
2-9
2 Rigid Bodies
Solid Geometries
In this section...
“Geometry Essentials” on page 2-10
“Compound Shapes” on page 2-10
“Basic Shapes” on page 2-11
“General Extrusion and Revolution Shapes” on page 2-12
“Imported Shapes” on page 2-13
Geometry Essentials
Geometry is one of three solid properties that you can specify in a Simscape Multibody
model. This property includes the shape of a rigid body and its size. For example, the
geometry of Earth consists of a spherical shape and an approximate radius of 6,370 km.
Specifying these parameters enables Simscape Multibody to perform two tasks:
• Set the visual appearance of a rigid body, excluding color and lighting, in Mechanics
Explorer.
• Automatically calculate the inertial properties of a rigid body, including the center of
mass, the moments of inertia, and the products of inertia.
You specify solid geometry using the Solid block. Solid shapes that you can specify range
from basic, such as a cylinder, to more sophisticated, such as a general extrusion. For
intricate shapes, you can also load solid geometry from external files. The following
figure shows examples of the different types of shapes.
Compound Shapes
Solid shapes are versatile but, used individually, limited. To make the most of solid
shapes, you must combine them using multiple Solid blocks. This approach yields a
2-10
Solid Geometries
compound rigid body with an aggregate shape that can be more complex than a single
solid shape would allow. The binary link shown in the following figure is one example.
In the figure, three Solid blocks provide the geometries of the binary-link sections
—the main body and the two ends. Two Rigid Transform blocks provide the spatial
relationships between the three binary-link sections, including their relative positions
and orientations.
Basic Shapes
Often, you can model a rigid body using basic shapes. These are common, simple shapes,
such as sphere and cylinder, with parameterizations based on dimensions such as radius
and length. Such shapes enable you to quickly model a rigid body approximately—e.g.,
for quick, proof-of-concept models. The table lists the basic shapes that you can model
using the Solid block.
Brick • Length
• Width
• Thickness
Ellipsoid • Ellipsoid radii along
semi-principal axes
2-11
2 Rigid Bodies
As an example, you can model a binary link using a brick shape. By using this
approximation, you can quickly move on to more important aspects of the modeling
workflow, such as multibody assembly. Once you have a working model, you can add
detail to the rigid bodies, e.g., by treating the binary links as compound rigid bodies with
more complex shapes.
For a tutorial showing how to model a binary link using a brick approximation, see
“Model Simple Link”.
For tutorials showing how to model general-extrusion and revolution shapes, see:
2-12
Solid Geometries
Imported Shapes
Instead of modeling a complex geometry manually, you can import it using one of two
file formats: STL and STEP. Files in these formats specify the surface geometries of 3-
D solids, albeit using different approaches. The table summarizes the key differences
between the two formats.
Note that these files do not specify graphic or inertial properties. You must specify those
properties separately. To generate the STL or STEP files, you must use an external
application, such as a CAD tool.
2-13
2 Rigid Bodies
Visualization Essentials
Visualization is an integral part of the Simscape Multibody modeling workflow. You
can render a model graphically and examine its bodies and their interconnections—
for example, to ensure that solid geometries, colors, and spatial relationships are what
you expect. To visualize bodies and the solids that comprise them, you use one of the
following:
• Solid block visualization pane — Visualize individual solids and their reference
port frames. Use the Solid block visualization pane to examine solid geometries and
colors without having to update or simulate the block diagram, a Mechanics Explorer
requirement.
• Mechanics Explorer — Visualize multibody systems, the bodies that comprise the
systems, and the solids that comprise the bodies. Use Mechanics Explorer if you
must visualize more than one solid at a time, or if the spatial relationships between
different frames are important to you.
Solid Visualization
To visualize individual solids—for example, the binary link main section shown in the
“Model Link” on page 2-75 tutorial—you use the embedded visualization pane in the
Solid block dialog box. This pane enables you to change Solid block parameters and
examine their effect on solid geometry and color near instantly without having to open a
separate window. Above the pane, the Solid block includes a visualization toolstrip that
you can use to:
2-14
Solid and Body Visualization
• Toggle visualization on and off for the solid reference port frame. The position of the
frame varies for shapes such as General Extrusion and Revolution, making
frame visualization useful when deciding how to connect your solid in a model.
You do not need to update or simulate the block diagram—which means that you can
visualize a solid before the block diagram is complete. For example, you can visualize
a solid before connecting a Simscape Solver Configuration block to the Simscape
Multibody portion of the physical network. You can also visualize a solid before
connecting the Solid block to any other blocks on the model canvas.
You can visualize a solid even if you parameterize its properties in terms of MATLAB
variables—for example, entering a variable T in the Length parameter of a General
Extrusion shape. However, you must assign numerical values to your MATLAB
variables before the Solid block can render your solid. You can do this in a Simulink®
Subsystem mask, or in the model workspace through Model Explorer. For examples, see:
2-15
2 Rigid Bodies
Each time you change a Solid block parameter, you must select the Update Visualization
button —or press F5—in order to refresh the solid view in the visualization pane.
The Update Visualization button does not apply your changes to the model, giving you a
chance to verify them before you commit to them. To apply you parameter changes to the
model, you must select Apply.
Body Visualization
To visualize a body containing multiple solids—for example, the complete binary link
shown in the “Model Link” on page 2-75 tutorial—you use Mechanics Explorer. This
visualization utility displays the entire contents of your model, enabling you to examine
not only solid geometries and colors, but also how solids connect in compound bodies and
how bodies connect in multibody systems.
Mechanics Explorer provides its own visualization toolstrip—similar to, but more
expansive than, the Solid block visualization toolstrip. You can use the toolstrip to:
2-16
Solid and Body Visualization
To visualize a body or multibody system in Mechanics Explorer, you must update the
block diagram (Simulation > Update Diagram) or start simulation (Simulation >
Run). As a result, you must also ensure that your block diagram is valid. In particular,
you must connect a Simscape Solver Configuration block to the Simscape Multibody
portion of the model.
2-17
2 Rigid Bodies
Coordinate Matrices
Coordinate matrices are M × 2 in size. Each row corresponds to a point on the cross-
section outline and each column corresponds to a coordinate on the cross-section plane. If
you specify a cross-section shape using ten points, the resulting coordinate matrix is 10 ×
2 in size.
The cross-section plane differs between General Extrusion and Revolution shapes.
That plane is the XY plane for general extrusion shapes and the XZ plane for revolution
shapes. Cross-section coordinates are therefore [X, Y] pairs for general extrusion shapes
and [X, Z] pairs for revolution shapes.
The Solid block generates the cross-section shape from your coordinate matrix by
connecting each point to the next with a straight line. If the last point is different from
the first point, the block connects the two in order to close the cross-section outline.
2-18
Revolution and General Extrusion Shapes
The cross-section outline divides the solid region of your shape from the empty region
outside of it. To decide where the solid region is, the Solid block uses a special rule:
looking from one point to the next, the solid region must lie to the left of the connecting
line. The figure shows the application of this rule to an I-beam cross-section shape.
However, the path must now traverse not only the outer outline of the cross-section, but
also the outline of its hollow region. To do this, the path must cut across the solid portion
of the cross section. The figure shows such a cut.
outerCS = ÈÎ X 1 , Y1 ; X 2 , Y2 ; X 3 , Y3 ; X 4 , Y4 ; X 1 , Y1 ˘˚ .
2-19
2 Rigid Bodies
innerCS = ÈÎ X 6 , Y6 ; X 7 Y7 ; X 8 , Y8 ; X 9 , Y9 ; X 6 , Y6 ˘˚ .
CS = [ outerCS; innerCS] .
Note that outerCS traces the outer profile counterclockwise, while innerCS traces the
inner profile clockwise. You must reverse the order of the coordinates as you transition
between the two outlines in order to keep the solid region to the left of the cross-section
line.
Note also that, taken individually, outerCS and innerCS each trace a closed outline.
You must close each outline by ending its coordinate matrix on the first coordinate pair
for that outline. The Solid block automatically closes the overall cross-section profile by
connecting the last coordinate pair to the first. In doing so, the Solid block traces the first
cut at the same location and in reverse, ensuring that the cut thickness is zero.
• For a general extrusion of thickness L, the block sweeps the cross-section outline by
L/2 along the positive and negative directions of the Z axis.
• For a revolution with a sweep angle of θ, the block sweeps the cross-section outline by
θ/2 about the positive and negative directions of the Z axis.
2-20
Revolution and General Extrusion Shapes
The reference port frame of revolution and general extrusion solids has its origin at the
[0, 0] coordinate. This coordinate lies in the cross-section plane for a general extrusion
solid and in the revolution axis for a revolution solid.
2-21
2 Rigid Bodies
Solid Inertia
In this section...
“Inertial Properties” on page 2-22
“Blocks with Inertia” on page 2-22
“Inertia in a Model” on page 2-23
“Inertia Parameterizations” on page 2-24
“Custom Inertia” on page 2-24
“Moments and Products of Inertia” on page 2-25
“Complex Inertias” on page 2-27
Inertial Properties
Inertia is the resistance of matter to acceleration due to applied forces and torques.
The inertial properties of a body include its mass and inertia tensor—a symmetric 3×3
matrix that contains the moments and products of inertia. Mass resists translational
acceleration while the moments and products of inertia resist rotational acceleration.
Among the solid properties of a model, the inertial properties have the greatest impact on
multibody dynamics. Those that you must specify depend on the type of inertia you are
modeling—a point mass or a body with a 3-D mass distribution. They include one or more
of the following:
• Mass or density
• Center of mass
• Moments of inertia
• Products of inertia
In a Simscape Multibody model, these properties are time-invariant. Rigid bodies cannot
gain or lose mass nor can they deform in response to an applied force or torque. The
mass distribution of a body—and therefore its inertia tensor and center of mass—remain
constant throughout simulation.
2-22
Solid Inertia
• Solid — Model a complete solid element with geometry, inertia, and color. This block
can automatically compute the moments of inertia, products of inertia, and center
of mass based on the solid geometry and mass or mass density. During simulation,
Mechanics Explorer renders the solid using the geometry and color specified.
• Inertia — Model only the inertial properties of a solid element. You must specify
the moments of inertia, products of inertia, and center of mass explicitly. During
simulation, Mechanics Explorer identifies the center of mass using the inertia icon
Inertia in a Model
To add a Solid or Inertia block to your model, connect its frame port to another frame
entity in the model. Frame entities include frame lines, nodes, and ports. The frame
entity to which you connect the block determines the position and orientation of the
inertia within the model. See “Representing Frames” on page 1-6.
The Solid and Inertia blocks each provide a reference frame port. The Solid block enables
you to create additional frames, each of which adds a new frame port to the block. You
can use any of these frames to connect a Solid block in a model.
The figure shows an example. The model shown contains two Solid blocks, labeled Link
A and Link B. The reference frame port of Link A connects directly to the World Frame
block. Its reference frame is therefore coincident with the World frame.
The reference frame port of Link B connects to the follower frame port of the Rigid
Transform block. This block applies a spatial transform between the World frame the
reference frame of the Link B block. The spatial transform translates and/or rotates the
two frames relative to each other.
2-23
2 Rigid Bodies
Inertia Parameterizations
Once you have connected the Solid or Inertia blocks in a model, you must specify their
inertial parameters. These depend on the inertia parameterization that you select. The
blocks provide three optional parameterizations:
Custom Inertia
If you select the Custom Inertia parameterization, you must specify the moments
of inertia, products of inertia, and center of mass explicitly. These parameters depend
2-24
Solid Inertia
closely on the reference frame used in their calculations, so you must ensure that frame
matches the one used in Simscape Multibody:
• Moments and products of inertia — Enter with respect to a frame parallel to the
reference port frame but with origin at the center of mass.
• Center of mass — Enter with respect to the reference port frame.
Consider the main section of the binary link in “Model Link” on page 2-75. You model
this solid using a single solid block with a General Extrusion shape. As described in
the Solid block documentation, the reference port frame for a general extrusion has its
origin in the XY plane at the [0,0] cross-section coordinate.
The figure shows the solid reference port frame, labeled R. The center-of-mass
coordinates must be with respect to this frame. The moments and products of inertia
must be with respect to a parallel frame offset so that its origin coincides with the center
of mass. This frame is virtual , as it does not correspond to any frame port, line, or node
in the model. It is labeled R* in the figure.
• I xy = I yx
• I yz = I zy
• I zx = I xz
This symmetry reduces the number of unique tensor elements to six—three moments of
inertia and three products of inertia. The complete inertia tensor has the form:
ÈI I xy I zx ˘
Í xx ˙
Í I xy I yy I yz ˙
Í ˙
Í I zx I yz I zz ˙
Î ˚
2-25
2 Rigid Bodies
ÈI ˘
Í xx ˙
Í I yy ˙
Í ˙
ÍÎ I zz ˙˚
•
Ú(y )
2
I xx = + z 2 dm
V
•
Ú (z )
2
I yy = + x 2 dm
V
•
Ú (x )
2
I zz = + y2 dm
V
The products of inertia are the unique off-diagonal elements, each of which appears in
the inertia tensor twice:
È I xy I zx ˘
Í ˙
Í I xy I yz ˙
Í ˙
Í I zx I yz ˙
Î ˚
•
I yz = - yz dmÚ
V
•
I zx = - zx dmÚ
V
•
I xy = - xy dmÚ
V
2-26
Solid Inertia
The inertia tensor is simplest when it is diagonal. Such a tensor provides the moments of
inertia about the principal axes of the solid or inertia element—known as the principal
moments of inertia. The products of inertia reduce to zero:
ÈI 0 0 ˘
Í xx ˙
Í 0 I yy 0 ˙
Í ˙
ÍÎ 0 0 I zz ˙˚
For more information, see the Solid and Inertia block reference pages.
Complex Inertias
Bodies often comprise different materials, have complex shapes, or contain material
imperfections that alter their centers of mass and principal axes. One example is an
imbalanced automobile wheel after driving through a pothole. You can model complex
inertias such as these using two approaches:
• Use a divide-and-conquer approach. Break up the complex solid or inertia into simpler
chunks and model each using a separate Solid or Inertia block. The resulting set of
Solid and Inertia blocks constitute a compound inertia. You use a similar approach to
model complex geometries, such as the binary link geometry in “Model Link” on page
2-75.
• Manually specify the complete inertial properties using a single Solid or Inertia block
with the inertia parameterization set to Custom. You must obtain the moments
of inertia, products of inertia, and center of mass through direct calculation, from
another modeling platform, or from another external source.
For bodies with complex shapes but uniform mass distributions, you can also import
a STEP file containing the solid geometry and set the inertia parameterization to
Calculate from Geometry.
2-27
2 Rigid Bodies
Custom Inertia
You can specify the inertia tensor and center of mass of a solid explicitly. To do this,
in the Solid or Inertia block, you set the inertia parameterization to Custom. This
option exposes additional fields so that you can enter the moments of inertia, products of
inertia, and center of mass.
Before entering the inertia parameters, you must ensure that they are defined with
respect to the correct frame. This frame typically coincides with the reference port
frame for standard shapes such as Sphere, Brick, and Cylinder, but not for the more
advanced Revolution and General Extrusion shapes or imported shapes.
This tutorial shows how you can specify the inertial parameters of a solid explicitly,
clarifying along the way the frames that the moments of inertia, products of inertia, and
center of mass must refer to.
Model Overview
The model in this tutorial is simple. It contains a single Solid block through which you
specify the inertial parameters of your solid. This block connects to the World frame
through a Revolute Joint block, providing it one rotational degree of freedom. You
examine the effect of the inertial parameters by simulating the angular motion in the
model.
The solid that you model has a brick shape. To illustrate the challenges associated with
the Custom Inertia parameterization, the tutorial represents the brick shape as a
2-28
Specify Custom Inertia
general extrusion. The result is a brick shape with the reference port frame origin located
at the [0,0] cross–section coordinates—which in this tutorial do not coincide with the
solid center of mass.
The figure shows the cross section of the general extrusion and its coordinates. The
[0,0] coordinates, and therefore the reference port frame origin, coincide with the upper
left vertex in the cross section. Variables Lx, Ly, and Lz refer to the length, width, and
thickness of the solid, respectively. Their values are:
• Lx = 20 cm
• Ly = 1 cm
• Lz = 1 cm
You specify the center of mass, but not the moments or products of inertia, with respect
to the reference port frame. To specify the moments and products of inertia, you must
use a different frame—one whose axes are parallel to the reference port frame axes but
whose origin is coincident with the solid center of mass.
The figure shows the extruded solid, its reference port frame (R), and the parallel frame
with origin at the center of mass (R*). This frame does not correspond to any frame entity
in the model. It is said to be virtual.
Inertia Parameters
To fully specify the inertia of a solid, you must specify four parameters:
2-29
2 Rigid Bodies
• Mass
• Center of mass
• Moments of inertia
• Products of inertia
The mass of the solid is the product of its density and volume. For an aluminum
solid, the density is r = 2 .7 g . The volume is the product of the side lengths
cm 3
M = r V = 54 g.
Assuming the mass distribution is uniform, the center of mass must coincide with the
center of geometry, which in frame R has the coordinates:
È Lx Ly ˘
CM = Í ,- , 0 ˙ = [10, - 0.5, 0 ] cm.
Î 2 2 ˚
The axes of frame R* align with the principal axes of the solid. Taken with respect to this
frame, the moments of inertia are:
• M
I xx =
12
( )
Ly 2 + Lz 2 = 9 g cm 2
• M
I yy =
12
( )
Lz 2 + Lx2 = 1804 .5 g cm 2
• M
I zz =
12
( )
Lx 2 + Ly 2 = 1804 .5 g cm 2
The axes of frame R* are the solid principal axes. The products of inertia are therefore
zero:
• I yz = 0
• I zx = 0
2-30
Specify Custom Inertia
• I xy = 0
Build Model
1 At the MATLAB command prompt, enter smnew. Simscape Multibody opens a new
model with some commonly used blocks. The Simscape Multibody library also opens
up.
2 From the Joints library, drag a Revolute Joint block.
3 Connect the blocks as shown in the figure. You can remove any unused blocks.
4 In the Mechanism Configuration block, set Gravity to [0 -9.81 0]. The new
gravity vector is perpendicular to the revolute joint axis, ensuring that the solid you
modeled oscillates due to gravity when displaced from its equilibrium position.
Specify Inertia
1 In the Solid block dialog box, under Geometry, specify the following parameters.
These parameters define the shape and size of the solid.
2-31
2 Rigid Bodies
• View > Layout > Four Standard Views. This option splits the visualization
window into four panes, each with a different view.
• View > Show Frames. This option exposes all the frames in the model.
• View > Show COMs. This option exposes the center of mass for each rigid body
in the model.
2-32
Specify Custom Inertia
5 Examine the solid reference frame and center of mass. Verify that the center of mass
appears at the geometric center of the solid and that the solid reference frame origin
coincides with the upper left corner of the solid cross section.
2-33
2 Rigid Bodies
Run Simulation
Simulate the model—for example, by selecting Simulation > Run. Mechanics Explorer
plays an animation of the model. To ensure that the gravity vector aligns vertically on
your screen, in the Mechanics Explorer toolstrip, set View Convention to Y up (XY
Front).
Double-click the Scope block and examine the oscillation period of the solid. The figure
shows the resulting plot.
2-34
Specify Custom Inertia
Try changing the inertia parameterization in the Solid block to Calculate from
Geometry and simulate the model once again. Compare the plot from the second
simulation to the first. The results are identical.
2-35
2 Rigid Bodies
Solid Frames
By default, the Solid block provides only a reference frame port, labeled R. In simple
shapes, such as bricks, cylinders, and spheres, the reference frame origin coincides with
the solid center of mass. In more complex shapes, such as extrusions and revolutions, the
reference frame can be anywhere relative to the solid.
An alternative approach, and one that is often more intuitive, is to create new frames
directly in the Solid block dialog box using the frame-creation interface. This interface
enables you to define new frames interactively by aligning the frame origin and axes with
geometric features such as planes, lines, and points.
In this example, you create a new frame in a solid using the frame-creation interface.
The solid shape is a general extrusion with three unequal sides. This shape helps to
demonstrate the difference between the primary and secondary frame axes that you
specify in the frame creation interface.
The figure shows the solid shape, its default reference frame (R), and the new frame that
you create (ECF).
2-36
Interactively Create Solid Frames
Frame-Creation Interface
The frame-creation interface is accessible through the Solid block dialog box. To open the
interface, in the Frames expandable area, select the Create button . If you change
any of the block parameters, you must first update the solid visualization by selecting the
You can define frames based on geometric features of the solid or a choice of two frames
—reference and principal inertia frames. The reference frame is the default frame of the
solid. The principal inertia frame is one whose origin coincides with the center of mass
and whose axes coincide with the principal axes of the solid.
Frames that you define by geometric features are specific to the shapes the features
belong to. If you make the frame origin coincident with the vertex of a brick, the new
frame is valid only for that particular brick shape. If you change shapes, you must edit or
delete the new frame, as the geometric features it depends on no longer exist.
The frame-creation interface has three sections for specifying the following:
• Frame origin
• Primary axis
• Secondary axis
The primary axis constrains the possible directions of the remaining two axes. These
axes must lie in the normal plane of the primary axis. If the axis or geometric feature
2-37
2 Rigid Bodies
used to define the secondary axis does not lie on this plane, the secondary axis is the
projection of that axis or feature onto the normal plane.
The figure shows a top view of the three-sided extrusion you model in this tutorial. You
align the primary axis (z) with the surface normal vector nz and the secondary axis (x)
with the line vector nx. Because nx is not normal to the primary axis, the secondary axis
is the projection of nx onto the normal plane of the primary axis.
Parameter Value
Geometry > Shape General Extrusion
Geometry > Cross-section [0,0;1,0;1,0.5]
3
In the visualization toolstrip, select the Update Visualization button . The
visualization pane updates with the three-sided extrusion that you specified.
4 Select the Toggle Frames button. The visualization pane shows all the frames
in the solid. At this point, the solid has a single frame—its reference frame. The
reference frame origin coincides with the [0,0] cross-section coordinate in the
midplane of the extrusion.
2-38
Interactively Create Solid Frames
2-39
2 Rigid Bodies
In the Frame Name parameter, enter ECF (short for Extrusion Corner Frame). The
frame name identifies the new frame in the Solid block visualization pane. It also
appears as the frame port label on the Solid block.
2-40
Interactively Create Solid Frames
Experiment with other frame origin locations. Define the origin location using one of the
extrusion vertices.
1 Under Frame Origin, select Based on Geometric Feature. This option enables
you to select a point or the center of a plane or line as the frame origin.
2 In the visualization pane, select the vertex shown in the figure. The vertex is in the
top plane of the extrusion. Ensure the view point is set to Isometric. In the Frame
Origin area, ensure the vertex is named Location of top point 3.
3 Under Frame Origin, select the Use Selected Feature button. The visualization
pane updates with the frame origin at the selected corner.
2-41
2 Rigid Bodies
1 In the Frame Axes area under Primary Axis, select Based on Geometric
Feature. The direction you specify in the next steps is that of the default primary
axis, +Z.
2 In the visualization pane, rotate the solid and select the surface shown. The
visualization pane highlights the surface and shows its normal vector. In the Frame
Axes area under Primary Axis, ensure the surface is named Surface normal of
side surface 3.
3 In the Frame Axes area under Primary Axis, select the Use Selected Feature
button. The visualization pane updates with the z axis of the ECF frame, shown in
dark blue, parallel to the normal vector of the selected surface.
2-42
Interactively Create Solid Frames
1 In the Frame Axes area, set the Secondary Axis parameter to -X. The direction
you specify in the following steps is that of the -X axis.
2 In the Frame Axes area, under Secondary Axis, select Based on Geometric
Feature.
3 In the visualization pane, rotate the solid and select the line shown. In the Frame
Axes area, under Secondary Axis, ensure this line is named Curve direction
of top curve 1.
2-43
2 Rigid Bodies
4 Select the Use Selected Feature button. The visualization pane updates wit the x
axis of the frame, shown in red, partially aligned with the selected line.
The two are not completely aligned as the selected line does not lie on the normal
plane of the primary axis. The secondary axis is therefore the projection of the
selected line onto the normal plane of the primary axis.
1 Select the Save button. The visualization pane shows the solid with the final version
of the frame you defined.
2-44
Interactively Create Solid Frames
2 In the main interface of the Solid block dialog box, select OK or Apply. The Solid
block commits the new frame to the model and exposes a new frame port labeled
with the frame name you specified.
2-45
2 Rigid Bodies
Solid Color
In this section...
“Basic Graphic Parameters” on page 2-47
“Advanced Graphic Parameters” on page 2-48
To make the most of the visualization capability of Mechanics Explorer, the Solid block
provides two parameterizations that you can use to specify the graphic appearance of
a solid: Simple and Advanced. The two parameterizations accept material color and
opacity parameters as input. Light source parameters are fixed for all models. The table
provides a comparison of the input parameters present in each graphic parameterization.
As an example, the figure shows two identical elliptical extrusions, one based on Simple
and the other on Advanced graphic parameterizations. In both cases, the extrusion is
completely opaque with a gray diffuse color. The advanced version adds to the solid a set
of blue highlights, through the use of specular color, and a red ambient hue, through the
use of ambient color.
2-46
Solid Color
The material colors — diffuse, ambient, specular, and emissive — form the core of the
graphical representation of a solid in Simscape Multibody. You can specify the material
colors in terms of RGB or RGBA color vectors.
Diffuse Color
Apparent color of a rough solid surface exposed to direct white light. Diffuse light
scatters equally in all directions according to Lambert’s law, causing the intensity
and color of the scattered light to appear the same from all angles. The diffuse color
normally provides the dominant contribution to the color of a solid surface. In most
cases, you can think of the diffuse color as the “true color” of a solid surface.
The figure shows the effect of varying the diffuse color of a solid. The array of spheres
have identical graphical properties, with the exception of Diffuse Color. The RGBA
2-47
2 Rigid Bodies
color vector of the diffuse color progresses from [1 1 1], at the left corner, to [0.85 0.45
0], at the right corner. A gray ambient color gives the solid a darker appearance.
Opacity
The opacity is the degree to which a solid blocks light from passing through. A
completely opaque solid blocks all light penetration through the solid. The opposite
of a completely opaque solid is a transparent solid, which allows all light to pass
through. You can reduce the opacity of a solid in order to improve the visibility of
other solids otherwise blocked from view.
The figure shows the effect of varying the opacity of a solid. The array of spheres
have identical graphical properties, with the exception of Opacity. The opacity value
progresses from 0.1, at the left corner, to 1, at the right corner. An opacity value
of 0 represents a completely transparent, or invisible, solid. An opacity value of 1
represents a completely opaque solid.
2-48
Solid Color
Specular Color
The specular color is the apparent color of the glossy highlights arising from a solid
surface exposed to direct light. The size of the specular highlights depends on the
value of the Shininess parameter. The intensity of the specular color is not uniform
in space, and has a strong dependence on the viewing angle. Changing the specular
color changes only the color of the specular highlights. For most applications, the [R
G B A] vector [0.5 0.5 0.5 1] works well.
The figure shows the effect of varying the specular color of a solid. The array of
spheres have identical graphical properties, with the exception of Specular Color.
The RGBA color vector of the specular color progresses from [1 1 1 1], at the left
corner, to [1 0 0 1], at the right corner. A gray ambient color gives the solid a darker
appearance.
Ambient Color
The ambient color is the apparent color of a solid surface exposed only to indirect
light. Changing the ambient color changes the overall color of the entire solid surface.
For most applications, the RGBA vector [0.15 0.15 0.15 1] works well.
The figure shows the effect of varying the ambient color of a solid. The array of
spheres have identical graphical properties, with the exception of the Ambient
Color. The RGBA color vector of the ambient color progresses from [1 1 1 1], at the
left corner, to [1 0 0 1], at the right corner. A gray ambient color gives the solid in the
left corner a darker appearance.
Emissive Color
The emissive color is the apparent color of light emitted directly by the solid surface.
Examples of solids with a nonzero emissive color include glowing hot metal, light
displays, and the Sun. For most applications, the RGBA vector [0 0 0 1] works well.
2-49
2 Rigid Bodies
The figure shows the effect of varying the emissive color of a solid. The array of
spheres have identical graphical properties, with the exception of the Emissive
Color. The RGBA color vector of the emissive color progresses from [1 1 1 1], at the
left corner, to [1 0 0 1], at the right corner. A gray ambient color gives the solid in
the left corner a darker appearance. The glowing appearance of the emissive color
differentiates the emissive color from ambient and diffuse colors.
Shininess
The shininess is a parameter that encodes the size and rate of decay of specular
highlights on a solid surface. A small shininess value corresponds to a large specular
highlight with gradual falloff in highlight intensity. On the other hand, a large
shininess value corresponds to a small specular highlight with sharp falloff in
highlight intensity.
The figure shows the effect of varying the shininess of a solid. The array of spheres
have identical graphical properties, with the exception of Shininess. The shininess
value progresses from 5, at the left corner, to 25, at the right corner. As the shininess
value increases, the area of the specular highlight decreases, while the falloff rate in
highlight intensity increases.
2-50
Model Cone
Model Cone
In this section...
“Model Overview” on page 2-51
“Modeling Approach” on page 2-51
“Build Solid Model” on page 2-52
“Define Solid Properties” on page 2-53
“Visualize Solid Model” on page 2-54
Model Overview
You can model solids of revolution using the Simscape Multibody Revolution shape.
Examples of solids of revolution include cone and circular dome shapes. In this example,
you model a simple solid with cone shape using the Revolution shape. For an example
that shows you how to model a circular dome solid, see “Model Dome” on page 2-57.
Modeling Approach
To represent the cone geometry, first identify its cross-section shape. This is the 2-D
area that Simscape Multibody revolves to obtain the 3-D cone. Then, specify the cross-
section coordinates in the Solid block dialog box. These coordinates must satisfy certain
restrictions. See “Revolution and General Extrusion Shapes” on page 2-18.
The cone in this example has a trapezoidal cross-section. The figure shows this cross-
section.
2-51
2 Rigid Bodies
The [0 0] cross-section coordinate identifies the reference frame origin for this solid.
To place the solid reference frame at the cone tip, you by specify the coordinates so
that the [0 0] coordinate coincides with the tip. By parameterizing the cross-section
coordinates in terms of the relevant cone dimensions, you can quickly change the cone
dimensions without having to reenter the cross-section coordinates. The figure shows the
parameterized cross-section coordinates points.
2-52
Model Cone
Prompt Name
Base Radius R
Cone Height H
Wall Thickness T
Density Rho
Color RGB
3 In the Initialization tab of the Mask Editor, define the cross-section coordinates
and assign them to the MATLAB variable CS:
Alpha = atan(R/H);
CS = [0 0; R H; R-T/cos(Alpha) H; 0 T/sin(Alpha)];
2-53
2 Rigid Bodies
4 In the Subsystem block dialog box, specify the numerical values of the solid
properties. The table shows some values that you can enter.
Parameter Enter
Base Radius 1
Cone Height 2
Wall Thickness 0.1
Density 2700
Color [0.85 0.45 0]
2-54
Model Cone
2-55
2 Rigid Bodies
2-56
Model Dome
Model Dome
In this section...
“Model Overview” on page 2-57
“Modeling Approach” on page 2-57
“Build Solid Model” on page 2-58
“Define Solid Properties” on page 2-59
“Visualize Solid Model” on page 2-60
Model Overview
You can model a solid of revolution with a round cross-section. One example is the
circular dome. In this example, you specify the cross-section coordinates of a circular
dome using the MATLAB cos and sin functions. For an example that shows you how to
model a cone-shaped solid, see “Model Cone” on page 2-51.
Modeling Approach
To represent the dome geometry, first identify its cross-section shape. This is the 2-D
shape that Simscape Multibody revolves to obtain the 3-D dome. You can then specify the
cross-section coordinates in the Solid block dialog box. These coordinates must satisfy
certain restrictions. See “Revolution and General Extrusion Shapes” on page 2-18.
The dome has a quarter-circle cross-sectional shape. The figure shows this shape.
2-57
2 Rigid Bodies
The [0 0] cross-section coordinate identifies the reference frame origin for this solid. To
place the solid reference frame at the dome base center, you specify the coordinates so
that the [0 0] coordinate coincides with the base center. By parameterizing the cross-
section coordinates in terms of the relevant dome dimensions, you can quickly change
the dome dimensions without having to reenter the cross-section coordinates. The figure
shows the parameterized cross-section coordinate points.
To define the dome cross-section, first define two angle arrays—one in counterclockwise
order, running from 0–90°; the other in a clockwise order running from 90–0°. You can
then use the first array to define the outer cross-section coordinates, and the second
array to define the inner cross-section coordinates. You do that using the MATLAB cos
and sin functions.
2-58
Model Dome
Prompt Name
Base Radius R
Wall Thickness T
Density Rho
Color RGB
3 In the Initialization tab of the Mask Editor, define the cross-section coordinates
and assign them to the MATLAB variable CS:
2-59
2 Rigid Bodies
CS = [OuterCS; InnerCS];
4 In the Subsystem block dialog box, specify the numerical values of the solid
properties. The table shows some values that you can enter.
Parameter Enter
Base Radius 1
Wall Thickness 0.1
Density 2700
Color [0.85 0.45 0]
2-60
Model Dome
2-61
2 Rigid Bodies
2-62
Model I-Beam
Model I-Beam
In this section...
“Model Overview” on page 2-63
“Modeling Approach” on page 2-63
“Build Solid Model” on page 2-64
“Define Solid Properties” on page 2-65
“Visualize Solid Model” on page 2-66
Model Overview
You can model an extrusion using the Simscape Multibody shape General Extrusion.
Examples of extrusions include the I-beam and box-beam shapes. In this example, you
model a simple solid with I-beam shape using the General Extrusion shape. For
an example that shows you how to model a box beam, see “Model Box Beam” on page
2-69.
Modeling Approach
To represent the I-beam geometry, first identify its cross-section. This is the 2-D area
that Simscape Multibody extrudes to obtain the 3-D I-beam. You can then specify the
cross-section coordinates in the Solid block dialog box. The figure shows the I-beam
cross-section that you specify in this example.
2-63
2 Rigid Bodies
The [0 0] coordinate identifies the solid reference frame origin. To place the reference
frame at the center of the I-beam, specify the coordinates so that the [0 0] coordinate
is at the cross-section center. Because the I-beam cross-section is symmetric about the
horizontal and vertical axes, you need only define the coordinates for one cross-section
half—e.g, the right half. You can then define the left half coordinates in terms of the
right half coordinates.
Using the cross-section points that the figure shows, you define the coordinate matrix as:
2-64
Model I-Beam
2 In the Solid block dialog box, specify the following parameters. You later initialize
the different MATLAB variables in a subsystem mask.
Prompt Name
Length L
Height H
Width W
Thickness T
2-65
2 Rigid Bodies
Prompt Name
Density Rho
Color RGB
3 In the Initialization tab of the Mask Editor, define the cross-section coordinates
and assign them to MATLAB variable CS:
D = H/2-T;
HalfCS = [W/2, -H/2; W/2, -D; T/2, -D;...
T/2, D; W/2, D; W/2, H/2];
CS = [HalfCS; -HalfCS];
4 In the Subsystem block dialog box, specify the numerical values of the solid
properties. The table shows some values that you can enter.
Parameter Enter
Length 10
Height 4
Width 2
Thickness 0.2
Density 2700
Color [0.85 0.45 0]
2-66
Model I-Beam
2-67
2 Rigid Bodies
2-68
Model Box Beam
In this section...
“Model Overview” on page 2-69
“Modeling Approach” on page 2-69
“Build Solid Model” on page 2-70
“Define Solid Properties” on page 2-71
“Visualize Solid Model” on page 2-72
Model Overview
You can model an extrusion with a hole. One example is the box beam. Specifying
hollow cross-sections must satisfy the cross-section guidelines. See “Revolution and
General Extrusion Shapes” on page 2-18. In this example, you specify the cross-section
coordinates of a box beam. For an example that shows you how to model an I-beam
extrusion, see “Model I-Beam” on page 2-63.
Modeling Approach
To represent the box beam geometry, first identify its cross-section. This is the 2-D area
that you sweep along an axis to obtain the 3-D box beam. You can then specify the cross-
section coordinates using the Solid block. The figure shows the box beam cross-section
that you specify in this example.
2-69
2 Rigid Bodies
The [0 0] coordinate identifies the solid reference frame origin. To place the reference
frame at the center of the box beam, specify the coordinates so that the [0 0] coordinate
is at the cross-section center. By parameterizing the cross-section coordinates in terms
of relevant box beam dimensions, you can later change the box beam dimensions without
having to reenter the cross-section coordinates. The figure shows the cross-section
dimensions and coordinates that you must specify to represent the box beam.
Using the cross-section points that the figure shows, you define the coordinate matrix as:
2-70
Model Box Beam
2 In the Solid block dialog box, specify the following parameters. You later initialize
the different MATLAB variables in a subsystem mask.
1 Select the Subsystem block and create a subsystem mask, e.g., by pressing Ctrl+M.
2
In the Parameters & Dialog tab of the Mask Editor, drag six Edit boxes into
the Parameters group and specify these parameters.
Prompt Name
Length L
Height H
2-71
2 Rigid Bodies
Prompt Name
Width W
Thickness T
Density Rho
Color RGB
3 In the Initialization tab of the Mask Editor, define the cross-section coordinates
and assign them to MATLAB variable CS:
D1 = W/2-T;
D2 = H/2-T;
OuterCS = [-W/2,-H/2; W/2,-H/2; W/2,H/2; ...
-W/2,H/2; -W/2,-H/2];
InnerCS = [-D1,-D2; -D1,D2; D1,D2; D1 -D2; -D1,-D2];
CS = [OuterCS; InnerCS];
4 In the Subsystem block dialog box, specify the numerical values of the solid
properties. The table shows some values that you can enter.
Parameter Enter
Length 10
Height 4
Width 2
Thickness 0.2
Density 2700
Color [0.85 0.45 0]
2-72
Model Box Beam
2-73
2 Rigid Bodies
2-74
Model Link
Model Link
In this section...
“Model Overview” on page 2-75
“Build Model” on page 2-75
“Generate Subsystem” on page 2-77
“Visualize Model” on page 2-79
“Open Reference Model” on page 2-79
Model Overview
In this example, you model a two-hole binary link as a rigid body. Three Solid blocks
represent the main body and hole sections of the link. Two Rigid Transform blocks define
the spatial relationships between the three solids.
Build Model
1 Start a new model.
2 Drag the following blocks to the model.
2-75
2 Rigid Bodies
Be sure to flip the Rigid Transform block. Its B frame port must face the Main Solid
block. Also include the broken line extending from the Hole B block (right click the
existing connection line and drag).
2-76
Model Link
Generate Subsystem
Enclose the binary link blocks in a Subsystem block, define the general extrusion
coordinates, and specify the relevant parameter values:
1 Select all blocks excluding Solver Configuration and press Ctrl+G.. Simulink
encloses the selected blocks in a new subsystem block. Rename the subsystem block
as shown in the figure.
2 Select the subsystem block and press Ctrl+M. Simulink adds a parameter mask to
the subsystem block.
3
In the Parameters & Dialog tab of the Mask Editor, drag six edit boxes into
the Parameters group and specify the following parameters.
Prompt Name
Length L
Width W
2-77
2 Rigid Bodies
Prompt Name
Thickness T
Peg Hole Radius R
Mass Density Rho
Link Color LinkRGB
4 In the Initialization tab of the Mask Editor, define the extrusion cross sections and
click OK:
% Cross-section of Main:
Alpha = (pi/2:-0.01:-pi/2)';
Beta = (3*pi/2:-0.01:pi/2)';
% Cross-section of HoleA:
Alpha = (pi/2:0.01:3*pi/2)';
Beta = (3*pi/2:-0.01:pi/2)';
HoleACS = [W/2*cos(Alpha) W/2*sin(Alpha);...
R*cos(Beta) R*sin(Beta)];
% Cross-section of HoleB:
Alpha = (-pi/2:0.01:pi/2)';
Beta = (pi/2:-0.01:-pi/2)';
HoleBCS = [W/2*cos(Alpha) W/2*sin(Alpha);...
R*cos(Beta) R*sin(Beta)];
5 In the dialog box of the Binary Link B subsystem block, specify these parameters.
Parameter Value
Length 30
Width 2
Thickness 0.8
Peg Hole Radius 0.4
2-78
Model Link
Parameter Value
Mass Density 2700
Link Color [R G B] [0.25 0.4 0.7]
Visualize Model
Update the block diagram. You can do this by pressing Ctrl+D. Mechanics Explorer
opens with a static display of the binary link rigid body. To obtain the view shown in the
figure, in the Mechanics Explorer toolstrip select the isometric view button .
You can open a copy of the resulting model. At the MATLAB command line, enter
smdoc_binary_link_b.
Related Examples
• “Model Mount” on page 2-81
2-79
2 Rigid Bodies
2-80
Model Mount
Model Mount
In this section...
“Model Overview” on page 2-81
“Build Model” on page 2-81
“Generate Subsystem” on page 2-83
“Visualize Model” on page 2-85
“Open Reference Model” on page 2-85
Model Overview
Bodies in Simscape Multibody models are often combinations of simpler solid elements.
These bodies are known as compound. They comprise various Solid and Rigid
Transform blocks often placed inside a Simulink Subsystem block. This example shows
how to model a compound body consisting of an hexagonal plate and a cylindrical peg.
To model the mount body, you use two Solid blocks—one for the hexagonal plate, another
for the cylindrical peg. Each Solid block provides a reference frame, located at the
geometric center of the solid shape. You specify the spatial relationship between the two
solids by connecting the reference frame ports through a Rigid Transform block.
Build Model
1 Drag these blocks into a new model.
2-81
2 Rigid Bodies
Note: Include the disconnected frame line. This line becomes important when you
generate a subsystem for the pivot mount. To add this line, right-click on the solid
frame line and drag to the right.
Parameter Value
Geometry > Shape Select Regular Extrusion.
Geometry > Number of Sides Enter 6.
Geometry > Outer Radius Enter HexagonR. Select units of cm.
Geometry > Length Enter T. Select units of cm.
Inertia > Density Enter Rho.
2-82
Model Mount
Parameter Value
Graphic > Color Enter HexagonRGB.
4 In the Peg block dialog box, specify these parameters.
Parameter Value
Geometry > Shape Select Cylinder
Geometry > Radius Enter PegR. Select units of cm.
Geometry > Length Enter 2*T.
Inertia > Density Enter Rho.
Graphic > Color Enter PegRGB.
5 In the To Peg block dialog box, specify these parameters.
Parameter Value
Translation > Method Select Standard Axis.
Translation > Axis Select +Z.
Translation > Offset Enter 3/2*T. Select units of cm.
6 In the To World block dialog box, specify these parameters.
Parameter Value
Rotation > Method Select Standard Axis.
Rotation > Axis Select –Y.
Rotation > Angle Enter 90.
Generate Subsystem
You can now generate a subsystem to encapsulate the pivot mount block diagram. The
subsystem mask provides a convenient place to initialize the MATLAB variables that you
defined the block parameters with. To generate the subsystem:
3 Select the Pivot Mount block and create a subsystem mask, e.g., by pressing Ctrl+M.
4
In the Parameters & Dialog tab of the Mask Editor, drag six edit boxes into
the Parameters group and specify their properties. Click OK.
Prompt Name
Hexagon Outer Radius HexagonR
Hexagon Thickness T
Mass Density Rho
Hexagon Color HexagonRGB
Peg Radius PegR
Peg Color PegRGB
5 In the Pivot Mount block dialog box, specify these parameters.
Parameter Value
Hexagon Outer Radius (m): 4
Hexagon Thickness (m): 0.8
Mass Density (kg/m^3): 2700
Hexagon Color [R G B]: [0.25 0.4 0.7]
Peg Radius (m): 0.4
Peg Color [R G B]: [1 0.6 0.25]
2-84
Model Mount
Visualize Model
Update the block diagram. You can do this by pressing Ctrl+D. Mechanics Explorer
opens with a static display of the pivot mount rigid body. To obtain the view shown in the
figure, in the Mechanics Explorer toolstrip select the isometric view button .
More About
• “Representing Frames” on page 1-6
• “Revolution and General Extrusion Shapes” on page 2-18
• “Solid Inertia” on page 2-22
• “Solid Color” on page 2-46
2-85
3
Multibody Systems
3-2
Modeling Joint Connections
Joints impose between bodies the primary kinematic constraints that determine how
they can move relative to each other. A joint can be a physical connection, such as
that between the case and shaft of a linear hydraulic actuator, or a virtual connection,
such as that between the Earth and the moon. In Simscape Multibody, you model both
connection types using Joint blocks.
Gear and Constraint blocks too impose kinematic constraints between bodies. How are
joint blocks different? While Gear and Constraint blocks are parameterized in terms of
the DoFs they remove between bodies, Joint blocks are parameterized in terms of the
DoFs they provide, through modules called joint primitives.
3-3
3 Multibody Systems
Joint DoFs are a measure of joint mobility. Precluding other constraints in a model, a
joint with mode DoFs allows greater freedom of motion between the adjoining bodies.
Joint DoFs also have a mathematical interpretation. They are the minimum number of
state variables needed to fully determine the configuration of a joint at each time step
during simulation.
Consider a rectangular joint. This joint allows translation in a plane and it therefore
has two translational DoFs—one for each spatial dimension. At each time step, the joint
configuration is fully determined by two state variables, the position coordinates in the
plane of motion [x(t), y(t)]. This means, for example, that you can fully prescribe motion
at this joint using two position input signals.
The table summarizes the DoFs that the various Joint blocks provide.
3-4
Modeling Joint Connections
The actual DoFs at a joint are often fewer in number than the joint alone would allow.
This happens when kinematic constraints elsewhere in the model limit the relative
motion of the adjoining bodies. Such constraints can arise from gears in mesh, forbidden
DoFs due to other joints in closed kinematic loops, and fixed distances and angles
between bodies, among other factors.
Joint Primitives
Joint blocks are assortments of joint primitives, basic yet complete joints of various
kinds you cannot decompose any further—at least without losing behavior such as
the rotational-translational coupling of the lead screw joint. Joint primitives range in
number from zero in the Weld Joint block to six in the Bushing Joint block. There are
five joint primitives:
• Prismatic — Allows translation along a single standard axis (x, y, or z). Joint blocks
can contain up to three prismatic joint primitives, one for each translational DoF.
Prismatic primitives are labeled P*, where the asterisk denotes the axis of motion,
e.g., Px, Py, or Pz.
3-5
3 Multibody Systems
• Revolute — Allows rotation about a single standard axis (x, y, or z). Joint blocks can
contain up to three revolute joint primitives, one for each rotational DoF. Revolute
primitives are labeled R*, where the asterisk denotes the axis of motion, e.g., Rx, Ry,
or Rz.
• Spherical — Allows rotation about any 3-D axis, [x, y, z]. Joint blocks contain no more
than one spherical primitive, and never in combination with revolute primitives.
Spherical primitives are labeled S.
• Lead Screw Primitive — Allows coupled rotation and translation on a standard
axis (e.g., z). This primitive converts between rotation at one end and translation at
the other. Joint blocks contain no more than one lead screw primitive. Lead screw
primitives are labeled LS*, where the asterisk denotes the axis of motion.
• Constant Velocity Joint — Allows rotation at constant velocity between intersecting
though arbitrarily aligned shafts. Joint blocks contain no more than one constant
velocity primitive. Constant velocity primitives are labeled CV.
The table summarizes the joint primitives and DoFs that the various Joint blocks
provide.
3-6
Modeling Joint Connections
Why use Joint blocks with spherical primitives? Those with three revolute primitives are
susceptible to gimbal lock—the natural but often undesired loss of one rotational DoF
when any two rotation axes become aligned. Gimbal lock leads to simulation errors due
to numerical singularities. Spherical primitives eliminate the risk of gimbal-lock errors
by representing 3-D rotations using 4-D quantities known as quaternions.
Joint Inertia
Simscape Multibody joints are idealizations. They differ from real joints in that they have
no inertia—a suitable approximation in most models, where the impact of joint inertia on
system dynamics is often negligible. This is the case, for example, in the constant-velocity
joints of automobile driveline systems, where shaft inertia can dwarf joint inertia.
If joint inertia is important in your model, you can account for it using Solid or Inertia
blocks. Connect the block reference frame ports to the appropriate joint frames and
specify the joint inertial properties in the block dialog boxes. You can specify joint
mass or density, products of inertia, moments of inertia, and center of mass. For more
information on how to specify inertia, see “Solid Inertia” on page 2-22.
3-7
3 Multibody Systems
In this section...
“Model Assembly” on page 3-8
“Connecting Joints” on page 3-8
“Orienting Joints” on page 3-9
“Guiding Assembly” on page 3-10
“Verifying Model Assembly” on page 3-11
Model Assembly
You model an articulated system by interconnecting bodies through joints and
occasionally gears and other constraints. Bodies contribute their inertias to the model,
while joints, gears, and constraints determine the relative degrees of freedom that exist
between the bodies. You interconnect the two component types by linking frame ports on
Joint, Gear, and Constraint blocks to frame ports on body subsystems.
Simscape Multibody automatically assembles your model when you update the block
diagram—for example, by selecting Simulation > Update Diagram from the Simulink
menu bar.
During model update, Simscape Multibody determines the initial states of joints—
their positions and velocities—so that the resulting assembly satisfies all kinematic
constraints in the model. This process occurs in two phases, with the assembly algorithm
first computing the joint positions and then the joint velocities. The complete process is
called model assembly.
Connecting Joints
Joints connect to bodies through frames. Each Joint block contains two frame ports, base
(B) and follower (F), identifying the connection points in the adjoining bodies and the
relative directions they can move in. When you connect these ports to frames in the body
subsystems, you determine how the bodies themselves connect upon model assembly.
3-8
Assembling Multibody Models
Joint Frames Identifying Connection Points and Rotation Axis of Aircraft Propeller
If a joint has no actuation and no sensing outputs, its frame ports are fully
interchangeable. In this case, you can switch the bodies that the ports connect to without
affecting model dynamics or joint sensing outputs. If the joint does have actuation inputs
or sensing outputs, you may need to reverse the actuation or sensing signals to obtain the
same dynamic behavior and simulation results.
To change the connection points of a joint, you must modify the connection frames
in the adjoining body subsystems. You do this by specifying a translation transform
using a Rigid Transform block. You can add new Rigid Transform blocks to the
body subsystems or, if appropriate, change the translation transforms in existing Rigid
Transform subsystems.
For more information on how Simscape Multibody software interprets frame ports,
nodes, and lines, see “Representing Frames” on page 1-6.
Orienting Joints
To obtain the motion expected in a model, you must align its various joint motion axes
properly. This means aligning the joints themselves as observed or anticipated in the real
system. Misaligning the joint axes may lead to unexpected motion but it often leads to
something more serious, such as a failure to assemble and simulate.
You can specify and change joint alignment by rotating the connection frames local to the
adjoining body subsystems. For this purpose, you specify rotation transforms using Rigid
Transform blocks, either by adding new blocks to the body subsystems or, if appropriate,
by changing the rotation transforms in existing blocks within the subsystems.
Why change the orientation of joints through body subsystem frames? The primitives in
a Joint block each have a predetermined motion axis, such as x or z. The axis definition
is fixed and cannot be changed. Realigning the connection frames local to the adjoining
3-9
3 Multibody Systems
body subsystems provides a natural way to reorient joints while avoiding confusion over
which axis a particular joint uses.
For an example of how to rotate joint connection frames, see “Model Mount” on page 2-81.
Guiding Assembly
Joints can start simulation from different states. For example, the crank joint of a crank-
rocker linkage can start at any angle from 0° to 360°. As a result, during model assembly,
Simscape Multibody must choose from many equally valid states. You can guide the
states chosen by specifying state targets in the Joint block dialog boxes.
State targets need not be exact values. If Simscape Multibody cannot achieve a state
target exactly, it searches for the joint state nearest to the state target. For example, if
you specify a position state target of 60° but the joint can only reach angles of 0° to 45°,
Simscape Multibody attempts to assemble the joint at 45°.
How close the actual joint state is to the state target depends on the kinematic
constraints in your model, any conflicts with other state targets, and the state target
priority level—a ranking that determines which of two state targets to satisfy if they
prove to be mutually incompatible. You can set the priority level to Low or High.
Simscape Multibody first attempts to satisfy all state targets exactly. If a state target
conflict arises, Simscape Multibody ignores the low-priority state targets and attempts to
satisfy only the high-priority state targets. If a state target conflict still exists, Simscape
Multibody ignores also the high-priority state targets and attempts to assemble the
model in the nearest valid configuration.
You can specify state targets for all joints in an open kinematic chain. However, to
avoid simulation errors, every closed chain must contain at least one joint without state
targets.
3-10
Assembling Multibody Models
Joint Assembly Failure in Four-Bar Linkage with Exceedingly Long Ground Link
To ensure that your model has assembled correctly, use these Simscape Multibody and
Simscape utilities:
3-11
3 Multibody Systems
3-12
Assembling Multibody Models
3-13
3 Multibody Systems
j
F = 3 ( N - 1) - Â (3 - fi )
i =1
You can view the mechanism DoFs through the Simscape Statistics Viewer, shown
below for the four-bar featured example. You open the Statistics Viewer from the
Simulink Editor menu bar by selecting Tools > Simscape > Statistics Viewer. Enter
sm_four_bar at the MATLAB command prompt to open the four-bar model and view its
DoFs through the Statistics Viewer.
3-14
Model Double Pendulum
Model Overview
The double pendulum is a simple multibody system. It contains two links and a pivot
mount that connect with joints. This system is nonlinear and does under certain
conditions exhibit chaos. In this example, you assemble a double pendulum using custom
blocks for the links and the pivot mount. You can later use this model to study the
chaotic motion of a double pendulum.
To model the double pendulum, you represent each physical component and constraint
using a Simscape Multibody block. The double pendulum system contains three rigid
3-15
3 Multibody Systems
bodies—one pivot mount and two binary links— that connect in series through a pair
of revolute joints. You represent the pivot mount and the binary links using the custom
library blocks that you created in previous examples. You represent the two joints using
two Revolute Joint blocks from the Joints library.
You can guide model assembly. By specifying joint state targets, you can instruct
Simscape Multibody to assemble a joint in the configuration you want. State targets that
you can specify include position and velocity. At times, a state target may conflict with
other state targets, or even with other kinematic constraints in the model. In these cases,
you can prioritize the most important state targets by assigning them a high priority
level. During assembly, if two targets conflict with each other, Simscape Multibody
assembles the high priority target first. To specify both state target values and priority
levels, you use the State Targets menu of the joint block dialog boxes.
Build Model
1 Start a new model.
2 Drag these blocks into the model. The two Revolute Joint blocks provide the double
pendulum two rotational degrees of freedom.
Block Quantity
Pivot Mount 1
3-16
Model Double Pendulum
Block Quantity
Binary Link A 2
5 Connect the blocks as shown in the figure.
3-17
3 Multibody Systems
To check the assembly status of the revolute joints, use the Model Report utility. You
can open this utility from the Mechanics Explorer menu bar by selecting Tools > Model
Report. The figure shows the assembly information for the double pendulum.
3-18
Model Double Pendulum
Simulate Model
Run the simulation, e.g., by selecting Simulation > Run. Mechanics Explorer shows a
3-D animation of the double pendulum assembly. The assembly moves due to gravity,
specified in the Mechanism Configuration block.
• smdoc_double_pendulum
3-19
3 Multibody Systems
Model Overview
The four-bar linkage is a planar closed-loop linkage used extensively in mechanical
machinery. This linkage has four coplanar bars that connect end-to-end with four
revolute joints. In this example, you model a four-bar linkage using the Binary Link
and Pivot Mount custom blocks that you created in previous examples. For an advanced
application of the four-bar linkage, see the bucket actuating mechanism of the Backhoe
featured example.
Modeling Approach
To model the four-bar linkage, you represent each physical component with a Simscape
Multibody block. The linkage in this example has five rigid bodies—three binary links
3-20
Model Four Bar
and two pivot mounts—that connect in a closed loop through four revolute joints. Two
of the binary links have one peg and one hole. The third binary link has two holes.
The fourth link is implicit: the fixed distance between the two coplanar pivot mounts
represents this link.
You represent the binary links and pivot mounts using the custom library blocks that
you created in previous examples. You represent the four revolute joints using four
Revolute Joint blocks from the Simscape Multibody Joints library.
The two pivot mounts connect rigidly to the world frame. For this reason, the implicit
link acts as the ground link. Two Rigid Transform blocks provide the rigid connection
between the two pivot mounts and the World frame. A translation offset in each Rigid
Transform block displaces the two pivot mounts symmetrically along the world frame Y
axis.
To guide model assembly, you can specify the desired initial state for one or more joints
in the model. To do this, you use the State Targets menu of the joint blocks. The
state targets that you can specify are the joint position and velocity. These are angular
quantities in revolute joints. You can specify state targets for all but one of the joints in a
closed loop.
Build Model
To model the four-bar linkage:
3-21
3 Multibody Systems
4 From the Simscape > Multibody > Joints library, drag four Revolute Joint blocks
into the model.
5 At the MATLAB command prompt, enter smdoc_compound_rigid_bodies. A
custom library with compound rigid body blocks opens up.
6 From the smdoc_compound_rigid_bodies library, drag these blocks. Each block
represents a rigid body present in the four bar assembly. See the tutorials in the
table for instructions on how to create the blocks.
Block Quantity
Pivot Mount 2
3-22
Model Four Bar
Block Quantity
Binary Link A 2
Binary Link B 1
7 Connect and name the blocks as shown in the figure. You must position the frame
ports of the custom rigid body blocks exactly as shown.
3-23
3 Multibody Systems
Mechanics Explorer opens with a static display of the four-bar linkage in its initial
configuration. If the joint state targets that you specified are valid and compatible,
the initial configuration matches those state targets. The figure shows the static
display that you see in Mechanics Explorer after updating the model. To obtain the
view shown in the figure, in the Mechanics Explorer toolstrip select the isometric
view button .
3-24
Model Four Bar
You can guide assembly so that the four-bar linkage assembles in an open configuration
instead. To do this, you must specify a position state target for at least one more joint.
You do not have to specify this target precisely. If you have a general idea of what the
target should be, you can enter an approximate value and select a low priority level for
that target.
Closed-loop kinematic chains like the four-bar linkage are especially vulnerable to
assembly issues. Even when the model assembles, Simscape Multibody may fail to meet
one or more state targets. You can check the assembly status of the model and of the
joints using the Model Report utility:
1 In the Mechanics Explorer menu bar, select Tools > Model Report.
2 Examine the model report for red squares or yellow triangles. These shapes identify
issues in the assembly or in the joint state targets.
The figure shows the model report for the four bar linkage in the open configuration. A
green circle indicates that Simscape Multibody satisfied the Base-Crank Revolute Joint
state target precisely. A yellow circle indicates that Simscape Multibody satisfied the
Base-Rocker Revolute Joint state target approximately.
3-25
3 Multibody Systems
Simulate Model
Run the simulation, e.g., by selecting Simulation > Run. Mechanics Explorer shows a
3-D animation of the four bar assembly. The assembly moves due to gravity, specified in
the Mechanism Configuration block.
• smdoc_four_bar
3-26
Find and Fix Aiming-Mechanism Assembly Errors
In this section...
“Model Overview” on page 3-27
“Explore Model” on page 3-28
“Update Model” on page 3-31
“Troubleshoot Assembly Error” on page 3-31
“Correct Assembly Error” on page 3-33
“Simulate Model” on page 3-34
Model Overview
In closed-loop systems, joints and constraints must be mutually compatible. For example,
in a four-bar linkage, all revolute joints must spin about parallel axes. If one of the joints
spins about a different axis, assembly fails and the model does not simulate.
To simplify the troubleshooting process, Simscape Multibody provides Model Report. This
tool helps you pinpoint the joints and constraints that caused assembly to fail. Once you
identify these joints and constraints, you can then determine which of their frames to
correct—and how to correct them.
In this example, you identify the assembly error source in an aiming mechanism model
using Model Report. Then, using Mechanics Explorer, you determine how to correct that
error source. The sm_dcrankaim_assembly_with_error featured example provides
the basis for this example.
3-27
3 Multibody Systems
Explore Model
To open the model, at the MATLAB command line, enter
sm_dcrankaim_assembly_with_error. The model opens in a new window.
The figure shows a schematic of the system that the model represents. This system
contains four rigid bodies, labeled A-D. These rigid bodies connect in a closed loop via
four joints, labeled Ri, Ro, Rg, and Pg. When connected to each other, these components
form a system with one degree of freedom.
3-28
Find and Fix Aiming-Mechanism Assembly Errors
The model represents the components of this system using blocks. Each block represents
a physical component. A World Frame block provides the ultimate reference frame in
the model. The figure shows the block diagram that the model uses to represent the
double-crank aiming mechanism.
3-29
3 Multibody Systems
To represent the rigid bodies, the model contains four subsystem blocks, labeled Rigid
Body A-D. Each subsystem contains one Solid block and multiple Rigid Transform
blocks. The Solid block provides geometry, inertia, and color to the rigid body subsystem.
The Rigid Transform blocks provide the frames that you connect the joints to. A
Reference Frame block identifies the ultimate reference frame in the subsystem block.
The model labels the rigid body subsystem blocks Rigid Body A-D. To examine the block
diagram for a rigid body subsystem, right-click the subsystem block and select Mask >
Look Under Mask. The figure shows the block diagram for Rigid Body A.
3-30
Find and Fix Aiming-Mechanism Assembly Errors
To represent the joints, the model contains four joint blocks. Three joints provide one
rotational degree of freedom between a pair of rigid bodies. You represent each of these
joints with a Revolute Joint block. A fourth joint provides one translational degree
of freedom between a pair of rigid bodies. You represent this joint with a Prismatic
Joint block. The model labels the revolute joint blocks Ro, Rg, and Ri, and the prismatic
joint block Pg.
Update Model
As the model name suggests, this model contains an error. The error prevents the model
from assembling successfully, which causes simulation to fail. To update the model and
investigate the assembly error:
Mechanics Explorer opens with a static display of your model in its initial state.
Because the model contains an assembly error, Simscape Multibody issues an error
message. Ignore that message for now.
3-31
3 Multibody Systems
to determine which joint has failed to assemble. To do this, in the Mechanics Explorer
menu bar, select Tools > Model Report.
Model Report opens in a new window. A red square indicates that the model, as expected,
has failed to assemble. A second red square indicates that an unassembled joint, Pg,
is the only contributing factor in the model assembly error. This information enables
you to concentrate your troubleshooting efforts on a small block diagram region—that
surrounding the Pg joint block.
The error message that Simscape Multibody issued during model update identifies
position violation as the root cause of assembly failure. This suggests that the frames
connected by joint Pg are improperly aligned. To confirm this hypothesis, check the
orientation of these frames in Mechanics Explorer.
3-32
Find and Fix Aiming-Mechanism Assembly Errors
2 In the Mechanics Explorer visualization pane, examine the position and orientation
of the highlighted frames. These are the frames that appear in a light turquoise blue
color.
The two frames are offset along the Z axis. This offset is valid, since joint Pg contains a
prismatic primitive aligned with the Z axis, providing the frames with one translational
degree of freedom along that axis. However, the two frames are also rotated with respect
to each other about the common Z axis. This offset is invalid, since joint Pg contains no
Revolute or Spherical primitives, and hence no rotational degrees of freedom about any
axis. To correct the model assembly error, you must rotate either of the two frames so
that all of their axes are parallel to each other.
3-33
3 Multibody Systems
transform to the base frame. This step enables joint Pg, and hence the model itself, to
assemble successfully.
1 In the tree pane of Mechanics Explorer, right-click the Pg node and select Go To
Block. Simscape Multibody brings the block diagram to the front and highlights the
Pg block.
2 Right-click the Rigid Body C subsystem block and select Mask > Look Under
Mask.
3 Double-click the Slide Frame Transform block and select the new parameter
values that the table provides. Select OK.
Simulate Model
You can now simulate the model. On the Simulink menu bar, select Simulation > Run.
Mechanics Explorer opens with a 3-D animation of your model. The figure shows a
snapshot of the animation. Rotate, pan, and zoom to explore.
You can use the Model Report tool to verify the assembly status. To do this, in the
Mechanics Explorer menu bar, select Tools > Model Report. In Model Report, check
3-34
Find and Fix Aiming-Mechanism Assembly Errors
that the assembly status icons for the model and its joints are green circles. The green
circles indicate that the model has assembled correctly.
Related Examples
• “Model Double Pendulum” on page 3-15
• “Model Four Bar” on page 3-20
More About
• “Modeling Joint Connections” on page 3-3
3-35
3 Multibody Systems
Gear Constraints
In this section...
“Gear Types” on page 3-36
“Featured Examples” on page 3-37
“Inertia, Geometry, and Efficiency” on page 3-37
“Using Gear Blocks” on page 3-37
“Assembling Rigid Bodies with Gear Constraints” on page 3-39
“Common Gear Assembly and Simulation” on page 3-40
“Rack and Pinion Assembly and Simulation” on page 3-42
You can represent gear constraints in a multibody model. To do this, Simscape Multibody
provides a Gears and Couplings library. This library contains gear blocks that you can
use to constrain the motion of two rigid body frames. The figure shows the gear blocks
that the library provides.
Gear Types
The Gears and Couplings > Gears library provides blocks for modeling gears. The
table summarizes the gears you can model with these blocks.
Block Description
Common Gear Constraint Transfer rotational motion between two
frames spinning about parallel axes
3-36
Gear Constraints
Block Description
Rack and Pinion Constraint Transfer rotational motion at a pinion into
translational motion at a rack and vice-
versa.
Bevel Gear Constraint Transfer rotational motion between two
frames spinning about arbitrarily aligned
axes.
Featured Examples
Simscape Multibody provides two featured examples that highlight the use of gear
blocks. The table lists these examples. To open an example model, at the MATLAB
command line, enter the model name, e.g., sm_cardan_gear.
Open the models and examine the blocks for examples of how to connect the gear blocks
and specify their parameters.
3-37
3 Multibody Systems
the gear block dialog box and specify the gear parameters. Parameters can include gear
dimensions and ratio.
So that the three gear subsystems can rotate with respect to each other, the model
includes three Revolute Joint blocks. Each Revolute Joint block provides one rotational
degree of freedom between one gear subsystem and the gear carrier—a rigid body that
holds the three rotating gears. The figure shows the Mechanics Explorer display of this
model.
3-38
Gear Constraints
The rigid body frames that the gear block connects must have the proper number
and type of degrees of freedom. For a Common Gear block, the frames must have two
rotational degrees of freedom with respect to each other. For a Rack and Pinion block, the
frames must have one translational and one rotational degree of freedom with respect to
each other. You provide these degrees of freedom using joint blocks.
• Use joint blocks with revolute primitives to provide the rotational degrees of freedom.
3-39
3 Multibody Systems
• Use joint blocks with prismatic primitives to provide the translational degrees of
freedom.
Connect the gear rigid bodies to joints possessing one (or more) revolute joint primitives.
The rotational axis of the revolute primitive must align with the Z axis of the gear frame
that it connects to. This ensures that the gear frames possess a rotational degree of
freedom about the correct axis (Z).
With the Common Gear block, you can represent internal and external gear constraints.
If the gear constraint is internal, the gear frames rotate in the same direction. If it is
external, the gear frames rotate in opposite directions. The figure illustrates the two
common gear types that you can represent and their relative rotation senses.
3-40
Gear Constraints
Gear Dimensions
In the block dialog box, you specify the gear dimensions. Depending on the specification
method that you choose, you can specify the center-to-center distance between gears
or the pitch circle radii. During model assembly, the Common Gear block imposes this
distance constraint between the two gear frames. This ensures that the gear assembles
properly or, if issues arise, that you can correct any assembly issues early on.
You specify the gear relative sizes in the block dialog box. If you select the Center
Distance and Ratio specification method, the gear ratio specifies which of the two
gears is the larger one. If the gear ratio is greater than one, the follower gear is the larger
gear. If the gear ratio is smaller than one, the base gear is the larger gear.
If you specify an internal gear type, the larger gear is the ring gear. A gear ratio greater
than unity makes the follower gear the ring gear. A gear ratio smaller than unity makes
the base gear the ring gear.
The pitch circle of a gear is an imaginary circle that passes through the contact point
between gears. The pitch radius of a gear is the radius of this imaginary circle. The figure
illustrates the pitch circles of two meshing gears and their pitch radii. These are the gear
radii that you enter in the block dialog box when you select the Pitch Circle Radii
specification method.
3-41
3 Multibody Systems
Simulation
During simulation, the Common Gear block requires that the model maintain the proper
distance between gear frames. This distance must equal either the center-to-center
distance or the sum of base and follower gear pitch radii that you specify in the block
dialog box. The structure of the model must be such that the gears maintain this distance
between them. Failure to maintain this distance results in an error during simulation.
In the Cardan Gear example, the Carrier rigid body fixes the distances between the three
gears. As long as these distances match the gear dimensions that you specify in the block
dialog box, the model should simulate without an issue.
When the gear is in its zero configuration—a configuration in which the angle and
displacement between base and follower frames are taken as zero—the follower frame
Z axis is also parallel to the base frame X axis, and base and follower frame Y axes are
parallel to each other. The follower frame origin lies along the base frame -Y axis, at a
distance equal to the base gear pitch radius. The figure illustrates these constraints.
3-42
Gear Constraints
To ensure the rack and pinion can move with respect to each other, you must connect the
rack and pinion rigid bodies to joints blocks. The joint block on the rack side must have
one (or more) prismatic primitives. At least one primitive axis must align with the Z axis
of the follower gear frame. The joint block on the pinion side must have one (or more)
revolute primitives. At least one revolute axis must align with the Z axis of the base gear
frame.
The pitch circle of a rack and pinion gear is the imaginary circle that passes through
the contact point between the pinion and the rack. The pitch radius is the radius of this
imaginary circle. The figure illustrates the pitch circle for a rack and pinion. This is the
circle whose radius you enter in the block dialog box.
3-43
3 Multibody Systems
Simulation
During simulation, the Rack and Pinion block requires that the model maintain the
proper distance between gear frames. The distance between the base frame origin
(pinion) and the follower frame Z axis must equal the pinion radius. Failure to maintain
this distance between gear frames results in a simulation error.
3-44
Model Rack and Pinion
In this section...
“Model Overview” on page 3-45
“Model Pinion” on page 3-47
“Model Rack” on page 3-49
“Add Rack and Pinion Constraint” on page 3-52
“Actuate Model” on page 3-53
“Simulate Model” on page 3-55
“Open Complete Model” on page 3-56
Model Overview
In this tutorial, you model a kinematic constraint between rack and pinion components.
The constraint causes the two components to move in sync such that a pinion rotation
corresponds to a rack translation:
V F = w B · RB ,
where:
3-45
3 Multibody Systems
3-46
Model Rack and Pinion
For simplicity, the rack has a brick shape and the pinion has a cylinder shape. These
shapes depend on several dimensions, shown in the figure. You specify each dimension
using a MATLAB variable. After model assembly, you can add detail to the component
shapes. For example, you can specify an involute tooth profile for the rack and pinion.
Model Pinion
1 Start a new model.
2 Add these blocks to the model.
Library Block
Simscape > Utilities Solver Configuration
Simscape > Multibody > Frames and World Frame
Transforms
Simscape > Multibody > Utilities Mechanism Configuration
Simscape > Multibody > Joints Revolute Joint
3-47
3 Multibody Systems
Library Block
Simscape > Multibody > Body Solid
Elements
The Solid block specifies the component geometry, inertia, and color. The joint block
provides the component its motion degrees of freedom—in this case, one rotational
degree of freedom with respect to the world frame.
3 Connect and name the blocks as shown in the figure. Port frames joined by a
connection line are coincident in space.
4 In the Pinion block dialog box, specify geometry, inertia, and color.
% Common Parameters
Rho = 2700; % Mass density of both rack and pinion components
% Pinion Parameters
Pinion.R = 10;
Pinion.T = 4;
Pinion.RGB = [0.8, 0.4, 0];
6 Update the block diagram. You can do this by selecting Simulation > Update
Diagram. Mechanics Explorer opens with a 3-D view of the pinion gear. To obtain
the view shown in the figure, in the Mechanics Explorer toolstrip set the View
convention parameter to Y up (XY Front). Then, select the isometric view
button .
Model Rack
1 Add these blocks to the model.
Library Block
Simscape > Multibody > Frames and Rigid Transform
Transforms
Simscape > Multibody > Joints Prismatic Joint
3-49
3 Multibody Systems
Library Block
Simscape > Multibody > Body Solid
Elements
The Rigid Transform block sets the rack position and pose with respect to the pinion.
These quantities must satisfy the assembly conditions later imposed by the Rack and
Pinion Constraint block.
2 Connect and name the blocks as shown in the figure.
3 In the Rack block dialog box, specify geometry, inertia, and color.
The rotation transform makes the rack and pinion Z axes mutually orthogonal while
keeping the Y axes parallel. The translation transform separates the rack and pinion
frame origins by a distance equal to the pinion pitch radius. These transforms satisfy
the assembly conditions imposed by the Rack and Pinion Constraint block.
5 In the model workspace, initialize the new MATLAB variables entered in the block
dialog boxes:
% Rack Parameters
Rack.L = 80;
Rack.H = 2;
Rack.T = Pinion.T;
Rack.RGB = [0.2, 0.4, 0.7];
6 Update the block diagram. Mechanics Explorer displays a 3-D view of the rack and
pinion assembly. Examine the assembly from different viewpoints and verify it is
accurate. You can view the rack and pinion frames by clicking the frame button
in the Mechanics Explorer tool bar.
3-51
3 Multibody Systems
1 From the Gears and Couplings > Gears library, drag a Rack and Pinion
Constraint block to the model.
2 Connect the block as shown in the figure. The follower frame port connects to the
Rack block, while the base frame port connects to the Pinion block.
3-52
Model Rack and Pinion
3 In the dialog box of the Rack and Pinion Constraint block, enter Pinion.R in
Pinion Radius.
4 Update the block diagram. Mechanics Explorer shows a 3-D display of the updated
rack and pinion assembly. Assembly errors due to gear constraints become evident at
this stage. If Simscape Multibody issues an error message, correct the model before
attempting to run the simulation.
Actuate Model
1 In the Revolute Joint block dialog box, for Z Revolute Primitive (Rz) > Actuation
> Torque, select Provided by Input.
The block exposes a physical signal input port. You use this port to specify a driving
torque acting on the pinion. During simulation, this torque will be the source of
motion in the model.
2 Drag these blocks to specify and process the input torque signal.
3-53
3 Multibody Systems
Library Block
Simulink > Sources Signal Builder
Simscape > Utilities Simulink-PS Converter
The Simulink-PS Converter block converts the Simulink input signal into a physical
signal compatible with Simscape Multibody blocks. It also provides signal filtering,
which enables you to smooth discontinuous signals.
3 Connect the blocks as shown in the figure.
4 In the Signal Builder block dialog box, draw the input signal as shown in the figure.
This signal starts with a positive torque followed by a negative torque. The positive
torque causes the pinion to rotate counterclockwise about the base frame +Z axis and
the rack to translate along the follower frame +Z axis.
3-54
Model Rack and Pinion
5 In the Simulink-PS Converter block dialog box, in the Input Handling tab, specify
second-order filtering with a time constant of 0.1 s. This filter helps to smooth the
discontinuities of the input signal.
Simulate Model
Run the simulation. You can do this by selecting Simulation > Run. Mechanics
Explorer plays a physics-based animation of the rack and pinion assembly. To better see
motion during playback, select the frame button in the Mechanics Explorer tool bar.
3-55
3 Multibody Systems
3-56
Model Planetary Gear Train
In this section...
“Model Overview” on page 3-57
“Model Sun-Planet Gear Set” on page 3-58
“Constrain Sun-Planet Gear Motion” on page 3-61
“Add Ring Gear” on page 3-63
“Add Gear Carrier” on page 3-66
“Add More Planet Gears” on page 3-71
Model Overview
Planetary gear trains are common in industrial, automotive, and aerospace systems. A
typical application is the automatic transmission system of car. From a kinematic point
of view, what sets this mechanism apart is the kinematic constraint set between gear
pairs. These constraints fix the angular velocity ratios of the gear pairs, causing the
gears in each pair to move in sync.
In Simscape Multibody, you represent the kinematic constraint between meshed gears
using blocks from the Gears sublibrary. This tutorial shows you how to use these blocks
to model a planetary gear train. The gear train contains four rigid bodies:
• Sun gear
• Planet gear
• Ring gear
• Planet carrier
Each rigid body, including the planet carrier, can spin about its central axis. In addition,
each planet gear can revolve about the sun gear. Joint blocks provide the required
degrees of freedom, while gear constraint blocks ensure the gears move as if they were
meshed.
3-57
3 Multibody Systems
3-58
Model Planetary Gear Train
Parameter Setting
Geometry > Shape Select General Extrusion.
Geometry > Cross-Section Enter
simmechanics.demohelpers.gear_profile(2*Su
Select units of cm.
Geometry > Length Enter T. Select units of cm.
3-59
3 Multibody Systems
Parameter Setting
Inertia > Density Enter Rho.
Graphic > Visual Properties > Color Enter Sun.RGB.
Parameter Setting
Geometry > Shape Select General Extrusion.
Geometry > Cross-Section Enter
simmechanics.demohelpers.gear_profile(2*Pl
Select units of cm.
Geometry > Length Enter T. Select units of cm.
Inertia > Density Enter Rho.
Graphic > Visual Properties > Color Enter Planet.RGB.
5 In the Rigid Transform block dialog box, specify these parameters.
Parameter Setting
Translation > Method Select Standard Axis.
Translation > Axis Select +Y.
Translation > Offset Enter Sun.R + Planet.R. Select units
of cm.
6 In the model workspace, define the block parameters using MATLAB code:
% Common Parameters
Rho = 2700;
T = 3;
A = 0.8; % Gear Addendum
3-60
Model Planetary Gear Train
You can open a copy of the resulting model. At the MATLAB command line, enter
smdoc_planetary_gear_a.
Library Block
Constraints Distance Constraint
Gears and Couplings > Gears Common Gear Constraint
2 Connect the blocks as shown. The new blocks are highlighted.
3-61
3 Multibody Systems
3 In the Common Gear Constraint block dialog box, specify these parameters.
Parameter Setting
Specification Method Select Pitch Circle Radii.
Specification Method > Base Gear Enter Sun.R. Select units of cm.
Radius
Specification Method > Follower Enter Planet.R. Select units of cm.
Gear Radius
3-62
Model Planetary Gear Train
You can open a copy of the resulting model. At the MATLAB command line, enter
smdoc_planetary_gear_b.
Library Block
Body Elements Solid
Joints Revolute Joint
Gears and Couplings > Gears Common Gear Constraint
2 Connect and name the blocks as shown. The new blocks are highlighted.
3-63
3 Multibody Systems
3-64
Model Planetary Gear Train
Parameter Setting
Geometry > Shape Select General Extrusion.
Geometry > Cross-Section Enter Ring.CS. Select units of cm.
Geometry > Length Enter T.
Inertia > Density Enter Rho.
Graphic > Visual Properties > Color Enter Ring.RGB.
4 In the Common Gear Constraint1 block dialog box, specify these parameters.
Parameter Setting
Type Select Internal.
Specification Method Select Pitch Circle Radii.
Specification Method > Base Gear Enter Planet.R. Select units of cm.
Radius
Specification Method > Follower Enter Ring.R. Select units of cm.
Gear Radius
5 In the model workspace, define the Ring Gear block parameters using MATLAB
code:
Ring.Theta = linspace(-pi/Ring.N,2*pi-pi/Ring.N,100)';
Ring.RO = 1.1*Ring.R;
Ring.CSO = [Ring.RO*cos(Ring.Theta) Ring.RO*sin(Ring.Theta)];
Ring.CSI = simmechanics.demohelpers.gear_profile(2*Ring.R,Ring.N,A);
Ring.CSI = [Ring.CSI; Ring.CSI(1,:)];
Ring.CS = [Ring.CSO; flipud(Ring.CSI)];
6 Simulate the model. To induce motion, try adjusting the velocity state targets in
the joint block dialog boxes. Notice that the sun, planet, and ring gears move in a
meshed fashion.
3-65
3 Multibody Systems
You can open a copy of the resulting model. At the MATLAB command line, enter
smdoc_planetary_gear_c.
• Planar Joint
• Rigid Transform
• Distance Constraint
3-66
Model Planetary Gear Train
3-67
3 Multibody Systems
Pay close attention to the Rigid Transform block orientation: the B frame ports
should face the Solid block. The new blocks are highlighted.
3-68
Model Planetary Gear Train
Parameter Setting
Geometry > Shape Select General Extrusion.
Geometry > Cross-Section Enter Carrier.CS. Select units of cm.
Geometry > Length Enter Carrier.T.
3-69
3 Multibody Systems
Parameter Setting
Inertia > Density Enter Rho.
Graphic > Visual Properties > Color Enter Carrier.RGB.
5 In the Rigid Transform block dialog box, specify these parameters.
Parameter Setting
Translation > Method Select Cartesian.
Translation > Offset Enter [Carrier.L/2 0 -(Carrier.T
+T)/2]. Select units of cm.
6 In the Rigid Transform1 block dialog box, specify these parameters.
Parameter Setting
Translation > Method Select Cartesian.
Translation > Offset Enter [-Carrier.L/2 0 -(Carrier.T
+T)/2]. Select units of cm.
7 In the model workspace, define the Carrier block parameters using MATLAB code:
Theta = (90:1:270)'*pi/180;
Beta = (-90:1:90)'*pi/180;
3-70
Model Planetary Gear Train
You can open a copy of the resulting model. At the MATLAB command line, enter
smdoc_planetary_gear_d.
3-71
3 Multibody Systems
3-72
Model Cam Mechanism
In this section...
“Model Overview” on page 3-73
“Geometry Ports” on page 3-74
“Spline Curves” on page 3-76
“Point On Curve Constraints” on page 3-77
“Model Eccentric Cam” on page 3-77
“Model Cam Follower” on page 3-83
“Interactively Create Frame at Follower Tip” on page 3-85
“Constrain Cam and Follower” on page 3-89
Model Overview
This tutorial shows how to model an eccentric cam mechanism. The mechanism consists
of an eccentric disk (the cam) with a lever (the cam follower) mounted on its periphery.
The distance between the rotation axis and perimeter of the cam varies with rotation
angle, causing the follower to translate in a reciprocating motion.
3-73
3 Multibody Systems
To work, the cam mechanism must constrain the follower tip (a point) to lie on the
cam periphery (a curve). This type of constraint is known as point-on-curve. The same
constraint is at work, for example, in a roller coaster cart bound to the perimeter of a
track. You model this constraint using the Point On Curve Constraint block.
Any frame origin associated with a frame port can be a constraint point. Any curve
associated with a geometry port can be a constraint curve. In this example, a frame
origin positioned at the follower tip provides the constraint point. A circular spline curve
defined in a Spline block provides the constraint curve.
Geometry Ports
Geometry ports are analogues of frame ports. In the same way that frame ports identify
frames on bodies, geometry ports identify curves and surfaces. You use these ports to
apply kinematic constraints between the frames, curves, and surfaces that the ports
represent.
You can then apply kinematic constraints between the frames, curves, and surfaces given
by these ports.
3-74
Model Cam Mechanism
If a block has an intrinsic curve or surface definition, its geometry port makes that
definition available to other blocks. If a block does not have such a definition, its
geometry port enables you to reference one through a geometry connection line.
In this example, the Spline block provides an intrinsic curve definition. You specify this
curve in the Spline block dialog box. The Point On Curve Constraint block, which does
not have an intrinsic curve definition, then references this curve through a geometry
connection line to the Spline block.
You can branch a geometry connection line, for example, so that it joins one Spline block
to several Point On Curve Constraint blocks. Such a connection enables you to constrain
various cam followers to the same cam or roller coaster carts to the same track.
However, branched or not, a geometry connection line must have exactly one geometry
definition. If two blocks with intrinsic geometry definitions attach to the same geometry
connection line, Simscape Multibody ignores one. If no such block connects to a geometry
connection line, the model does not simulate. The figure shows a valid branched
geometry line between one cam and three point-on-curve constraints.
3-75
3 Multibody Systems
Spline Curves
The Spline block enables you to model a smooth, continuous curve. In mechanical
systems, such curves are generally limited to contours on bodies. To preserve the parallel
between your model and the system it represents, use the Spline block in the body
subsystem that the spline curve is based on.
3-76
Model Cam Mechanism
In this example, the spline curve represents the cam profile, a 2-D circle on the periphery
of the cam. For this reason, you place the Spline block in the subsystem that represents
the cam body. This approach treats the spline curve as part not of the constraint
definition but of the body definition.
Treating the constraint curve as part of the cam body subsystem enables you to replace
one cam subsystem for another without having to change anything else in the model. It
also enables you to parameterize both the cam solid properties and spline curve in terms
of MATLAB variables defined in a common subsystem mask.
To create the spline curve, the Spline block applies smooth interpolation between the
data points you specify in the block dialog box. The interpolation ensures that the curve
and its first two derivatives are continuous at each point. These constraints enable you to
specify relatively complex curves with a only small number of interpolation points.
Because spline curves need only a small number of interpolation points, they are more
computationally efficient than other curve types. However, if you specify a sufficiently
large number of interpolation points, spline curves can slow down simulation. Try
starting with a small number of interpolation points and gradually adding more until you
reach the curve precision you need.
Similarly, you must identify the constraint curve externally by connecting the geometry
port of the Point On Curve Constraint block to another geometry port in your model. The
geometry connection must be to a block with intrinsic curve definition, such as Spline.
The curve associated with the geometry port is the constraint curve.
1 At the MATLAB command prompt, enter smnew. MATLAB opens the Simscape
Multibody library and a model template with commonly used blocks. Remove all but
3-77
3 Multibody Systems
3-78
Model Cam Mechanism
The Spline block provides the curve coordinates relative to its reference frame port.
The origin of this frame coincides with the [0,0] coordinate.
Parameter Value
Translation > Method Standard Axis
Translation > Axis +Y
Translation > Offset camOffset, units of in
The string camOffset is the translational offset between the cam center of mass
and rotation axis specified as a MATLAB variable. You later initialize this and other
MATLAB variables in the model workspace.
2 In the Solid block dialog box, specify these parameters.
Parameter Value
Geometry > Shape Cylinder
Geometry > Radius r, units of in
Geometry > Length t, units of in
Inertia > Density rho
Graphic > Visual Properties > Color rgbCam
The strings r, t, rho, rgbCam are the cam properties specified as MATLAB
variables.
3 In the Spline curve block, specify these parameters.
Parameter Value
Interpolation Points camProfile, units of in
Graphic > Visual Properties > Color rgbSpline
The string camProfile is the spline curve specified as a MATLAB variable. The
string rgbSpline is the color of the spline curve. 3-79
3 Multibody Systems
4 In the model workspace, define the MATLAB variables referenced in the block dialog
boxes by entering this code:
% Cam parameters
r = 1; % Cam radius
t = 0.3; % Cam thickness
rho = 2700; % Aluminum density, kg/m^3
rgbCam = [1,1,1]; % Cam color
camOffset = r/3; % Distance from rotation axis to CM
% Spline parameters
rgbSpline = [210,120,0]/255; % Spline color
n = 6; % Number of interpolation points
theta = linspace(0,2*pi*(n-1)/n,n)'; % Angle vector
% Spline coordinates
x = r*cos(theta); % Interpolation-point x coordinates
y = r*sin(theta); % Interpolation-point y coordinates
camProfile = [x,y]; % Curve coordinate matrix
The spline portion of the code specifies the circular curve shown in the figure. You
can view the spline curve in the visualization pane of the Spline block dialog box.
The figure shows a top view of the curve.
3-80
Model Cam Mechanism
Drag a selection box around the Rigid Transform, Solid, and Spline blocks. Then, select
the Create Subsystem action button. Name the new Subsystem block Cam. This block
represents the cam body.
3-81
3 Multibody Systems
To visualize the cam body, update the diagram. You can do this from the Simulink menu
bar, by selecting Simulation > Update diagram. Mechanics Explorer opens with a
visualization of the model. To obtain the view shown, in the Mechanics Explorer toolstrip,
set the View convention parameter to Y Up (XY Front). Then, select the Isometric
View button.
3-82
Model Cam Mechanism
3-83
3 Multibody Systems
Parameter Value
Rotation > Method Standard Axis
Rotation > Axis +X
Rotation > Angle -90
This rotation transform ensures that the translational axis of the cam follower is in
the rotation plane of the cam.
2 In the Solid block dialog box, specify these parameters.
3-84
Model Cam Mechanism
Parameter Value
Geometry > Shape Brick
Geometry > Dimensions sizeFollower, units of in.
Inertia > Density rho
Graphic > Visual Properties > Color rgbFollower
The strings sizeFollower, rho, and rgbFollower are the cam follower properties
specified as MATLAB variables.
3 In the model workspace, initialize the cam follower properties by adding this code:
% Follower parameters
sizeFollower = [0.2 0.2 1.5]; % Follower dimensions
rgbFollower = [0.5,0.5,0.5]; % Follower color
Update the diagram. Mechanics Explorer shows the updated model visualization. The
cam and follower bodies overlap as the follower tip is not yet constrained to the cam
periphery.
3-85
3 Multibody Systems
create a new frame. You can create new frames interactively in the Solid block dialog box
using the frame-creation interface.
1 In the Solid block dialog box, expand the Frames area and select the Create
button. If you make any changes to the block parameters, you must first select the
4 Under Frame Origin, select the Use Selected Feature button. This button sets
the center of the selected surface as the origin of the new frame. By default, the
frame orientation is that of the solid reference frame.
3-86
Model Cam Mechanism
5 Select Save. The block saves the new frame definition without committing it to the
model. If you close the block dialog box without first selecting Apply or OK, the
block discards the new frame definition.
6 In the Frames area, clear the Show Port R check box. The block hides the
reference frame port. You do not need this port in this model. Select OK to commit
your changes to the model.
7 Rotate the Follower block and connect its new frame port, labeled F1, to the model as
shown.
3-87
3 Multibody Systems
Update the diagram. Mechanics Explorer shows the updated model visualization. The
model assembles with the cam follower in a new position, though the cam and follower
bodies are still unconstrained.
3-88
Model Cam Mechanism
3-89
3 Multibody Systems
Set the cam in motion by specifying a nonzero initial velocity. Set gravity to zero to
ensure uniform motion of the cam.
Parameter Setting
State Targets > Specify Velocity Select check box.
Target
State Targets > Specify Velocity Enter 0.5. Select units of rev/s.
Target > Value
2 In the Mechanism Configuration block, set the Uniform Gravity parameter to
None.
3-90
Model Cam Mechanism
Simulate the model. You can do this from the Simulink menu bar by selecting
Simulation > Run. Mechanics Explorer shows a physics-based animation of the cam
mechanism.
3-91
4
4-2
Modeling and Sensing System Dynamics
4-3
4 Internal Mechanics, Actuation and Sensing
Modeling Gravity
In this section...
“Gravity Models” on page 4-4
“Gravitational Force Magnitude” on page 4-5
“Force Position and Direction” on page 4-6
“Gravitational Torques” on page 4-7
Gravity Models
Gravity influences motion in many natural and engineered systems. These range in scale
from the very large, such as the planets orbiting the sun, to the relatively small, such as
the shock absorbers damping gravity-driven oscillations in a car. In Simscape Multibody,
you can add gravity to systems like these using three gravity models:
• Uniform gravity, as experienced by most earthbound systems. The force on each body
due to uniform gravity depends only on its mass. This force is the same everywhere in
space for a given body, though it can vary in time. You model uniform gravity using
the Mechanism Configuration block.
• Gravitational field, as experienced by the planets in the solar system. The force on
each body due to a gravitational field depends not only on its mass but also on its
inverse square distance to the field origin. You model a gravitational field using the
Gravitational Field block.
4-4
Modeling Gravity
• Inverse-square law force pair, similar in nature to a gravitational field, but acting
exclusively between one pair of bodies. You model an inverse-square law force pair
using the Inverse Square Law Force block. You must specify the body masses
and force constants explicitly.
Mm
Fg = - G
R2
with G being the gravitational constant. This is the force that you model when you
represent gravity through Gravitational Field or Inverse Square Law Force blocks. If the
distance between source and target masses is constant, the gravitational force reduces to
a simpler form,
Fg = - mg
with g being the nominal gravitational acceleration. Near the surface of the Earth,
at a distance equal to Earth’s radius from the gravitational field origin, the nominal
acceleration equals
GM
g= ª 9 .80665 m s2
R2
This is the gravitational force that you model when you represent gravity through
the Mechanism Configuration block. The figure shows how the magnitude of the
gravitational force (Fg) varies with distance (R) for a given body under uniform gravity, a
gravitational field, and an inverse-square law force pair.
4-5
4 Internal Mechanics, Actuation and Sensing
Far from the field origin, the field origin-center of mass line remains approximately
constant at small-to-moderate displacements, and the force of gravity behaves as if its
direction were fixed. This is the approximation used in the Mechanism Configuration
block. Gravity still acts at each body’s center of mass, but its direction is now fixed along
the gravity vector that you specify.
If you want to model the effects of gravity on a point other than a body’s center of mass,
you can add a frame at the desired location and apply a gravitational force directly at
that frame. You model the force using the Inverse Square Law Force block. This force
points along the imaginary line between the two body frames that the Inverse Square
Law Force block connects.
The table summarizes the application point and direction of gravity provided by the
different blocks.
4-6
Modeling Gravity
Gravitational Torques
A gravitational torque can arise in a large body immersed in a nonuniform gravitational
field. The lemon-shaped moon, with its near end perpetually facing Earth, is one
example. Being placed at different distances from Earth, the near and far elongated ends
experience dissimilar gravitational forces, resulting in a net gravitational torque if the
line between the two ends ever falls out of alignment with the center of the Earth.
You can model such torques in Simscape Multibody by modeling the different
gravitational forces acting on a body. You do this using the Inverse Square Law Force
or Gravitational Field block. If you use the Inverse Square Law Force block, you must
create additional frames in each body whose response to gravitational torque you want
to model. You must then apply a gravitational force to each frame explicitly. The figure
shows an example.
Torque on the moon due to dissimilar gravitational forces at the elongated ends
4-7
4 Internal Mechanics, Actuation and Sensing
If you use the Gravitational Field block, you must split each body into discrete
sections and connect them through Weld Joint blocks. The Gravitational Field block
automatically applies a force at the center of mass of each section, approximating the
compound effect of the different gravitational forces on the body—which in this case is
treated as a rigid multibody system. The figure shows an example.
Torque on the moon due to dissimilar gravitational forces at the elongated ends
4-8
Model Planetary Orbit Due to Gravity
In this section...
“Model Overview” on page 4-9
“Build Model” on page 4-11
“Configure Simulation Parameters” on page 4-16
“Simulate Model” on page 4-17
“Add Remaining Planets” on page 4-18
Model Overview
In this tutorial, you model planet orbit in our solar system due to gravity. The planets
are treated as spheres, each with three translational and zero rotational degrees of
freedom with respect to a fixed world frame. Cartesian Joint blocks provide these degrees
of freedom. Gravitational Field blocks generate the attractive forces that keep the
planets in orbit.
For simplicity, the tutorial assumes that each planet is at aphelion at simulation time
zero. Aphelion is the point of greatest distance from the sun. It corresponds to the
minimum orbital velocity of a given planet.
4-9
4 Internal Mechanics, Actuation and Sensing
Placing the planets simultaneously at aphelion while neglecting orbital parameters such
as inclination and longitude of ascension node causes them to align on a single axis. In
the tutorial, aphelion lies on the X axis at a distance Px from the sun. The planet velocity
at aphelion is orthogonal to the line joining the planet to the sun. It points along the Y
axis with magnitude Vy.
The procedure in this tutorial shows how you can model the gravitational interaction
between Earth and the sun. In this procedure, you add two Cartesian Joint blocks. One
block, connected between the Earth reference frame and the World frame, provides three
translational degrees of freedom to Earth. The other block, connected between the Sun
reference frame and the World frame, provides the same to the sun, allowing it too to
move under the gravitational pull of Earth. Planet spin is ignored.
Similarly, you add two Gravitational Field blocks to the model. One block, connected to
the sun reference frame, represents the gravitational field of the sun. This field exerts an
attractive pull on Earth, but it has no effect on the sun itself. To represent the attractive
pull of Earth on the sun, you connect the second Gravitational Field block to the Earth
reference frame.
When using the Gravitational Field block, you must set the Uniform Gravity
parameter of the Mechanism Configuration block to None. This step prevents conflicting
gravity sources in your model. If you forget to take this step, Simscape Multibody throws
an error and the model does not simulate.
The figure shows the key blocks in this model and their connections. Note that you must
add other blocks, such as Solver Configuration, for the model to simulate.
4-10
Model Planetary Orbit Due to Gravity
Build Model
Start by modeling the gravitational interaction between the sun and the earth. This
model shows the approach to use when you add the remaining planets to the model.
Except where noted, the blocks you use are from the Simscape Multibody library.
Start Model
Library Block
Utilities Mechanism Configuration
Frames and Transforms World Frame
Simscape Utilities Solver Configuration
3 Connect the blocks as shown.
4-11
4 Internal Mechanics, Actuation and Sensing
4 In the Mechanism Configuration block dialog box, set Uniform Gravity to None.
This change enables you to specify gravity using a Gravitational Field block instead.
Add Sun
1 Add these blocks to the model. The blocks represent the sun: its solid properties,
its gravitational pull on other bodies, and its degrees of freedom with respect to the
(fixed) World frame.
Library Block
Body Elements Solid
Forces and Torques Gravitational Field
Joints Cartesian Joint
2 Connect the blocks as shown. Note that each line joining two or more frame ports
represents a single frame. The R, B, and F port frames of the Sun, Sun Gravity, and
Sun Translational DOFs blocks are coincident with each other.
4-12
Model Planetary Orbit Due to Gravity
3 In the Sun block dialog box, specify these parameters. These variables are the
solid properties of the sun. You define their numerical values later in the model
workspace.
In the previous two steps, you specified the sun mass in two blocks, Sun and Sun
Gravity, using a single variable, Sun.M. This approach ensures the two blocks, both
of which represent the sun, use the same mass.
4-13
4 Internal Mechanics, Actuation and Sensing
Add Earth
1 Add these blocks to the model. The blocks represent Earth: its solid properties, its
gravitational pull on other bodies, and its degrees of freedom with respect to the
(fixed) World frame.
Library Block
Body Elements Solid
Forces and Torques Gravitational Field
Joints Cartesian Joint
2 Connect the blocks as shown. The R, B, and F port frames of the Earth, Earth
Gravity, and Earth Translational DOFs blocks are coincident with each other.
3 In the Earth block dialog box, specify these parameters. These variables are the solid
properties of Earth. You define their numerical values later in the model workspace.
4-14
Model Planetary Orbit Due to Gravity
4-15
4 Internal Mechanics, Actuation and Sensing
%% Sun Parameters
% Scale sun size for visualization purposes
SunScaling = 1e2;
%% Earth Parameters
% Scale Earth size for visualization purposes
TerrestrialPlanetScaling = 1.2e3; % Scale the size of Earth
4-16
Model Planetary Orbit Due to Gravity
Simulate Model
Update the block diagram, e.g., by pressing Ctrl+D with the model window active.
Mechanics Explorer opens with a static 3-D display of the model in its initial state.
Adjust the viewpoint and zoom level to optimize visualization on your screen.
Run the simulation, e.g., by pressing Ctrl+T. Mechanics Explorer plays a physics-based
animation of the solar system. At the default value of the base playback speed, planet
motion is hardly noticeable. Increase this value to watch Earth complete one revolution
about the sun in 10 seconds:
4-17
4 Internal Mechanics, Actuation and Sensing
The table shows the relevant parameters for each planet. To better visualize the planets,
consider scaling the radius parameters. For example, you can multiply the terrestrial
planet radii by a common scaling factor (e.g., TerrestrialPlanetScaling), and the
gas giant planets by another common scaling factor (e.g., GasGiantScaling).
If you struggle with the remaining planets, you can open a completed model of the solar
system. At the MATLAB command prompt, enter:
These models include Rigid Transform blocks to account for orbit inclination and
longitude of ascension node.
Note that gravity is an inverse-square law force. That is, the force magnitude decays
with the square distance between a body and the field source mass. As such, you can
model the gravitational force between two bodies using the Inverse Square Law Force
block. However, this block applies a force only between its two port frames. Use this
approach to neglect secondary gravitational interactions, e.g., if orbital perturbations due
to planet-planet interactions are irrelevant to your application.
4-18
Model Planetary Orbit Due to Gravity
Open these models to see how to model the solar system using the Inverse Square Law
Force block instead:
These models account only for the gravitational interactions between sun-planet pairs.
4-19
4 Internal Mechanics, Actuation and Sensing
Joint Actuation
In this section...
“Actuation Modes” on page 4-20
“Motion Input” on page 4-23
“Input Handling” on page 4-25
“Assembly and Simulation” on page 4-26
Actuation Modes
Joint blocks provide two actuation parameters. These parameters, Force/Torque and
Motion, govern how the joint behaves during simulation. Depending on the parameter
settings you select, a joint block can accept either actuation parameter as input or
automatically compute its value during simulation.
An additional setting (None) allows you to set actuation force/torque directly to zero. The
joint primitive is free to move during simulation, but it has no actuator input. Motion is
due indirectly to forces and torques acting elsewhere in the model, or directly to velocity
state targets.
Like all joint block parameters, you select the actuation parameter settings for each joint
primitive separately. Different joint primitives in the same block need not share the
same actuation settings. Using a Pin Slot Joint block, for example, you can provide
motion input and have actuation torque automatically computed for the Z Revolute
Primitive (Rz), while having motion automatically computed with no actuation force for
the X Prismatic Primitive (Px).
4-20
Joint Actuation
By combining different Force/Torque and Motion actuation settings, you can achieve
different joint actuation modes. Forward dynamics and inverse dynamics modes are two
common examples. You actuate a joint primitive in forward dynamics mode by providing
actuation force/torque as input while having motion automatically computed. Conversely,
you actuate a joint primitive in inverse dynamics mode by providing motion as input
while having actuation force/torque automatically computed.
Other joint actuation modes, including fully computed and fully specified modes, are
possible. The table summarizes the different actuation modes that you can obtain by
manipulating the actuation parameter settings.
4-21
4 Internal Mechanics, Actuation and Sensing
By selecting the joint actuation settings based on the answers to these questions, you can
ensure that each joint is properly set for your application. The figure shows the proper
settings depending on your answers.
4-22
Joint Actuation
Motion Input
The motion input of a joint primitive is a timeseries object specifying that primitive’s
trajectory. For a prismatic primitive, that trajectory is the position coordinate along the
primitive axis, given as a function of time. The coordinate provides the position of the
follower frame origin with respect to the base frame origin. The primitive axis is resolved
in the base frame.
For a revolute primitive, the trajectory is the angle about the primitive axis, given as a
function of time. This angle provides the rotation of the follower frame with respect to the
base frame about the primitive axis. The axis is resolved in the base frame.
Spherical joint primitives provide no motion actuation options. You can specify actuation
torque for these primitives, but you cannot prescribe their trajectories. Those trajectories
are always automatically computed from the model dynamics during simulation.
4-23
4 Internal Mechanics, Actuation and Sensing
Unlike Actuation > Force/Torque, the Actuation > Motion parameter provides no
zero input option, corresponding to a fixed joint primitive during simulation. You can,
however, prescribe zero motion the same way you prescribe all other types of motion:
using Simscape and Simulink blocks.
In Simscape Multibody, motion input signals are position-centric. You specify the joint
primitive position and, if filtered to the second-order, the Simulink-PS Converter
block smooths the signal while providing its two time-derivatives automatically. This
behavior makes zero motion prescription straightforward: just provide a constant signal
to the motion actuation input port of the joint primitive and simulate.
4-24
Joint Actuation
Input Handling
When prescribing a joint primitive trajectory, it is practical to specify a single input, the
position, and filter that input using a Simulink-PS Converter block. This filter, which
must of second-order, automatically provides the two time derivatives of the motion
input. Because it also smooths the input signal, the filter can help prevent simulation
issues due to sudden changes or discontinuities, such as those present when using a
Simulink Step block.
Filtering smooths the input signal over a time scale of the order of the input filtering
time constant. The larger the time constant, the greater the signal smoothing, and the
more distorted the signal tends to become. The smaller the time constant, the closer the
filtered signal is to the input signal, but also the greater the model stiffness—and, hence,
the slower the simulation.
As a guideline, the input filtering time constant should be only as small as the smallest
relevant time scale in a model. By default, its value is 0.001 s. While appropriate for
4-25
4 Internal Mechanics, Actuation and Sensing
many models, this value is often too small for Simscape Multibody models. For faster
simulation, start with a value of 0.01 s. Decrease this value for greater accuracy.
If you know the two time derivatives of the motion input signal, you can specify
them directly. This approach is most convenient for simple trajectories with simple
derivatives. You must, however, ensure that the two derivative signals are compatible
with the position signal. If they are not, even when simulation proceeds, results may be
inaccurate.
Note: You obtain the assembled state each time you update the block diagram, e.g.,
by pressing Ctrl+D. You obtain the initial simulation state each time you run the
simulation, e.g., by pressing Ctrl+T, and pausing at time zero.
Due to the discrepancy between the two states, Model Report provides accurate initial
state data only for models lacking motion inputs. For models possessing motion inputs,
that data is accurate only when the initial position prescribed by the motion input signal
exactly matches the initial position prescribed in the joint state targets.
Similarly, Mechanics Explorer displays the initial joint states accurately only for models
lacking motion inputs. As it transitions from the assembled state to the initial simulation
state, Mechanics Explorer may show a sudden jump if a model contains motion inputs
that are incompatible with the joint state targets. You can eliminate the sudden change
by making the initial position prescribed by joint motion inputs equal to the initial
position prescribed by the joint state targets.
4-26
Joint Actuation
Related Examples
• “Prescribe Joint Motion in Planar Manipulator Model” on page 4-105
• “Prescribe Joint Motion in Four-Bar Model” on page 4-100
• “Specify Motion Input Derivatives” on page 4-28
4-27
4 Internal Mechanics, Actuation and Sensing
1 Open the dialog box of the Simulink-PS Converter block and click Input Handling.
2 In Filtering and derivatives, select Filter input.
3 In Input filtering order, select Second-order filtering.
4 In Input filtering time constant (in seconds), enter the characteristic time over
which filter smooths the signal. A good starting value is 0.01 seconds.
If providing the input derivatives directly, you must first compute those derivatives.
Then, using the Simulink-PS Converter block, you can provide them to the target joint
block. To specify the input derivatives directly:
1 Open the Simulink-PS Converter block receiving the input signal and click the
Input Handling tab.
2 In Filtering and derivatives, select Provide input derivative(s).
3 To specify both derivatives, in Input derivatives, select Provide first and
second derivatives.
The block displays two additional physical signal ports, one for each derivative.
Related Examples
• “Prescribe Joint Motion in Planar Manipulator Model” on page 4-105
• “Prescribe Joint Motion in Four-Bar Model” on page 4-100
More About
• “Joint Actuation” on page 4-20
4-28
Joint Actuation Limitations
In models not meeting this condition, you can replace a rigid connection line between
two Solid blocks with a Weld Joint block. Since the Weld Joint block represents a rigid
connection, this approach leaves the model dynamics unchanged. The advantage of this
approach lies in its ability to satisfy the Simscape Multibody closed-loop requirement
without altering model dynamics.
4-29
4 Internal Mechanics, Actuation and Sensing
Models that have more degrees of freedom with automatically computed actuation forces/
torques than with prescribed motion inputs cause simulation errors.
Related Examples
• “Prescribe Joint Motion in Planar Manipulator Model” on page 4-105
• “Prescribe Joint Motion in Four-Bar Model” on page 4-100
• “Specify Motion Input Derivatives” on page 4-28
More About
• “Joint Actuation” on page 4-20
4-30
Actuating and Sensing Using Physical Signals
Some Simscape Multibody blocks provide physical signal ports for actuation input or
sensing output. These ports accept or output only Simscape physical signals. If you wish
to connect these ports to Simulink blocks, you must use the Simscape converter blocks.
The table summarizes the converter blocks that Simscape provides. You can find both
blocks in the Simscape Utilities library.
Block Summary
PS-Simulink Converter Convert Simscape physical signal into
Simulink signal
Simulink-PS Converter Convert Simulink signal into Simscape
physical signal
4-31
4 Internal Mechanics, Actuation and Sensing
In the figure, the connection line that connects to the input port of the Simulink-PS
Converter block represents the original Simulink signal. The connection line that
connects to the output port of the same block represents the converted physical signal.
This is the signal that you must connect to the actuation ports in Simscape Multibody
blocks.
1 Connect the Simscape Multibody sensing port to the input port of a PS-Simulink
Converter block.
2 Connect the output port of the PS-Simulink Converter block to the Simulink
block of your choice.
The figure shows how you can connect a Simscape Multibody sensing signal to a
Simulink Scope block.
4-32
Actuating and Sensing Using Physical Signals
4-33
4 Internal Mechanics, Actuation and Sensing
Sensing
In this section...
“Sensing Overview” on page 4-34
“Variables You Can Sense” on page 4-35
“Blocks with Sensing Capability” on page 4-35
“Sensing Output Format” on page 4-35
Sensing Overview
Sensing enables you to perform analytical tasks on a model. For example, you can
perform inverse dynamic analysis on a robotic manipulator model. By prescribing the
end-effector trajectory and sensing the joint actuation forces and torques, you can obtain
the time-varying profile of each joint actuation input.
The variables you prescribe, the model inputs, and those you sense, the model outputs,
determine which types of analysis you can perform. By changing the model inputs
and outputs, you can perform numerous other analysis types. For example, to perform
forward kinematic analysis on the robotic manipulator model, you can prescribe the
manipulator joint trajectories and sense the resulting end-effector trajectory.
4-34
Sensing
• Motion variables — Linear and angular position, velocity, and acceleration. Linear
variables are available in different coordinate systems, including Cartesian, spherical,
and cylindrical. Angular variables are available in different formats, including
quaternion, axis-angle, and transform matrix.
• Force and torque variables — Actuation, constraint, and total forces and torques
acting at a joint, as well as certain forces and torques acting outside of a joint.
• Joint blocks — Motion sensing between the base and follower port frames of a joint
block. Variables that you can sense are organized by joint primitive (prismatic,
revolute, or spherical).
• Transform Sensor block — Motion sensing between any two frames in a model.
This block provides the most comprehensive motion sensing capability in Simscape
Multibody.
• Joint blocks — Actuation, constraint, and total force and torque sensing between the
base and follower port frames. Actuation force and torque sensing is arranged by joint
primitive.
• Constraint blocks — Constraint force and torque between the base and follower port
frames.
• Certain Forces and Torques blocks — Total force the block exerts between the base
and follower port frames. Only certain Forces and Torques blocks provide this type of
sensing. Blocks that do include Spring and Damper Force and Inverse Square
Law Force.
4-35
4 Internal Mechanics, Actuation and Sensing
the Scope block. For information on how to use physical signals in Simscape Multibody
models, see “Actuating and Sensing Using Physical Signals” on page 4-31.
4-36
Force and Torque Sensing
In this section...
“Blocks with Force and Torque Sensing” on page 4-37
“Joint Forces and Torques You can Sense” on page 4-38
“Force and Torque Measurement Direction” on page 4-40
• Forces and Torques — Sense the magnitude of certain forces not explicitly provided by
input. Blocks with force sensing include Inverse Square Law Force and Spring
and Damper Force. Each block can sense only the magnitude of its own force.
• Joints — Sense various forces and torques acting directly at a joint. All joint blocks
provide force and torque sensing. However, the specific force and torque types that
you can sense vary from joint to joint. Force and torque sensing is available strictly
between the rigid bodies the joint connects.
4-37
4 Internal Mechanics, Actuation and Sensing
• Joint primitive forces and torques. Each such force or torque is individually computed
for a given joint primitive. Joint actuator forces and torques belong to this category.
• Composite forces and torques. Each such force or torque is computed in aggregate for
an entire joint. Constraint and total forces and torques belong to this category.
4-38
Force and Torque Sensing
The figure shows a basic example of these forces acting on a crank-slider piston.
In the figure:
• FA is the actuator force, which drives the piston toward the crank link.
• FI is the internal spring and damper force, which resists motion of the piston with
respect to the chamber.
• FC is the constraint force, which opposes the effect of gravity on the piston, preventing
it from falling.
4-39
4 Internal Mechanics, Actuation and Sensing
The total force equals the net sum of FA, FI, and FC.
• Follower on base — Sense the force or torque that the follower port frame exerts on
the base port frame.
• Base on follower — Sense the force or torque that the base port frame exerts on the
follower port frame.
The figure shows the effect of reversing the measurement direction. Reversing this
direction changes the measurement sign.
4-40
Motion Sensing
Motion Sensing
In this section...
“Sensing Spatial Relationship Between Joint Frames” on page 4-41
“Sensing Spatial Relationship Between Arbitrary Frames” on page 4-43
In Simscape Multibody, you can sense the spatial relationship between two frames using
two types of blocks:
• Transform Sensor — Sense the spatial relationship between any two frames in a
model. Parameters that you can sense with this block include position, velocity, and
acceleration of the linear and angular types. This block provides the most extensive
motion sensing capability in the Simscape Multibody libraries.
• Joint blocks — Sense the spatial relationship between the base and follower frames of
a Joint block. Parameters that you can sense with a Joint block include the position
and its first two time derivatives (velocity and acceleration) for each joint primitive.
These blocks output a physical signal for each measurement that you specify. You can
use the sensing output of these blocks for analysis or as input to a control system in a
model.
The sensing capability of a joint block is limited to the base and follower frames of that
joint block. Every measurement provides the value of a parameter for the joint follower
frame with respect to the joint base frame. If sensing the spatial relationship with a
spherical joint primitive, you can also select the frame to resolve the measurement in. To
sense the spatial relationship between any other two frames, use the Transform Sensor
block instead.
If the joint primitive is of the revolute or spherical type, the parameters correspond to
the rotation angle, angular velocity, and angular acceleration, respectively. If the joint
4-41
4 Internal Mechanics, Actuation and Sensing
primitive is of the prismatic type, the parameters correspond to the offset distance, linear
velocity, and linear acceleration, respectively.
Regardless of joint primitive type, each parameter that you select applies only to the joint
primitive it belongs to. For example, selecting Position in the Z Revolute Primitive
(Rz) > Sensing menu exposes a physical signal port that outputs the rotation angle of
the follower frame with respect to the base frame about the base frame Z axis.
The table lists the port label for each parameter that you can sense using a joint block.
The first column of the table identifies the parameters that you can select. The remaining
three columns identify the port labels for the three joint primitive menus that the dialog
box can contain: Spherical, Revolute, and Prismatic.
Note: For parameter descriptions, see the reference pages for Spherical Joint,
Revolute Joint, and Prismatic Joint blocks.
A joint block can contain multiple revolute and prismatic joint primitives. For blocks with
multiple primitives of the same type, the port labels include an extra letter identifying
the joint primitive axis. For example, the Position port label for the Z prismatic
primitive of a Cartesian Joint block is pz.
1 Open the dialog box for the joint block to sense the spatial relationship across.
2 In the Sensing menu of the block dialog box, select the parameters to sense.
The block exposes one physical signal port for each parameter that you select. The label
of each port identifies the parameter that port outputs.
4-42
Motion Sensing
Every measurement provides the value of a parameter for the follower frame with
respect to the base frame, resolved in the measurement frame that you choose. You
can connect the base and follower frame ports of the Transform Sensor block to any
two frames in a model. To measure a parameter for a different frame, connect the
follower frame port to the frame line or port that identifies that frame. Likewise, to
measure a parameter for the same frame but with respect to a different frame, connect
the base frame port to the frame line or port that identifies that frame. Finally, to
resolve a measurement in a different frame, select a different measurement frame in the
block dialog box. For more information about measurement frames, see “Measurement
Frames” on page 4-59. For more information about frame lines and ports, see
“Representing Frames” on page 1-6.
Selecting a parameter from the block dialog box exposes the corresponding physical
signal port in the block. Use this port to output the measurement for that parameter. To
identify the port associated with each parameter, each port uses a unique label.
The table lists the port labels for each angular parameter that you can sense. The first
column of the table identifies the parameters that you can select. The remaining three
columns identify the port labels for the three angular parameter menus in the dialog box:
Rotation, Angular Velocity, and Angular Acceleration. Certain parameters belong
to one menu but not to others. N/A identifies the parameters that do not belong to a given
menu—e.g. Angle, which is absent from the Angular Velocity.
Note: For parameter descriptions, see the Transform Sensor reference page.
4-43
4 Internal Mechanics, Actuation and Sensing
The table lists the port labels for each linear parameter that you can sense. As in the
previous table, the first column identifies the parameters that you can select. The
remaining three columns identify the port labels for the three linear parameter menus in
the dialog box: Translation, Velocity, and Acceleration.
The block exposes one physical signal port for each parameter that you select. The label
of each port identifies the parameter that port outputs.
Related Examples
• “Sense Motion in Double-Pendulum Model” on page 4-62
• “Actuate Joint in Four-Bar Model” on page 4-68
4-44
Motion Sensing
More About
• “Rotational Measurements” on page 4-46
• “Translational Measurements” on page 4-51
• “Measurement Frames” on page 4-59
4-45
4 Internal Mechanics, Actuation and Sensing
Rotational Measurements
In this section...
“Rotation Sensing Overview” on page 4-46
“Measuring Rotation” on page 4-46
“Axis-Angle Measurements” on page 4-46
“Quaternion Measurements” on page 4-47
“Transform Measurements” on page 4-49
Measuring Rotation
Rotation is a relative quantity. The rotation of one frame is meaningful only with respect
to another frame. As such, blocks with rotation sensing capability require two frames
to make a measurement: measured and reference frames. In these blocks, the follower
frame port identifies the measured frame; the base frame port identifies the reference
frame of the measurement.
Axis-Angle Measurements
Axis-angle is one of the simpler rotation measurement formats. This format uses two
parameters to completely describe a rotation: axis vector and angle. The usefulness of
the axis-angle format follows directly from Euler’s rotation theorem. According to the
4-46
Rotational Measurements
theorem, any 3–D rotation or rotation sequence can be described as a pure rotation about
a single fixed axis.
To measure frame rotation in axis-angle format, use the Transform Sensor block. The
block dialog box contains separate Axis and Angle parameters that you can select to
expose the corresponding physical signal (PS) ports (labeled axs and q, respectively).
Because the axis-angle parameters are listed separately, you can choose to measure the
axis, the angle, or both.
The axis output is a 3–D unit vector in the form [ax, ay, az]. This unit vector encodes the
rotation direction according to the right-hand rule. For example, a frame spinning in a
counterclockwise direction about the +X axis has rotation axis [1 0 0]. A frame spinning
in a clockwise direction about the same axis has rotation axis [-1 0 0].
The angle output is a scalar number in the range 0–π. This number encodes the extent
of rotation about the measured axis. By default, the angle is measured in radians. You
can change the angle units in the PS-Simulink Converter block used to interface with
Simulink blocks.
Quaternion Measurements
The quaternion is a rotation representation based on hypercomplex numbers. This
representation uses a 4-vector containing one scalar (S) and three vector components (Vx,
4-47
4 Internal Mechanics, Actuation and Sensing
Vy, Vz). The scalar component encodes the rotation angle. The vector components encode
the rotation axis.
• Transform Sensor block, if measuring rotation between two general frames. The
Rotation menu of the dialog box contains a Quaternion option that you can select to
expose the corresponding physical signal port (labeled Q).
• Joint block possessing spherical primitive, if measuring 3–D rotation between the two
joint frames. The Sensing menu of the dialog box contains a Position option that you
can select to expose the corresponding physical signal port (also labeled Q). For more
information, see Spherical Joint block reference page.
Q = (S V )
The quaternion output is a 4-element row vector , where:
4-48
Rotational Measurements
S = cos q( 2)
and
q
V = [Vx V y Vz ]sin
2
θ is the rotation angle. The angle can take any value between 0–π. [Vx, Vy, Vz] is the
rotation axis. Axis components can take any value between 0–1.
Transform Measurements
The rotation transform is a 3×3 matrix that encodes frame rotation. In terms of base
frame axes [x, y, z]B, the follower frame axes [x, y, z]F are:
Èr rxy rxz ˘ È x ˘
Èx ˘ Í xx ˙
Í y˙ = Ír ryy ryz ˙ ÍÍ y ˙˙
Í ˙ Í
yx
˙
ÍÎ z ˙˚ Í r rzy rzz ˙ ÍÎ z ˙˚ F
B Î zx ˚
Each matrix column contains the coordinates of a follower frame axis resolved in the base
frame. For example, the first column contains the coordinates of the follower frame X-
axis, as resolved in the base frame. Similarly, the second and third columns contain the
coordinates of the Y and Z-axes, respectively. Operating on a vector with the rotation
matrix transforms the vector coordinates from the follower frame to the base frame.
You can sense frame rotation in terms of a rotation matrix using the Transform Sensor
block. The dialog box for this block contains a Transform option that when selected
exposes a physical signal port labeled R. Use this port to output the rotation matrix
signal, for example, for processing and analysis in a Simulink subsystem—after
converting the output physical signal to a Simulink signal through the PS-Simulink
Converter block.
4-49
4 Internal Mechanics, Actuation and Sensing
Related Examples
• “Sense Motion in Double-Pendulum Model” on page 4-62
• “Actuate Joint in Four-Bar Model” on page 4-68
More About
• “Motion Sensing” on page 4-41
• “Translational Measurements” on page 4-51
• “Measurement Frames” on page 4-59
4-50
Translational Measurements
Translational Measurements
In this section...
“Translation Sensing Overview” on page 4-51
“Measuring Translation” on page 4-51
“Cartesian Measurements” on page 4-52
“Cylindrical Measurements” on page 4-54
“Spherical Measurements” on page 4-56
Measuring Translation
Translation is a relative quantity. The translation of one frame is meaningful only with
respect to another frame. As such, blocks with translation sensing capability require
two frames to make a measurement: measured and reference frames. In these blocks,
the follower frame port identifies the measured frame; the base frame port identifies the
reference frame of the measurement.
Some measurements are common to multiple coordinate systems. One example is the
Z-coordinate, which exists in both Cartesian and cylindrical systems. In the Transform
Sensor dialog box, coordinates that make up more than one coordinate system appear
only once. Selecting Z outputs translation along the Z-axis in both Cartesian and
cylindrical coordinate systems.
Other measurements are different but share the same name. For example, radius is a
coordinate in both spherical and cylindrical systems. The spherical radius is different
from the cylindrical radius: the former is the distance between two frame origins; the
latter is the distance between one frame origin and a frame Z-axis.
4-51
4 Internal Mechanics, Actuation and Sensing
To differentiate between the two radial coordinates, Simscape Multibody uses the
following convention:
Cartesian Measurements
The Cartesian coordinate system uses three linear coordinates—X, Y, and Z—
corresponding to three mutually orthogonal axes. Cartesian translation measurements
have units of distance, with meter being the default. You can use the PS-Simulink
Converter block to select a different physical unit when interfacing with Simulink
blocks.
4-52
Translational Measurements
Transform Sensor
You can select any of the Cartesian axes in the Transform Sensor for translation sensing.
This is true even if translation is constrained along any of the Cartesian axes. Selecting
the Cartesian axes exposes physical signal ports x, y, and z, respectively.
The figure shows a simple model using a Transform Sensor block to measure frame
translation along all three Cartesian axes. The measurement gives the relative
translation of the follower port frame with respect to the base port frame. These frames
are, respectively, the Solid1 and Solid2 reference port frames. For more information, see
“Representing Frames” on page 1-6.
Joints
With joint blocks, you can sense translation along each prismatic primitive axis.
Selecting a sensing parameter from a prismatic primitive menu exposes the
corresponding physical signal port. For example, if you select Position from the Z
Prismatic Primitive (Pz) of a Cartesian Joint block, the block exposes physical signal
port z.
4-53
4 Internal Mechanics, Actuation and Sensing
The figure shows a simple model using a Cartesian Joint block to sense frame
translation along the three Cartesian axes. The measurement gives the relative
translation of the follower port frame with respect to the base port frame. These frames
coincide with the Solid1 and Solid reference port frames.
Cylindrical Measurements
The cylindrical coordinate system uses one angular and two linear coordinates. The
linear coordinates are the cylinder radius, R, and length, Z. The angular coordinate is
the azimuth, ϕ, about the length axis. Linear coordinates have units of distance, with
meter being the default. The angular coordinate has units of angle, with radian being the
4-54
Translational Measurements
default. You can use the PS-Simulink Converter block to select a different physical
unit when interfacing with Simulink blocks.
Transform Sensor
Only the Transform Sensor block can sense frame translation in cylindrical coordinates.
In the dialog box of this block, you can select one or more cylindrical coordinates to
measure. The cylindrical coordinates are named Z, Radius, and Azimuth. Selecting the
cylindrical coordinates exposes physical signal ports z, rad, and azm, respectively.
The figure shows a simple model using a Transform Sensor block to measure frame
translation along all three cylindrical axes. The measurement gives the relative
translation of the follower port frame with respect to the base port frame. These frames
are, respectively, the Solid1 and Solid2 reference port frames.
4-55
4 Internal Mechanics, Actuation and Sensing
Spherical Measurements
The spherical coordinate system uses two angular coordinates and one linear coordinate.
The linear coordinate is the spherical radius, R. The angular coordinates are the
azimuth, ϕ, and inclination, θ. The linear coordinate has units of distance, with meter
being the default. The angular coordinates have units of angle, with radian being the
default. You can use the PS-Simulink Converter block to select a different physical
unit when interfacing with Simulink blocks.
4-56
Translational Measurements
Transform Sensor
Only the Transform Sensor block can sense frame translation in spherical coordinates. In
the dialog box of this block, you can select one or more spherical coordinates to measure.
The spherical coordinates are named Azimuth, Distance, and Inclination. Selecting
the spherical coordinates exposes physical signal ports azm, dst, and inc, respectively.
Note: Azimuth belongs to both cylindrical and spherical systems. Distance is the
spherical radius.
The figure shows a simple model using a Transform Sensor block to measure frame
translation along all three spherical axes. The measurement gives the relative
translation of the follower port frame with respect to the base port frame. These frames
are, respectively, the Solid1 and Solid2 reference port frames.
4-57
4 Internal Mechanics, Actuation and Sensing
Related Examples
• “Sense Motion in Double-Pendulum Model” on page 4-62
• “Actuate Joint in Four-Bar Model” on page 4-68
More About
• “Motion Sensing” on page 4-41
• “Rotational Measurements” on page 4-46
• “Measurement Frames” on page 4-59
4-58
Measurement Frames
Measurement Frames
In this section...
“Measurement Frame Purpose” on page 4-59
“Measurement Frame Types” on page 4-60
You can sense the spatial relationship between two frames. When you do so, Simscape
Multibody resolves the measurement in a measurement frame. For most joint blocks, the
measurement frame is the base frame. However, if you use either Transform Sensor
or a joint block with a spherical primitive, you can select a different measurement frame.
Measurement frames that you can select include Base, Follower, and World. The
Transform Sensor block adds the choice between rotating and non-rotating versions of
the base and follower frames.
The arrow connecting base and follower frame origins is the translation vector. If you
select the base frame as the measurement frame, Simscape Multibody resolves that
4-59
4 Internal Mechanics, Actuation and Sensing
translation vector along the axes of the base frame. If you select the World frame as the
measurement frame, Simscape Multibody instead resolves the translation vector along
the axes of the World frame. The translation vector remains the same, but the frame
Simscape Multibody expresses that measurement in changes.
Note that you can select the measurement frame only with certain blocks. Among joint
blocks, only those with a spherical primitive offer a selection of measurement frames. All
other joint blocks resolve their measurements in the base frame. The Transform Sensor
block offers the most extensive selection of measurement frames.
4-60
Measurement Frames
Related Examples
• “Sense Motion in Double-Pendulum Model” on page 4-62
• “Actuate Joint in Four-Bar Model” on page 4-68
More About
• “Motion Sensing” on page 4-41
• “Rotational Measurements” on page 4-46
• “Translational Measurements” on page 4-51
4-61
4 Internal Mechanics, Actuation and Sensing
In this section...
“Model Overview” on page 4-62
“Modeling Approach” on page 4-63
“Build Model” on page 4-63
“Guide Model Assembly” on page 4-65
“Simulate Model” on page 4-65
“Save Model” on page 4-67
Model Overview
The Transform Sensor block provides the broadest motion-sensing capability in Simscape
Multibody models. Using this block, you can sense motion variables between any two
frames in a model. These variables can include translational and rotational position,
velocity, and acceleration.
In this example, you use a Transform Sensor block to sense the lower link translational
position with respect to the World frame. You output the position coordinates directly
to the model workspace, and then plot these coordinates using MATLAB commands.
By varying the joint state targets, you can analyze the lower-link motion under quasi-
periodic and chaotic conditions.
4-62
Sense Motion in Double-Pendulum Model
Modeling Approach
In this example, you rely on gravity to cause the double pendulum to move. You displace
the links from equilibrium and then let gravity act on them. To displace the links at time
zero, you use the State Targets section of the Revolute Joint block dialog box. You can
specify position or velocity. When you are ready, you simulate the model to analyze its
motion.
To sense motion, you use the Transform Sensor block. First, you connect the base and
follower frame ports to the World Frame and lower link subsystem blocks. By connecting
the ports to these blocks, you can sense motion in the lower link with respect to the
World frame. Then, you select the translation parameters to sense. By selecting Y and
Z, you can sense translation along the Y and Z axes, respectively. You can plot these
coordinates with respect to each other and analyze the motion that they reveal.
Build Model
1 At the MATLAB command prompt, enter smdoc_double_pendulum. A double
pendulum model opens up. For instructions on how to create this model, see “Model
Double Pendulum” on page 3-15.
4-63
4 Internal Mechanics, Actuation and Sensing
4-64
Sense Motion in Double-Pendulum Model
1 In the Revolute Joint block dialog box, select State Targets > Specify Position
Target.
2 Set Value to 10 deg.
3 In the Revolute Joint1 block dialog box, check that State Targets > Specify
Position Target is cleared.
Simulate Model
Run the simulation. Mechanics Explorer plays a physics-based animation of the double
pendulum assembly.
You can now plot the position coordinates of the lower link. To do this, at the MATLAB
command line, enter:
figure;
plot(y_link.data, z_link.data, 'color', [60 100 175]/255);
xlabel('Y Coordinate (cm)');
ylabel('Z Coordinate (cm)');
4-65
4 Internal Mechanics, Actuation and Sensing
grid on;
The figure shows the plot that opens. This plot shows that the lower link path varies only
slightly with each oscillation. This behavior is characteristic of quasi-periodic systems.
By adjusting the revolute joint state targets, you can simulate the model under chaotic
conditions. One way to obtain chaotic motion is to rotate the top revolute joint by a large
angle. To do this, in the Revolute Joint dialog box, change State Targets > Position >
Value to 90 and click OK.
Simulate the model with the new joint state target. To plot the position coordinates of the
lower pendulum link with respect to the world frame, at the MATLAB command prompt,
enter this code:
figure;
plot(y_link.data, z_link.data, 'color', [60 100 175]/255);
xlabel('Y Coordinate (cm)');
ylabel('Z Coordinate (cm)');
4-66
Sense Motion in Double-Pendulum Model
grid on;
Save Model
Save the model in a convenient folder under the name double_pendulum_sensing.
You reuse this model in a subsequent tutorial, “Prescribe Joint Motion in Planar
Manipulator Model” on page 4-105.
4-67
4 Internal Mechanics, Actuation and Sensing
In this section...
“Model Overview” on page 4-68
“Four-Bar Linkages” on page 4-69
“Modeling Approach” on page 4-71
“Build Model” on page 4-72
“Simulate Model” on page 4-75
Model Overview
In Simscape Multibody, you actuate a joint directly using the joint block. Depending on
the application, the joint actuation inputs can include force/torque or motion variables. In
this example, you prescribe the actuation torque for a revolute joint in a four-bar linkage
model.
Transform Sensor blocks add motion sensing to the model. You can plot the sensed
variables and use the plots for kinematic analysis. In this example, you plot the coupler
curves of three four-bar linkage types: crank-rocker, double-crank, and double-rocker.
4-68
Actuate Joint in Four-Bar Model
Four-Bar Linkages
The four-bar linkage contains four links that interconnect with four revolute joints to
form a planar closed loop. This linkage converts the motion of an input link into the
motion of an output link. Depending on the relative lengths of the four links, a four-bar
linkage can convert rotation into rotation, rotation into oscillation, or oscillation into
oscillation.
Links
Links go by different names according to their functions in the four-bar linkage. For
example, coupler links transmit motion between crank and rocker links. The table
summarizes the different link types that you may find in a four-bar linkage.
Link Motion
Crank Revolves with respect to the ground link
Rocker Oscillates with respect to the ground link
Coupler Transmits motion between crank and
rocker links
Ground Rigidly connects the four-bar linkage to the
world or another subsystem
It is common for links to have complex shapes. This is especially true of the ground link,
which may be simply the fixture holding the two pivot mounts that connect to the crank
or rocker links. You can identify links with complex shapes as the rigid span between
two adjacent revolute joints. In example “Model Four Bar” on page 3-20, the rigid span
between the two pivot mounts represents the ground link.
Linkages
The type of motion conversion that a four-bar linkage provides depends on the types
of links that it contains. For example, a four-bar linkage that contains two crank links
converts rotation at the input link into rotation at the output link. This type of linkage
is known as a double-crank linkage. Other link combinations provide different types of
motion conversion. The table describes the different types of four-bar linkages that you
can model.
4-69
4 Internal Mechanics, Actuation and Sensing
Grashof Condition
The Grashof theorem provides the basic condition that the four-bar linkage must satisfy
so that at least one link completes a full revolution. According to this theorem, a four-
bar linkage contains one or more crank links if the combined length of the shortest
and longest links does not exceed the combined length of the two remaining links.
Mathematically, the Grashof condition is:
s+l ≤ p+q
where:
Grashof Linkages
• Crank-rocker
• Double-crank
• Double-rocker
By changing the ground link, you can change the Grashof linkage type. For example,
by assigning the crank link of a crank-rocker linkage as the ground link, you obtain a
double-crank linkage. The figure shows the four linkages that you obtain by changing the
ground link.
4-70
Actuate Joint in Four-Bar Model
Modeling Approach
In this example, you perform two tasks. First you add a torque actuation input to the
model. Then, you sense the motion of the crank and rocker links with respect to the
World frame. The actuation input is a torque that you apply to the joint connecting the
base to the crank link. Because you apply the torque at the joint, you can add this torque
directly through the joint block. The block that you add the actuation input to is called
Base-Crank Revolute Joint.
You add the actuation input to the joint block through a physical signal input port. This
port is hidden by default. To display it, you must select Provided by Input from the
Actuation > Torque drop-down list.
4-71
4 Internal Mechanics, Actuation and Sensing
You can then specify the torque value using either Simscape or Simulink blocks. If you
use Simulink blocks, you must use the Simulink-PS Converter block. This block
converts the Simulink signal into a physical signal that Simscape Multibody can use. For
more information, see “Actuating and Sensing Using Physical Signals” on page 4-31.
To sense crank and rocker link motion, you use the Transform Sensor block. With this
block, you can sense motion between any two frames in a model. In this example, you use
it to sense the [Y Z] coordinates of the crank and rocker links with respect to the World
frame.
The physical signal output ports of the Transform Sensor blocks are hidden by default.
To display them, you must select the appropriate motion outputs. Using the PS-
Simulink Converter, you can convert the physical signal outputs into Simulink
signals. You can then connect the resulting Simulink signals to other Simulink blocks.
In this example, you output the crank and rocker link coordinates to the workspace using
Simulink To Workspace blocks. The output from these blocks provide the basis for
phase plots showing the different link paths.
Build Model
Provide the joint actuation input, specify the joint internal mechanics, and sense the
position coordinates of the coupler link end frames.
1 At the MATLAB command prompt, enter smdoc_four_bar. A four bar model opens
up. For instructions on how to create this model, see “Model Four Bar” on page 3-20.
2 In the Base-Crank Revolute Joint block dialog box, in the Actuation > Torque
drop-down list, select Provided by Input. The block exposes a physical signal
input port, labeled t.
3 Drag these blocks into the model. The blocks enable you to specify the actuation
torque signal.
Library Block
Simulink > Sources Constant
Simscape > Utilities Simulink-PS Converter
4 Connect the blocks as shown in the figure. The new blocks are shaded gray.
4-72
Actuate Joint in Four-Bar Model
Real joints dissipate energy due to damping. You can specify joint damping directly
in the block dialog boxes. In each Revolute Joint block dialog box, under Internal
Mechanics > Damping, enter 5e-4 and press OK.
1 Add these blocks to the model. The blocks enable you to sense frame position during
simulation.
4-73
4 Internal Mechanics, Actuation and Sensing
• y_crank
• z_crank
• y_rocker
• z_rocker
5 Connect and name the blocks as shown in the figure, rotating them as needed.
Ensure that the To Workspace blocks with the z_crank and z_rocker variable names
connect to the z frame ports of the Transform Sensor blocks. The new blocks are
shaded gray.
4-74
Actuate Joint in Four-Bar Model
Simulate Model
Run the simulation. You can do this in the Simulink tool bar by clicking the run button.
Mechanics Explorer plays a physics-based animation of the four bar assembly.
4-75
4 Internal Mechanics, Actuation and Sensing
Once the simulation ends, you can plot the position coordinates of the coupler link end
frames, e.g., by entering the following code at the MATLAB command line:
figure;
plot(y_crank.data, z_crank.data, 'color', [60 100 175]/255);
hold;
plot(y_rocker.data, z_rocker.data, 'color', [210 120 0]/255);
xlabel('Y Coordinate (cm)');
ylabel('Z Coordinate (cm)');
axis equal; grid on;
The figure shows the plot that opens. This plot shows that the crank completes a full
revolution, while the rocker completes a partial revolution, e.g., it oscillates. This
behavior is characteristic of crank-rocker systems.
4-76
Actuate Joint in Four-Bar Model
Try simulating the model in double-crank mode. You can change the four-bar linkage
into a double-crank linkage by changing the binary link lengths according to the table.
Update and simulate the model. The figure shows the updated visualization display in
Mechanics Explorer.
4-77
4 Internal Mechanics, Actuation and Sensing
Plot the position coordinates of the coupler link end frames. At the MATLAB command
line, enter:
figure;
plot(y_crank.data, z_crank.data, 'color', [60 100 175]/255);
hold;
plot(y_rocker.data, z_rocker.data, 'color', [210 120 0]/255);
xlabel('Y Coordinate (cm)');
ylabel('Z Coordinate (cm)');
axis equal; grid on;
The figure shows the plot that opens. This plot shows that both links complete a full
revolution. This behavior is characteristic of double-crank linkages.
4-78
Actuate Joint in Four-Bar Model
4-79
4 Internal Mechanics, Actuation and Sensing
In this section...
“Model Overview” on page 4-80
“Build Model” on page 4-80
“Specify Block Parameters” on page 4-82
“Create Simulation Script” on page 4-83
“Run Simulation Script” on page 4-84
Model Overview
In this tutorial, you create a simple MATLAB script to simulate a four-bar model at
various coupler lengths. The script uses the coupler motion coordinates, obtained using
a Transform Sensor block, to plot the resulting coupler curve at each value of the coupler
length. For information on how to create the four-bar model used in this tutorial, see
“Model Four Bar” on page 3-20.
Build Model
1 At the MATLAB command prompt, enter smdoc_four_bar. A four-bar model opens
up. For instructions on how to create this model, see “Model Four Bar” on page 3-20.
4-80
Analyze Coupler Curves at Various Coupler Lengths
2 Under the mask of the Binary Link B block, connect a third Outport block as shown
in the figure. You can add an Outport block by copying and pasting Conn1 or Conn2.
The new block identifies the frame whose trajectory you plot in this tutorial.
3 Add the following blocks to the model. During simulation, the Transform Sensor
block computes and outputs the coupler trajectory with respect to the world frame.
• Translation > Y
• Translation > Z
The block exposes frame ports y and z, through which it outputs the coupler
trajectory coordinates.
5 Connect the blocks as shown in the figure. Be sure to flip the Transform Sensor block
so that its base frame port, labeled B, connects to the World Frame block.
4-81
4 Internal Mechanics, Actuation and Sensing
4-82
Analyze Coupler Curves at Various Coupler Lengths
4-83
4 Internal Mechanics, Actuation and Sensing
3 Save the script as sim_four_bar in the folder containing the four-bar model.
Simscape Multibody iteratively runs each simulation, adding the resulting coupler link
curve to the active plot. The figure shows the final plot.
4-84
Analyze Coupler Curves at Various Coupler Lengths
You can use the simple approach shown in this tutorial to analyze model dynamics at
various parameter values. For example, you can create a MATLAB script to simulate a
crank-slider model at different coupler link lengths, plotting for each simulation run the
constraint force acting on the piston.
4-85
4 Internal Mechanics, Actuation and Sensing
In this section...
“Overview” on page 4-86
“Open Model” on page 4-87
“Sense Actuation Torque” on page 4-87
“Sense Constraint Forces” on page 4-90
“Sense Total Forces” on page 4-92
Overview
Simscape Multibody provides force and torque sensing in joint blocks. You can use this
sensing capability to compute and output various types of forces and torques acting
directly at joints. Force and torque types that you can sense include those attributable to:
In this tutorial, you explore the different types of force and torque sensing that Simscape
Multibody joint blocks provide.
4-86
Sense Forces and Torques at Joints
Open Model
At the MATLAB command prompt, enter smdoc_rack_pinion_c. Simscape Multibody
opens a rack and pinion model that you can use to explore the force and torque sensing
capability of joint blocks.
4-87
4 Internal Mechanics, Actuation and Sensing
1 In the Revolute Joint block dialog box, select Z Revolute Primitive (Rz) > Sensing
> Actuator Torque. The block exposes a physical signal port, labeled t. This
port outputs the 3-D vector components of the joint actuator torque in a Simscape
physical signal.
2 Drag the following blocks into the model:
4-88
Sense Forces and Torques at Joints
4 Simulate the model, e.g., by pressing Ctrl+D. The To Workspace block outputs the
actuator torque signal into a time-series variable, simout, available in the MATLAB
base workspace.
5 At the MATLAB command prompt, enter:
figure;
plot(simout);
MATLAB plots the vector components of the joint actuator torque. All but the Z
component are zero throughout the simulation.
Compare the actuator torque plot to the original input signal in the Signal Builder
block. Neglecting any signal smoothing due to the second-order filtering, the two
signals are identical. The following figure shows the original input signal.
4-89
4 Internal Mechanics, Actuation and Sensing
Actuator force and torque sensing enables you to analyze the required forces and torques
to yield a prescribed joint trajectory. Use this feature in your model to perform inverse
dynamic and other types of analysis.
4-90
Sense Forces and Torques at Joints
figure;
plot(simout);
MATLAB plots the constraint force components with respect to time. All but one
component are zero throughout simulation. The Z component, which opposes the
gravity vector, is the only component needed to hold the joint frames in place.
Constraint forces ensure that weld joint frames remain fixed with respect to each other.
You can place a Weld Joint block inside a rigid body subsystem to sense the internal
forces and torques acting within that body during simulation. For an example of how you
can do this in a double pendulum model, see “Sense Internal Forces in Double-Pendulum
Link” on page 4-94.
4-91
4 Internal Mechanics, Actuation and Sensing
1 In the Revolute Joint block dialog box, select Composite Force/Torque Sensing >
Total Torque. The block exposes the physical signal port tt. This port outputs the
total torque acting between the joint frames as a Simscape physical signal.
2 Deselect Composite Force/Torque Sensing > Constraint Force.
3 Simulate the model.
4 At the MATLAB command prompt, enter:
figure;
plot(simout);
MATLAB plots the vector components of the total torque vector as a function of time.
All but one component are zero throughout simulation. The nonzero component, a
torque directed about the Z axis, contains torque contributions from actuation and
internal torques, but none from constraint torques.
4-92
Sense Forces and Torques at Joints
The torque peaks correspond to the actuation torque values specified in the input
signal. These peaks decay with time due to the internal damping torques specified
in the Revolute Joint block dialog box. The damping torques cause the energy
dissipation evident in the transient portions of the total torque plot.
To verify that the total torque excludes any contribution from constraint torques,
try sensing the constraint torques directly. A plot of the constraint torques will show
that they are in fact negligible.
4-93
4 Internal Mechanics, Actuation and Sensing
Model Overview
Simscape Multibody provides various types of force and torque sensing. Using joint
blocks, you can sense the actuation forces and torques driving individual joint primitives.
You can also sense the total and constraint forces acting on an entire joint.
In this tutorial, you use a Weld Joint block to sense the time-varying internal forces
that hold a rigid body together. A double-pendulum model, smdoc_double_pendulum,
provides the starting point for the tutorial. For information on how to create this model,
see “Model Double Pendulum” on page 3-15.
4-94
Sense Internal Forces in Double-Pendulum Link
By connecting the Weld Joint block between solid elements in a binary link subsystem,
you can sense the constraint forces acting between them. The following figure shows the
constraint forces that you sense in this tutorial. The longitudinal constraint force aligns
with the X axis of the weld joint frames. The transverse constraint force aligns with the Y
axis. The constraint force along the Z axis is negligible and therefore ignored.
The Weld Joint block enables you to sense the constraint force that the follower frame
exerts on the base frame or, alternatively, the constraint force that the base frame exerts
on the follower frame. The two forces have the same magnitude but, as shown in the
binary link schematic, opposite directions. In this tutorial, you sense the constraint force
that the follower frame exerts on the base frame.
You can also select the frame to resolve the constraint force measurement in. The
resolution frame can be either the base frame or the follower frame. Certain joint blocks
allow their port frames to have different orientations, causing the same measurement
to differ depending on your choice of resolution frame. However, because the Weld Joint
block provides zero degrees of freedom, both resolution frames yield the same constraint
force vector components.
4-95
4 Internal Mechanics, Actuation and Sensing
provides zero degrees of freedom between its port frames, it has no effect on model
dynamics.
3 Drag the following blocks into the main window of the model. These blocks enable
you to output the constraint force signal into the MATLAB workspace.
Library Block
Simscape > Utilities PS-Simulink Converter
Simulink > Sinks To Workspace
4 Connect the blocks as shown in the figure. Check that the PS-Simulink Converter
block connects to the newly added Simscape port.
4-96
Sense Internal Forces in Double-Pendulum Link
Units of mN are appropriate for this model, which contains Aluminum links roughly
30 cm × 2 cm × 0.8 cm.
Simulate Model
1 In the Simulink Editor menu bar, select Simulation > Model Configuration
Parameters.
2 In the Solver tab of the Configuration Parameters window, set the Solver parameter
to ode15s. This is the recommended solver for physical models.
3 In the same tab, set the Max step size parameter to 0.001 s.
4 Run the simulation. You can do this from the Simulink Editor menu bar, by selecting
Simulation > Run. Mechanics Explorer opens with a dynamic view of the model.
In the Mechanics Explorer menu bar, select the Isometric View button to view the
double pendulum from an isometric perspective.
4-97
4 Internal Mechanics, Actuation and Sensing
figure;
grid on;
xlabel('T, s');
ylabel('F_{C,X}, mN');
zlabel('F_{C,Y}, mN');
plot3(fcf_weld.time, fcf_weld.data(:,1), fcf_weld.data(:,2),...
'.', 'MarkerSize', 1, 'Color', 'r');
MATLAB plots the axial and transverse constraint forces with respect to time in 3-D. The
figure shows the resulting plot.
4-98
Sense Internal Forces in Double-Pendulum Link
4-99
4 Internal Mechanics, Actuation and Sensing
Model Overview
In this tutorial, you prescribe the time-varying crank angle of a four-bar linkage using
a Revolute Joint block. Then, during simulation, you sense the actuation torque at the
same joint corresponding to the prescribed motion.
Build Model
1 At the MATLAB command prompt, enter smdoc_four_bar. A four-bar model opens.
This is the model you create in tutorial “Model Four Bar” on page 3-20.
2 In the dialog box of the Base-Crank Revolute Joint block, specify the following
parameters settings.
Parameter Setting
Actuation > Torque Automatically Computed
4-100
Prescribe Joint Motion in Four-Bar Model
Parameter Setting
Actuation > Motion Provided by Input
Sensing > Actuator Torque Selected
The joint block displays two physical signal ports. Input port q accepts the joint
angular position. Output port t provides the joint actuation torque required to
achieve that angular position.
3 In each of the four Revolute Joint block dialog boxes, set Internal Mechanics >
Damping Coefficient to 5e-4 N*m/(deg/s). During simulation, damping forces
between the joint frames account for dissipative losses at the joints.
4 Drag the following blocks into the model. These blocks enable you to specify an
actuation torque signal and plot the joint position.
Block Library
Simulink-PS Converter Simscape > Utilities
PS-Simulink Converter Simscape > Utilities
Scope Simulink > Sinks
Signal Builder Simulink > Sources
5 Connect the blocks as shown in the figure.
4-101
4 Internal Mechanics, Actuation and Sensing
6 In the Input Handling tab of the Simulink-PS Converter block dialog box, specify the
following block parameters.
Parameter Value
Filtering and derivatives Filter input
Input filtering order Second-order filtering
7 In the Signal Builder window, specify the joint angular trajectory as shown in the
figure.
4-102
Prescribe Joint Motion in Four-Bar Model
Simulate Model
Run the simulation, e.g., by selecting Simulation > Run from the Simulink menu bar.
Mechanics Explorer opens with a dynamic display of the four-bar model.
4-103
4 Internal Mechanics, Actuation and Sensing
Open the Scope window. The scope plot shows the joint actuation torque with which you
can achieve the motion you prescribed.
Related Examples
• “Sense Motion in Double-Pendulum Model” on page 4-62
• “Prescribe Joint Motion in Planar Manipulator Model” on page 4-105
• “Specify Motion Input Derivatives” on page 4-28
4-104
Prescribe Joint Motion in Planar Manipulator Model
In this section...
“Model Overview” on page 4-105
“Add Virtual Joint” on page 4-106
“Prescribe Motion Inputs” on page 4-107
“Sense Joint Actuation Torques” on page 4-111
“Simulate Model” on page 4-112
Model Overview
In this tutorial, you prescribe the time-varying trajectory coordinates of a planar
manipulator end frame with respect to the world frame using a 6-DOF Joint block. This
block provides the requisite degrees of freedom between the two frames, but it does not
represent a real physical connection between them. The joint it represents is said to be
virtual.
4-105
4 Internal Mechanics, Actuation and Sensing
4-106
Prescribe Joint Motion in Planar Manipulator Model
Note: Check that the base port frame (B) connects to the world frame. The base port
frame functions as the reference frame for any joint motion input that you provide.
Switching the base and follower port frames causes the block to interpret any motion
input with respect to a different frame, possibly altering the manipulator end frame
trajectory.
Parameter Select
Y Prismatic Primitive (Py) > Provided by Input
Actuation > Motion
Z Prismatic Primitive (Pz) > Provided by Input
Actuation > Motion
The block exposes two physical signal ports through which you can provide the joint
motion inputs.
2 Drag these blocks into the model.
4-107
4 Internal Mechanics, Actuation and Sensing
The Signal Builder blocks provide the motion inputs as Simulink signals. The
Simulink-PS Converter blocks convert the Simulink signals into Simscape physical
signals compatible with Simscape Multibody blocks.
3 Connect the blocks as shown in the figure.
4 Open the dialog box of the Signal Builder block connected to port py of the 6-
DOF Joint block. Specify this signal, the time-varying Y coordinate of the square
trajectory the manipulator end frame is to follow.
4-108
Prescribe Joint Motion in Planar Manipulator Model
5 Open the dialog box of the Signal Builder block connected to port pz of the 6–
DOF Joint block. Specify this signal, the time-varying Z coordinate of the square
trajectory the manipulator end frame is to follow.
4-109
4 Internal Mechanics, Actuation and Sensing
6 In the dialog boxes of the Simulink-PS Converter blocks, specify the input signal
units and filtering settings. Simscape Multibody requires that you either specify
second-order filtering or provide the first two time derivatives of the trajectory
coordinates.
Parameter Value
Units > Input signal unit cm
Input Handling > Filtering and Filter input
derivatives
Input Handling > Input filtering Second-order filtering
order
Input Handling > Input filtering 0.1
time constant (in seconds)
Small filtering constants can slow simulation significantly. For most Simscape
Multibody models, a value of 0.1 seconds is a good choice. In this tutorial, this value
suffices.
4-110
Prescribe Joint Motion in Planar Manipulator Model
Parameter Setting
Actuation > Torque Automatically Computed
Sensing > Actuation Torque Selected
Simscape Multibody requires the number of joint primitive degrees of freedom with
motion inputs to equal the number with automatically computed joint actuation
forces and torques. If the model does not meet this condition, simulation fails with an
error.
2 Drag these blocks into the model.
The PS-Simulink Converter blocks convert the physical signal outputs into Simulink
signals compatible with other Simulink blocks.
3 In the two To Workspace block dialog boxes, enter the variable names t1 and t2.
4 Connect the blocks as shown in the figure.
4-111
4 Internal Mechanics, Actuation and Sensing
Simulate Model
Attempt to run the simulation. You can do this in the Simulink Editor menu bar, by
selecting Simulation > Run. Simulation fails with an error arising from the closed
kinematic loop present in the model. Simscape Multibody requires this loop to contain at
least one joint block without motion inputs or automatically computed actuation forces or
torques.
1 From the Simscape > Multibody > Joints library, drag a Weld Joint block and
connect it inside one of the Binary Link A subsystems.
4-112
Prescribe Joint Motion in Planar Manipulator Model
Adding the Weld Joint block ensures that the now-closed-loop system contains at
least one joint block without motion inputs or computed actuation torques.
Run the simulation once again. Mechanics Explorer opens with a dynamic 3-D display of
the two-bar linkage.
Plot the computed actuation torques acting at the two revolute joints in the linkage. At
the MATLAB command line, enter this code:
figure;
hold on;
plot(t1.time, t1.data, 'color', [60 100 175]/255);
plot(t2.time, t2.data, 'color', [210 120 0]/255);
xlabel('Time');
ylabel('Torque (N*m)');
4-113
4 Internal Mechanics, Actuation and Sensing
grid on;
The plot shows the time-varying actuation torques acting at the two revolute joints.
These torques enable the manipulator end frame to trace the prescribed square
trajectory.
Related Examples
• “Sense Motion in Double-Pendulum Model” on page 4-62
• “Prescribe Joint Motion in Four-Bar Model” on page 4-100
• “Specify Motion Input Derivatives” on page 4-28
More About
• “Joint Actuation” on page 4-20
• “Actuating and Sensing Using Physical Signals” on page 4-31
4-114
Simulation and Analysis
5
Simulation
5-2
Configure Model for Simulation
Note: For best performance, select Variable-step. For model deployment, select
Fixed-step.
4 Click Solver and select the appropriate solver for your application. The default
solver is ODE45 (Dormand-Prince).
Reducing the values of the step size and tolerance parameters enhances simulation
accuracy, but decreases simulation speed. Adjust the parameters to obtain an optimal
trade-off between simulation speed and accuracy.
Related Examples
• “Configure Model for Rapid Accelerator Mode” on page 8-7
5-3
5 Simulation
5-4
Troubleshoot Simulation Issues
Under certain conditions, a model that you simulate can behave in unexpected ways.
Some issues that you can encounter while simulating a Simscape Multibody model
include:
5-5
5 Simulation
Note: Simscape Multibody requires the Simulink global solver to be continuous. If the
global solver is discrete, Simscape Multibody issues an error and the model does not
simulate. This requirement applies to both fixed- and variable-step solvers.
Related Examples
• “Configure Model for Simulation” on page 5-3
• “Configure Model for Rapid Accelerator Mode” on page 8-7
5-6
6
In this section...
“Visualization Overview” on page 6-2
“Solid Visualization” on page 6-2
“Body and Multibody Visualization” on page 6-3
Visualization Overview
Visualization is the graphical rendering of bodies and multibody assemblies from a
model. You can use it as a modeling aid, e.g., to visually check bodies during modeling
and multibody connections during assembly or as a qualitative analysis tool, e.g., to
analyze motion during simulation.
Solid Visualization
To visualize a solid while modeling, you use the Solid block. This block provides a
visualization pane that you can use to view the solid from different perspectives. You
can select a standard viewpoint or rotate, pan, and zoom your solid. The figure shows the
Solid block visualization pane.
6-2
Simscape Multibody Visualization Utilities
You can view a solid before connecting the Solid block to a valid physical network.
However, you must first specify the solid shape and color. If parameterizing these
properties in terms of MATLAB variables, you must also initialize these variables—e.g.,
in the model workspace or in a subsystem mask.
6-3
6 Visualization and Animation
• View a model in its initial configuration. You must update the block diagram, e.g., by
selecting Simulation > Update diagram.
• View a model animation during simulation. You must run simulation, e.g., by
selecting Simulation > Run.
6-4
Open Mechanics Explorer
1 In the Simscape Multibody menu bar, select Simulation > Model Configuration
Parameters.
2 Expand the Simscape Multibody node and select Explorer.
3 Ensure the Open Mechanics Explorer on model update or simulation check
box is selected.
6-5
6 Visualization and Animation
Model Visualization
Multibody models lend themselves to 3-D visualization, a qualitative means of analysis
that you can use to examine rigid body geometries, mechanical connections, and
trajectories in three-dimensional space. In Simscape Multibody, you can visualize a
model using Mechanics Explorer, adjusting the view point and detail level as needed. You
can modify the model view by:
The figure shows a Cardan gear model from the different view points using a Z up (XY
Top) view convention.
6-6
Manipulate the Visualization Viewpoint
• Y up (XY Front)
• Z up (XY Top)
• Z down (YZ Front)
The figure shows a Cardan gear model from an isometric perspective using the three
view conventions: Y up, Z up, and Z down.
6-7
6 Visualization and Animation
1 In the Mechanics Explorer tool strip, set View convention to one of the three
options.
2 Select a standard view button.
The new view convention takes effect the moment you select a standard view.
You can also use keyboard-and-mouse shortcuts. The table summarizes these shortcuts.
6-8
Manipulate the Visualization Viewpoint
Button Shortcut
Rotate 1 Click and hold the mouse scroll wheel.
2 Move the mouse in the direction you
want to rotate the model.
Pan 1 Press and hold Shift.
2 Click and hold the mouse scroll wheel.
3 Move the mouse in the direction you
want to pan the model.
Zoom 1 Press and hold Ctrl.
2 Click and hold the mouse scroll wheel.
3 Move the mouse up to zoom in, down to
zoom out.
• Split the model view into four equally sized tiles, each with a different view point
(front, right, top, and isometric views).
• Merge all tiles into a single pane with the view point of the last highlighted tile.
• Split a visualization tile vertically or horizontally into two equally sized tiles.
The figure shows the Cardan gear model with a four-way visualization split.
6-9
6 Visualization and Animation
You can merge two tiles by clicking the black dot between the tiles. To ensure that the
resulting tile uses the view point of one or the other tile, select that tile first before
clicking the black dot between the tiles.
6-10
Global and Dynamic Cameras
Camera Manager
Camera Manager is a Simscape Multibody utility that lets you create, edit, and delete
dynamic cameras for the active model. You can create multiple dynamic cameras, each
with a different trajectory, for a given model. The visualization pane context-sensitive
menus enable you to set a particular camera as the active camera. To open Camera
Manager, in the Mechanics Explorer tool menu, select Tools > Camera Manager.
Camera Overview
Cameras define the visualization viewpoints used during animation playback. Mechanics
Explorer provides two camera types—global and dynamic. The global camera provides
a static viewpoint that you can manipulate interactively during animation playback.
Dynamic cameras provide moving viewpoints that you define through Camera Manager.
Camera in a Model
6-11
6 Visualization and Animation
Global Camera
The global camera is the default global camera in all visualization panes. This camera:
You must manipulate the camera manually to change the camera viewpoint, for
example, by using the Pan, Rotate, and Zoom tools.
• Is external to the model.
You cannot position the global camera between bodies, for example, to prevent one
body from obstructing another during animation playback.
• Uses an orthographic view mode.
Apparent body sizes remain constant regardless of object distance to the camera. This
effect, shown in the figure, is consistent with a camera located relatively far from the
model.
Dynamic Cameras
Dynamic cameras provide alternate moving viewpoints that you can use during
animation playback. These cameras:
Every dynamic camera follows a trajectory that you prespecify through Camera
Manager. You cannot use the Pan, Rotate, or Zoom buttons during animation
playback.
• Can be internal to a model.
Dynamic cameras can be inside or outside the perimeter of a model. Position a camera
between bodies for a viewpoint internal to the model.
• Use a perspective view mode.
6-12
Global and Dynamic Cameras
• Apparent body sizes vary noticeably with object distance to the camera, creating a
more realistic 3-D effect. This effect, shown in the figure, is consistent with a camera
located relatively close to the model.
Camera Keyframes
Dynamic camera trajectories are based on keyframes—animation stills, each with a
viewpoint corresponding to a particular point in the animation timeline. Simscape
Multibody software interpolates between the specified keyframes using the MATLAB
pchip function to obtain a smooth camera trajectory.
A dynamic camera can have one or more keyframes. Add keyframes to a camera to
obtain more intricate camera trajectories. Cameras that have a single keyframe have no
trajectory and are fixed during animation playback.
Setting Keyframes
Camera Manager provides a Keyframes pane for specifying camera keyframes. You
open this pane by clicking the Create button for a new camera or the Edit button for
6-13
6 Visualization and Animation
an existing camera. For more information on creating cameras and setting camera
keyframes, see “Create a Dynamic Visualization Camera” on page 6-15.
The Keyframes pane of Camera Manager provides Previous and Next buttons that you
can use to jump between camera keyframes. Use these buttons to select a keyframe for
editing. Colored markers in the playback slider identify the various keyframes for the
active dynamic camera.
6-14
Create a Dynamic Visualization Camera
For more information, see “Global and Dynamic Cameras” on page 6-11.
6-15
6 Visualization and Animation
A model can have multiple dynamic cameras. Give each camera a descriptive name so
that you can easily identify it when selecting the active camera. Then, click the Save
button to commit your changes to the model.
To edit an existing keyframe, use the Previous and Next buttons to navigate to the
keyframe you want to edit. Then, repeat the procedure for adding a keyframe. Click
the Remove button if you want to delete the current keyframe instead. Click the Save
button in the main pane to commit your changes to the camera.
1 Right-click the visualization pane that you want to set the active camera for.
You can select the global camera or any of the dynamic cameras listed in Camera
Manager for this model.
6-16
Selective Model Visualization
In this section...
“What Is Visualization Filtering?” on page 6-17
“Changing Component Visibility” on page 6-18
“Visualization Filtering Options” on page 6-19
“Components You Can Filter” on page 6-19
“Model Hierarchy and Tree Nodes” on page 6-20
“Filtering Hierarchical Subsystems” on page 6-20
“Updating Models with Hidden Nodes” on page 6-21
“Alternative Ways to Enhance Visibility” on page 6-22
Visualization filtering is a Mechanics Explorer feature that lets you selectively show and
hide parts of your model. By showing only those parts that you want to see, you can more
easily discern any components placed within or behind other components—such as an
engine piston traveling inside a cylinder casing.
The figure shows an example of visualization filtering. Two cylinders, one at the front
and one at the rear, are hidden in the model visualization of the sm_radial_engine
featured example. For a tutorial showing how to use visualization filtering, see “Show
and Hide Bodies and Multibody Subsystems” on page 6-23.
6-17
6 Visualization and Animation
6-18
Selective Model Visualization
• Show This — Enable visualization for the selected component. This option has no
effect if the component is already visible.
• Hide This — Disable visualization for the selected component. This option has no
effect if the component is already hidden.
• Show Only This — Enable visualization for the selected component and disable
visualization for the remainder of the model. This option has no effect if the selected
component is already the only component visible.
• Show Everything — Enable visualization for every component in the model. This
option has no effect if every component in the model is already visible.
Frames, joints, constraints, forces, and torques have no solid geometry to visualize and
therefore cannot be filtered in Mechanics Explorer. You can still open the visualization
filtering context-sensitive menu by right-clicking these nodes, but only one option is
active—Show Everything.
The tree-view pane identifies any node not being visualized by graying out its name. This
includes nodes that can be visualized but are currently hidden and nodes that cannot be
visualized at all. The figure shows an example with the grayed-out names of nodes not
being visualized.
6-19
6 Visualization and Animation
The figure shows portion of the tree-view pane of the sm_radial_engine featured
example. The Half_Cylinder_A node is a child to the Housing_and_Cylinder_Assembly
node and a parent to the Fins and Half_Annular_Cylinder nodes.
6-20
Selective Model Visualization
If you want to show part of a subsystem you have previously hidden, you can change
the visibility settings for the children nodes that you want to show. For example, if after
hiding the Half_Cylinder_A node, you want to show the Fins child node, you need only
right-click the Fins node and select Show This. Such changes have no effect on the
remainder of the Half_Cylinder_A parent node.
• If the model remains unchanged, the node visibility settings remain unchanged—that
is, the hidden nodes remain hidden and the visible nodes remain visible. This happens
even if you save the Mechanics Explorer configuration to the model by clicking the
icon.
• If you close Mechanics Explorer before updating the model, Mechanics Explorer
reopens with all nodes visible, including any nodes you may have previously hidden.
• If you change the name of a block corresponding to a hidden node—e.g., a Solid block
or a Subsystem block containing a Solid block—the hidden node and any children
nodes it may have become visible.
6-21
6 Visualization and Animation
• If you uncomment a block that corresponds to a hidden node and that you had
previously commented out, the hidden node and any children nodes it may have
become visible.
• If you add to a hidden Subsystem block a Solid block or another Subsystem block with
a Solid block, the child node corresponding to the new block becomes visible upon
model update but the visibility of the hidden parent node remains unchanged.
• If you change the parameters of a block corresponding to a hidden node, that node
and its children nodes retain their original visibility settings—that is, hidden nodes
remain hidden and visible nodes remain visible.
6-22
Show and Hide Bodies and Multibody Subsystems
Visualization Filtering
Visualization filtering is a Mechanics Explorer feature that enables you to selectively
show and hide solids, bodies, and multibody subsystems. This tutorial shows you how
to use this feature to control the visualization of a Simscape Multibody model, for
example, to observe a model component that might otherwise remain obstructed during
simulation. For more information, see “Selective Model Visualization” on page 6-17.
6-23
6 Visualization and Animation
6-24
Show and Hide Bodies and Multibody Subsystems
6-25
6 Visualization and Animation
6-26
Show and Hide Bodies and Multibody Subsystems
6-27
6 Visualization and Animation
Show Everything
In the tree-view pane, right-click any node and select Show Everything. All hidden
components become visible. The corresponding nodes are no longer grayed out in the
tree-view pane. The figure shows the resulting model visualization.
6-28
Show and Hide Bodies and Multibody Subsystems
6-29
6 Visualization and Animation
In this section...
“What Are Frames?” on page 6-30
“Show All Frames” on page 6-30
“Highlight Specific Frames” on page 6-31
“Visualize Frames via Graphical Markers” on page 6-33
Alternatively, you can select View > Toggle Frames in the menu bar. Mechanics
Explorer shows all the frames in your model, suiting this approach well for models with
small numbers of frames. The figure shows a radial engine model with frame visibility
toggled on.
6-30
Visualize Simscape Multibody Frames
If your model has many frames, a different approach may be ideal, as toggling frame
visibility may clutter the visualization pane with frames that you don’t want to track.
6-31
6 Visualization and Animation
You can also select individual port frames, which you expose by expanding the tree
nodes. For example, expanding the Piston_Connecting_Rod_Assembly_A node exposes
the port frame P node, which you can then select in order to highlight that frame. The
figure shows the result.
Finally, you can select individual solids directly in the visualization pane, highlighting
their reference frames. The figure shows the result of selecting one of the piston solids
directly. Mechanics Explorer highlights the solid and its reference frame, while the tree
view pane reveals the associated Solid block name. This is the block that you need to
change if you want to modify this particular solid.
6-32
Visualize Simscape Multibody Frames
6-33
6 Visualization and Animation
6-34
Highlight a Model Block from Mechanics Explorer
To help you troubleshoot such modeling issues, Mechanics Explorer enables you to go
directly to a block associated with a node in the tree view pane. This feature helps you
also to iterate on a model that is working properly, for example, if you want to replace a
body subsystem with an alternative version.
1 In the tree view pane of Mechanics Explorer, right-click the node whose block you
want to examine.
6-35
6 Visualization and Animation
For an example showing how to troubleshoot a model using Mechanics Explorer block
highlighting, see “Find and Fix Aiming-Mechanism Assembly Errors” on page 3-27.
6-36
Configure a Model for Video Recording
In this section...
“Correspondence Between Animation and Simulation Speeds” on page 6-37
“Configure Model with Variable-Step Solver” on page 6-37
“Configure Model with Fixed-Step Solver” on page 6-38
1 In the Simulink Editor menu bar, select Simulation > Model Configuration
Parameters.
2 In the Configuration Parameters tree pane, select Data Import/Export.
3 Under Additional parameters, set Output options to Produce specified
output only.
4 In Output times, enter [ti:1/f:tf], where:
6-37
6 Visualization and Animation
The output times vector determines the time steps at which to output simulation
data. By specifying time steps in 1/30 s intervals, you ensure that each animation
video frame corresponds to a simulation time step of equal size. The result is an
animation video that plays at normal speed without distortion.
You can also manipulate the output time step to generate videos that play at different
speeds. For example, to generate a video that plays at twice the normal speed, multiply
the output time step by 2. The output times vector becomes [ti:2/f:tf]. Similarly, to
generate a video that plays at half the normal speed, divide the output time step by 2.
The output times vector becomes [ti:1/(2*f):tf].
1 In the Simulink Editor menu bar, select Simulation > Model Configuration
Parameters.
2 In the Solver options area of the Solver pane, set Type to Fixed-step.
3 Under Additional options, set Fixed-step size (fundamental sample time) to
1/30.
6-38
Configure a Model for Video Recording
Changing the fixed-step size from 1/30 causes the recorded animation to play back
at a different speed. For example, doubling the step size to 2/30 causes the recorded
animation to play back at twice the normal speed. Similarly, changing the step size to
1/60 causes the recorded animation to play back at half the normal speed.
Note: When using a fixed-step solver, you cannot specify the simulation output times.
You must change the solver time step directly.
Model dynamics should take precedence over video playback considerations. Select a
solver and step size based on the dynamics of your model. Then, if possible, adjust the
time step to control the video playback speed.
6-39
6 Visualization and Animation
If you have not already done so, “Configure a Model for Video Recording” on page 6-37
before proceeding. This step ensures that your video plays at the correct speed and
without any time distortion. To record the video:
1 Update or simulate your model. If Mechanics Explorer does not open, see “Open
Mechanics Explorer” on page 6-5.
2 In the Mechanics Explorer menu bar, select Tools > Create Video.
3 When prompted, save the video file in a convenient folder. A new window opens with
a display of the model and the recording progress.
4 When the message Video file "filename.avi" has been successfully
created appears on your screen, press OK. filename is the path and name of your
video file.
6-40
Troubleshoot Visualization Issues
In this section...
“Mechanics Explorer Not Opening” on page 6-41
“Model Showing Sideways in Mechanics Explorer” on page 6-41
“Parts Not Showing in Mechanics Explorer” on page 6-42
“Colored Parts Showing Gray in Mechanics Explorer” on page 6-44
If Mechanics Explorer fails to open during model update, check that Mechanics Explorer
is set to open on model update:
1 In the Simulink Editor menu bar, select Simulation > Model Configuration
Parameters.
2 Expand the Simscape Multibody node.
3 Click Explorer.
4 Verify that Open Mechanics Explorer on model update or simulation is
selected.
6-41
6 Visualization and Animation
view convention to that used in the original CAD assembly model. The figure shows the
default Mechanics Explorer display of an imported robot arm model.
1 In the Mechanics Explorer toolbar, click the View Convention drop-down menu.
2 Select Y up (ZX Top).
3 Refresh the Mechanics Explorer display by selecting a view point from the
Mechanics Explorer tool bar.
Mechanics Explorer displays the model using the new view convention.
6-42
Troubleshoot Visualization Issues
cannot load the geometry file for a part, that part appears invisible in Mechanics
Explorer. This issue does not affect model update or simulation.
The figure shows the Mechanics Explorer display of an imported model containing an
invalid geometry file.
If either is incorrect, enter the correct information and update the model. Check that
Mechanics Explorer displays the invisible part. If not, check if the geometry files are
valid.
6-43
6 Visualization and Animation
If a geometry file specifies a normal vector with zero length, Simscape Multibody issues a
warning. The geometry file fails to load.
6-44
CAD Import
7
CAD Translation
CAD translation is the conversion of a CAD assembly model into a Simscape Multibody
model. This conversion relies on a specially formatted XML file to pass a detailed model
description from your CAD application to Simscape Multibody software. The model
description enables Simscape Multibody software to recreate the assembly model as a
block diagram.
You translate a CAD assembly in two steps—export and import. The export step converts
the CAD assembly model into an XML multibody description file and a set of STEP or
STL part geometry files. The import step converts the multibody description and part
geometry files into an SLX Simscape Multibody model and an M data file. The model
obtains all block parameter inputs from the data file.
CAD Translation
More About
• “CAD Model Export” on page 7-8
• “XML File Import” on page 7-10
• “Data File Update” on page 7-17
7-2
Translated Model
Translated Model
The translated model represents the CAD parts using Simulink subsystems based on
Solid and Rigid Transform blocks. The Solid blocks provide the part geometries,
inertias, and colors. The Rigid Transform blocks provides frames with the required
poses for connection to other parts. Consider the upper arm of the robotic arm model
shown in the figure
The corresponding Simulink subsystem for the upper arm part consists of one Solid block
and two Rigid Transform blocks. The Solid block provides the solid properties of the
upper arm part. The Rigid Transform blocks provide the frames for connection to the
robotic arm base and lower arm parts.
The CAD constraints between the various parts translate into joint and constraint
blocks. In the robotic arm example, the constraints between the upper arm and lower
arm parts translate into a Revolute Joint block. This block sits between the Simulink
Subsystem blocks that represent the upper arm and lower arm parts.
7-3
7 About CAD Import
The translated model preserves the structural hierarchy of the CAD assembly model. If
the CAD parts are nested in a multibody subassembly, then, in the translated model, the
Simulink subsystems for the parts are nested in a Simulink subsystem for the multibody
subassembly.
Consider the structural hierarchy of the robotic arm assembly model, shown in the
figure. The model contains a grip multibody subassembly that consists of seven parts.
7-4
Translated Model
7-5
7 About CAD Import
More About
• “CAD Translation” on page 7-2
• “Model Data File” on page 7-7
• “Data File Update” on page 7-17
7-6
Model Data File
Consider an imported model with a data structure named smiData. If the model contains
Revolute Joint blocks, the parameter data for these blocks is the structure array
smiData.RevoluteJoint. This structure array contains a number of data fields, each
corresponding to a different block parameter.
The structure array fields are named after the block parameters. For example,
the position state target data for the Revolute Joint blocks is in a field named
Rz_Position_Target. If the model has two Revolute Joint blocks, this field
contains two entries—smiData.RevoluteJoint(1).Rz_Position_Target and
smiData.RevoluteJoint(2).Rz_Position_target.
Each structure array index corresponds to a specific block in the imported model. The
index assignments can change if you regenerate a data file from an updated XML
multibody description file. The smimport function checks the prior data file, when
specified, to ensure the index assignments remain the same. See “Data File Update” on
page 7-17.
More About
• “CAD Translation” on page 7-2
• “Translated Model” on page 7-3
• “Data File Update” on page 7-17
7-7
7 About CAD Import
• Simscape Multibody — XML multibody description file compatible with the newer
Simscape Multibody blocks. You must import the XML file using the smimport
function.
• Simscape Multibody First Generation — XML multibody description file compatible
with the older Simscape Multibody First Generation blocks. You must import the
XML file using the mech_import function.
For information on how to export a CAD assembly model using the Simscape Multibody
Link CAD plug-in, see “Export a CAD Assembly Model”.
Alternatively, if you use an unsupported CAD application, you can write a program that
uses the CAD API and Simscape Multibody XML schema to generate the multibody
description and part geometry files. This task requires knowledge of XML documents,
XSD schema definitions, and CAD APIs.
See the schema website for the XSD schema definitions. See MATLAB Central for an
example program built on the SolidWorks CAD API.
More About
• “CAD Export Errors” on page 7-9
• “CAD Translation” on page 7-2
• “XML File Import” on page 7-10
7-8
CAD Export Errors
More About
• “CAD Import Errors” on page 7-11
• “CAD Model Export” on page 7-8
7-9
7 About CAD Import
More About
• “CAD Import Errors” on page 7-11
• “XML File Import” on page 7-10
• “Data File Update” on page 7-17
7-10
CAD Import Errors
More About
• “XML File Import” on page 7-10
7-11
7 About CAD Import
7-12
Minor Import Issues
In this section...
“Unexpected Model Orientation” on page 7-13
“Missing Part Visualization” on page 7-14
“Wrong Part Colors” on page 7-16
7-13
7 About CAD Import
1 In the Mechanics Explorer toolbar, click the View Convention drop-down menu.
2 Select Y up (ZX Top).
3 Refresh the Mechanics Explorer display by selecting a view point from the
Mechanics Explorer tool bar.
Mechanics Explorer displays the model using the new view convention.
The figure shows the Mechanics Explorer display of an imported model containing an
invalid geometry file.
7-14
Minor Import Issues
7-15
7 About CAD Import
If either is incorrect, enter the correct information and update the model. Check that
Mechanics Explorer displays the invisible part. If not, check if the geometry files are
valid.
To visualize a CAD assembly model that you import, Simscape Multibody relies on a set
of geometry files that specify the 3-D surface geometry of the CAD parts. Each geometry
file specifies the surface geometry of one CAD part as a set of 2-D triangles. To do this,
the geometry files contain:
If a geometry file specifies a normal vector with zero length, Simscape Multibody issues a
warning. The geometry file fails to load.
See Also
smimport
Related Examples
• “Install Simscape Multibody Link Plug-In” on page 7-18
• “Import a Robotic Arm Model” on page 7-22
More About
• “CAD Import Errors” on page 7-11
• “CAD Export Errors” on page 7-9
7-16
Data File Update
Before regenerating a data file, you must export a new XML multibody description file
from the updated CAD assembly model. The smimport function uses the data in the new
multibody description file to generate the new data file.
The function does not update the block diagram when run in dataFile mode. If you add
or delete parts in the source CAD assembly model, you must manually add or delete the
corresponding blocks in the previously imported model.
CAD Update
More About
• “CAD Translation” on page 7-2
• “Model Data File” on page 7-7
• “Translated Model” on page 7-3
7-17
7 About CAD Import
In this section...
“Before You Begin” on page 7-18
“Step 1: Get Installation Files” on page 7-18
“Step 2: Run Installation Function” on page 7-18
“Step 3: Register MATLAB as Automation Server” on page 7-19
“Step 4: Enable Simscape Multibody Link Plug-In” on page 7-19
Your MATLAB and CAD installations must have the same system architecture—e.g.,
Windows 64-bit.
Select the file versions matching your MATLAB release number and system
architecture—e.g., release R2015b and Win64 architecture. Do not extract the zip
archive.
7-18
Install Simscape Multibody Link Plug-In
7-19
7 About CAD Import
Example Files
Simscape Multibody software provides two sets of multibody description and part
geometry files that you can use as CAD import examples. One set corresponds to a
robotic arm assembly model. The other corresponds to a Stewart platform assembly
model. The file sets are in different folders named
matlabroot\toolbox\physmod\sm\smdemos\import\modelFolder,
where:
C:\Programs\MATLAB\
• modelFolder is the name of the folder that contains the example file sets.
The robot folder provides the robotic arm example files. The stewart_platform
folder provides the Stewart platform example files.
Import Model
You import a model into Simscape Multibody software using the smimport function in
its default mode. Consider the example file sets in your Simscape Multibody installation.
7-20
Import a CAD Assembly Model
To recreate the CAD assembly model described by the files as Simscape Multibody block
diagrams, enter:
smimport(multibodyDescriptionFile);
where multibodyDescriptionFile is the XML multibody description file name for the
example model you want to import, specified as a string. Use sm_robot for the robotic
arm model and stewart_platform for the Stewart platform model. For example, to
import the robotic arm model, enter:
smimport('sm_robot');
The function generates a new Simscape Multibody block diagram and a supporting data
file. The block diagram recreates the original CAD assembly model using Simscape
Multibody blocks. The data file provides the numerical values of the block parameters
used in the model.
After Import
Check the imported model for unexpected rigid connections between parts. Simscape
Multibody software replaces unsupported CAD constraints with rigid connections that
may appear as direct frame connection lines, Rigid Transform blocks, or Weld Joint
blocks.
A warning message in the MATLAB command window identifies the parts and
connection frames affected by the unsupported constraints. Replace the artificial rigid
connections between the parts with suitable Joint, Constraint, or Gear blocks from the
Simscape Multibody library.
Update the block diagram to rule out model assembly errors. Run simulation to ensure
the model dynamics are as expected. If you update the source CAD assembly model, you
can generate an updated data file directly from a new multibody description file. For
more information, see “CAD Translation” on page 7-2.
7-21
7 About CAD Import
Example Overview
This example shows how to generate a Simscape Multibody model from a multibody
description XML file using the smimport function. The example is based on a multibody
description file named sm_robot and a set of part geometry files included in your
Simscape Multibody installation. These files describe the robotic arm model shown in the
figure.
Example Files
The multibody description and part geometry files used in this example are located in the
folder
matlabroot\toolbox\physmod\sm\smdemos\import\robot
where matlabroot is the root folder of your MATLAB installation, for example:
C:Programs\MATLAB\
7-22
Import a Robotic Arm Model
smimport('sm_robot');
Simscape Multibody software generates the model described in the sm_robot.xml file
using the default smimport function settings.
The blocks in the generated model are parameterized in terms of MATLAB variables.
The numerical values of these variables are defined in a data file that is named
sm_robot.m and stored in the same active folder as the generated model.
7-23
7 About CAD Import
The default view convention in Mechanics Explorer differs from that in the CAD
application used to create the original assembly model. Mechanics Explorer uses a Z-axis-
up view convention while the CAD application uses a Y-axis-up view convention.
Change the view convention from the Mechanics Explorer toolstrip by setting the View
convention parameter to Y Up (XY Front). Then, select a standard view from the
View > Standard Views menu to apply the new view convention.
See Also
smimport
Related Examples
• “Import a CAD Assembly Model” on page 7-20
More About
• “CAD Translation” on page 7-2
• “XML File Import” on page 7-10
• “CAD Import Errors” on page 7-11
7-24
Deployment
8
Code Generation
8 Code Generation
Simulation Acceleration
Simulink can generate C/C++ executable code to shorten simulation time. Two
simulation modes generate code:
• Accelerator
• Rapid Accelerator
Simscape Multibody supports the two accelerator modes. You can access the simulation
accelerator modes in the Simulink Editor window for your model. Click Simulation
8-2
Code Generation Applications
> Mode, and select Accelerator or Rapid Accelerator. Accelerator modes do not
require additional Simulink code generation products.
Note: Simulation accelerator modes do not support model visualization. When you
simulate a Simscape Multibody model in Accelerator or Rapid Accelerator modes,
Mechanics Explorer does not open with a 3-D display of your model.
Model Deployment
With Simulink Coder, you can generate standalone C/C++ code for deployment outside
the Simulink environment. The code replicates the source Simscape Multibody model.
You can use the stand-alone code for applications that include:
Note: Simscape Multibody supports, but does not perform, code generation for model
deployment. Code generation for model deployment requires the Simulink Coder product.
Related Examples
• “Configure Four-Bar Model for Code Generation” on page 8-5
• “Configure Model for Rapid Accelerator Mode” on page 8-7
8-3
8 Code Generation
Solver Selection
Simscape Multibody models have continuous states and require a continuous or
hybrid Simulink solver. You can change solvers from the Solver pane of the Model
Configuration Parameters window. Select any solver but that marked discrete (no
continuous states). Consider the ODE1 fixed-step solver if you need to approximate
the behavior of a discrete solver.
Target Selection
The choice of code generation target depends on the Simulink solver used. If you select
a variable-step solver, you must set rsim.tlc as the system target file. You can specify
the system target file from the Model Configuration Parameters window. Look
for the System target file parameter in the Target selection area of the Code
Generation pane.
8-4
Configure Four-Bar Model for Code Generation
The four-bar model is present in your Simscape Multibody installation. To open the
model, at the MATLAB command line type sm_four_bar. A new Simulink Editor
window opens with the block diagram of the four-bar model.
Configure Model
To configure the model for code generation:
1 In the Simulink Editor window for your model, select Simulation > Model
Configuration Parameters.
8-5
8 Code Generation
Note: You must use the rsim.tlc target each time you use a variable-step solver.
You can change the solver type in the Solver section of the Model Configuration
Parameters window.
4 In Code Generation Advisor, select Execution Efficiency.
5 Click Apply.
6 To generate C code for your model, press Ctrl+B.
Related Examples
• “Configure Model for Rapid Accelerator Mode” on page 8-7
More About
• “Code Generation Applications” on page 8-2
8-6
Configure Model for Rapid Accelerator Mode
Model Overview
You can run a Simscape Multibody model in Accelerator and Rapid Accelerator modes.
When you select an accelerator mode, Simscape Multibody generates executable code
that accelerates the model simulation. This example shows how to configure a four-bar
model for Rapid Accelerator simulation mode. The simulation uses the default Simulink
solver ode45 (Dormand-Prince).
The four-bar model is present in your Simscape Multibody installation. To open the
model, at the MATLAB command line type sm_four_bar. A new Simulink Editor
window opens with the block diagram of the four-bar model.
8-7
8 Code Generation
Configure Model
To configure the model for Rapid Acceleration simulation mode, follow these steps:
Note: You must use the rsim.tlc target each time you generate code with a
variable-step solver. Both Accelerator and Rapid Accelerator modes generate
executable code that requires the rsim.tlc target to be used with variable-step
solvers.
5 Expand the Simscape Multibody node.
6 Select Explorer.
7 Clear the Open Mechanics Explorer on model update or simulation check box.
Note: The Rapid Accelerator mode incurs an initial time cost to generate the
executable code. Once the code is generated, the simulation proceeds more rapidly.
Rapid Accelerator mode is suggested for large or complex Simscape Multibody
models with long simulation times.
The Rapid Accelerator mode does not support visualization. Mechanics Explorer does
not open, and you cannot view a dynamic simulation of the model. All other simulation
capabilities remain functional, including graphics and scopes.
More About
• “Code Generation Applications” on page 8-2
8-8