Simscape Multibody Getting Starts
Simscape Multibody Getting Starts
R2024a
How to Contact MathWorks
Phone: 508-647-7000
v
1
Simscape Multibody provides a multibody simulation environment for 3D mechanical systems, such
as robots, vehicle suspensions, construction equipment, and aircraft landing gear. You can model
multibody systems using blocks representing bodies, joints, constraints, force elements, and sensors.
Simscape Multibody formulates and solves the equations of motion for the complete mechanical
system. You can import complete CAD assemblies, including all masses, inertias, joints, constraints,
and 3D geometry, into your model. An automatically generated 3D animation lets you visualize the
system dynamics.
Simscape Multibody helps you develop control systems and test system-level performance. You can
parameterize your models using MATLAB® variables and expressions, and design control systems for
your multibody system in Simulink®. You can integrate hydraulic, electrical, pneumatic, and other
physical systems into your model using components from the Simscape family of products. To deploy
your models to other simulation environments, including hardware-in-the-loop (HIL) systems,
Simscape Multibody supports C-code generation.
Key Features
• Single environment for simulating 3D mechanical systems together with multidomain physical
systems and control algorithms in Simulink
• Part definition tools, including standard geometry, extrusions defined in MATLAB, and STEP files
• Part definition by reading native CAD files, including CATIA
• CAD assembly import from SolidWorks®, PTC Creo™ (Pro/ENGINEER™), Autodesk Inventor® ,
and Onshape®
• Mechanical joints and constraints covering standard and custom kinematic relationships
• 3D animation of multibody system dynamics
• Support for C-code generation (with Simulink Coder™)
1-2
Multibody Model Anatomy
In this section...
“Basic Model Components” on page 1-3
“Model Actuation” on page 1-4
“Dynamical Sensing” on page 1-5
A multibody system is a set of bodies linked through joints and bound by kinematic constraints such
as gears. Forces and torques of various types enable you to actuate the various bodies, while sensors
enable you to sense the resulting motion. You can use Simscape Multibody blocks to represent these
components and analyze the dynamic responses of the system. For more information about multibody
dynamics simulations, see “Multibody Dynamics”.
The body subsystems in turn consist of Extruded Solid blocks interconnected through Rigid
Transform blocks. The Extruded Solid blocks provide the solid properties, including geometry, inertia,
color, and frames—axis triads that encode all position and orientation information in a model. The
Rigid Transform blocks rotate and translate the solids to ensure proper body assembly.
The figure shows the underlying block diagram for a binary link body subsystem. This diagram
includes three Solid blocks, representing the central and distal portions of the binary link. Two Rigid
Transform blocks translate the distal solids to their proper locations near the ends of the central
solid.
1-3
1 Introduction to Simscape Multibody Software
Model Actuation
You can actuate a model by applying a force or torque to a body or to a joint. To represent forces and
torques acting on a body, Simscape Multibody provides a Forces and Torques library. Add a block
from this library and connect it to the body frame(s) that you want to apply the force or torque to.
Block Function
External Force and Torque General force and/or torque originating outside of
the multibody model
Internal Force General force pair between two arbitrary frames
Spring and Damper Force Spring-damper force pair between two arbitrary
frames
Inverse Square Law Force Force pair with inverse dependence on the
square distance between two arbitrary frames
(e.g., Coulomb electrostatic forces)
Gravitational Field Gravitational pull of a point mass on all bodies as
a function of their distances to the point mass
itself
The figure shows a four-bar model with an External Force and Torque block for force and torque
prescription at a crank link frame.
1-4
Multibody Model Anatomy
To specify the force or torque acting at a joint, Simscape Multibody provides a selection of actuation
inputs directly in the joint blocks. Each joint primitive—the basic component of a joint block—
provides a selection of actuation inputs specific to that primitive.
The figure shows a four-bar model with an actuation torque acting on a revolute joint.
Dynamical Sensing
You can sense various dynamical variables between frame pairs, e.g., for analysis or control design.
Sensing outputs can be of two types:
1-5
1 Introduction to Simscape Multibody Software
• Motion — Compute and output the relative position, velocity, or acceleration between two
Simscape Multibody frames. You can sense motion between joint frames, by using the sensing
capability of joint blocks, or between arbitrary frames, by using the Transform Sensor block.
• Force or torque — Compute and output the forces and torques acting between two Simscape
Multibody frames. You can sense force and torque between the port frames of certain Forces and
Torques blocks, such as the Inverse Square Law Force block, or between the port frames of a joint
block.
Joint blocks enable you to sense different types of forces and torques between their respective port
frames, including:
The figure shows a four-bar model with a Transform Sensor block for trajectory coordinate sensing
between a coupler link frame and the world frame.
See Also
Related Examples
• “Model a Simple Link” on page 1-10
• “Model a Simple Pendulum” on page 1-15
• “Analyze a Single Pendulum” on page 1-18
1-6
Creating a Multibody Model
A multibody dynamics system is a set of interconnected bodies that have forces acting on them. You
can use Simscape Multibody to model the components in the system and analyze their dynamic
behaviors.
Identify the relevant bodies, joints, and constraints to incorporate in your model. Consider the forces
and torques acting between bodies or directly at joints.
Specify the solid properties of the various bodies. Add frames to the bodies so that you can connect
joints and constraints, apply forces and torques, and sense motion. See “Model a Simple Link” on
page 1-10 for an example showing how to model a simple body—one comprising a single solid. See
“Create a Compound Geometry” for a more elaborate example showing how to model a compound
body—one comprising multiple solids.
1-7
1 Introduction to Simscape Multibody Software
Connect the bodies by pairs through joints. Constrain body motion through gears and other kinematic
constraints. See “Model an Open-Loop Kinematic Chain” for an example showing how to connect
bodies through joints. See “Model a Compound Gear Train” for an example showing how to constrain
motion through gears.
Model external loads, interactions between bodies, and joint actuation inputs. Sense forces, torques,
and motion variables as functions of time. See “Specify Joint Actuation Torque” for an example
showing how to specify a joint actuation torque. See “Sense Motion Using a Transform Sensor Block”
for an example showing how to sense frame position using the Transform Sensor block. For more
information about multibody dynamics simulations, see “Multibody Dynamics”.
See Also
More About
• “Model an Open-Loop Kinematic Chain”
• “Model a Compound Gear Train”
• “Specify Joint Actuation Torque”
• “Sense Motion Using a Transform Sensor Block”
1-8
Start a Model from a Template
You can also open the Simscape Multibody block library from the MATLAB command prompt by
entering sm_lib. Browse the library to select blocks for your model. Alternatively, type the block
name in the Simulink Model window and select a match from the Simulink search results.
See “Model a Simple Link” on page 1-10 to model a body in the Simscape Multibody model
template. See “Model a Simple Pendulum” on page 1-15 to integrate the body in a multibody
mechanism.
See Also
Brick Solid | PS-Simulink Converter | Rigid Transform | Simulink-PS Converter | smnew | sm_lib
More About
• “Model a Simple Link” on page 1-10
• “Model a Simple Pendulum” on page 1-15
1-9
1 Introduction to Simscape Multibody Software
Mechanical links are common building blocks in linkages, mechanisms, and machines. In this
example, you learn how to model a simple mechanical link using Simscape Multibody. For simplicity,
the model assumes the link has a brick shape and two end frames.
Build Model
1 At the MATLAB command line, enter smnew. A Simscape Multibody model template with
commonly used blocks opens.
2 Delete the Simulink-PS Converter, PS-Simulink Converter, and Scope blocks because they are not
used in this example.
3 Show the names of the Rigid Transform and Brick Solid blocks if they are not shown already.
Right-click the block and select Format > Show Block Name > On.
4 Duplicate the Rigid Transform block to add a second end frame to the link.
5 Flip the Rigid Transform1 block so that you can connect the B ports of two Rigid Transform
blocks to each other and the Brick Solid block.
6 Connect the remaining blocks like the following figure.
1-10
Model a Simple Link
7 In the Brick Solid dialog box, specify the following parameters. These parameters define the
simple link's physical properties, such as shape, mass, and appearance.
Generate Subsystem
You can build a complex multibody system using several simple models, such as a simple link model.
The physical parameters of these simple models usually need to be adjusted to fit different design
requirements. To simplify the parameter adjusting process, you can create Subsystem blocks for
these simple models. A Subsystem block enables you to update many parameters in a single place—
the Subsystem block dialog box. In this section, you learn how to create a Subsystem block for the
simple link model.
1 Select the Brick Solid block and the two Rigid Transform blocks by holding shift and clicking the
blocks.
2 Right-click one of the selected blocks and select Create Subsystem from Selection. Simulink
adds a new Subsystem block that contains the Brick Solid and Rigid Transform blocks.
1-11
1 Introduction to Simscape Multibody Software
3 Double-click the Subsystem box. A new tab displays the children blocks of the Subsystem block.
Double-click the Conn1 and set Port location on parent subsystem to left. Click OK to apply
the change and navigate back to the parent model by clicking the up arrow button next to the
Subsystem tab.
4 Adjust the size and location of the Subsystem block as shown in the figure.
5 Right-click the Subsystem block and select Mask > Create Mask. The Mask Editor window
opens, where you can define the MATLAB variables that you entered in the Brick Solid and Rigid
Transform block dialog boxes.
6
Click the Parameters & Dialog tab and click Edit five times to create five Edit fields. In
the Edit fields, specify the following parameters and click OK. The Prompt property specifies
the names of the parameters that you can enter in the Subsystem block parameter window. The
Name property specifies their corresponding MATLAB variables.
1-12
Model a Simple Link
Prompt Name
Length (cm) L
Width (cm) W
Thickness (cm) H
Density (kg/m^3) rho
Color [R G B] rgb
7 Double-click the Subsystem block. Enter the following numerical values in the Subsystem Block
Parameters window and click OK. These values specify the shape of Brick Solid and the location
of Rigid Transform blocks.
Parameter Value
Length (cm) 20
Width (cm) 1
Thickness (cm) 1
Density (kg/m^3) 2700
Color [R G B] [0.25 0.40 0.70]
Visualize Model
Run the model. The Mechanics Explorer opens with a front view of the simple link model. To see the
3D view of the model, click the isometric view button . To view the frames in the model, in the
Mechanics Explorers tab, select View > Show Frames in the Mechanics Explorer menu bar.
1-13
1 Introduction to Simscape Multibody Software
See Also
Brick Solid | PS-Simulink Converter | Rigid Transform | Scope | Simulink-PS Converter
More About
• “Model a Simple Pendulum” on page 1-15
• “Design and Create a Custom Block”
1-14
Model a Simple Pendulum
In this section...
“Build Model” on page 1-15
“Specify Gravity” on page 1-16
“Set Pendulum Starting Position” on page 1-16
“Configure Solver” on page 1-16
“Assemble Model” on page 1-17
“Simulate Model” on page 1-17
“Save Model” on page 1-17
The pendulum is the simplest mechanical system you can model. This system contains two bodies, a
link and a fixed pivot, connected by a revolute joint. In this example, you learn how to model and
simulate a pendulum using the custom link block you created in the “Model a Simple Link” on page 1-
10. A Revolute Joint block provides the rotational degree of freedom between the link and the pivot
fixed at the world frame.
Build Model
1 At the MATLAB command prompt, enter smnew. The Simscape Multibody model template with
commonly used blocks opens up.
2 Delete the Simulink-PS Converter, PS-Simulink Converter, Scope, and Rigid Transform blocks.
You do not need them in this example.
3 Add to the model the Simple Link custom block created in the “Model a Simple Link” on page 1-
10.
4 Add a Revolute Joint block to the model. You can find this block in the Simscape > Multibody >
Joints library. This block provides one rotational degree of freedom between its frames.
5 Connect the blocks as shown in the image. The port orientation of the Revolute Joint block
becomes important when you specify joint state targets, prescribe joint actuation inputs, or sense
joint dynamic variables. The Revolute Joint block interprets each quantity as that applied to the
follower frame with respect to the base frame, so switching the port connections can affect model
assembly and simulation.
1-15
1 Introduction to Simscape Multibody Software
6 In the Brick Solid block dialog box, specify the following parameters. This block connects rigidly
to the World frame and therefore has no effect on the dynamics of the multibody model. For more
information about multibody dynamics simulations, see “Multibody Modeling”. You can leave the
inertia parameters in their default values.
Specify Gravity
The Revolute Joint block uses the common Z-axis of the base and follower frames as the joint rotation
axis. To ensure the pendulum oscillates under the effect of gravity, change the gravity vector so it no
longer aligns with the Z-axis. To do this, in the Mechanism Configuration block dialog box, set
Uniform Gravity > Gravity to [0 -9.81 0].
Configure Solver
1 Open the Configuration Parameters. In the Modeling tab, click Model Settings.
2 In the Solver tab, set the Solver parameter to ode15s (stiff/NDF). This solver is the
recommended choice for physical models.
3 Set Max step size to 0.01 and click OK. The small step size increases the simulation accuracy
and produces a smoother animation in Mechanics Explorer. Small step sizes can have a
detrimental effect on simulation speed but, in such a simple model, a value of 0.01 provides a
good balance between simulation speed and accuracy.
1-16
Model a Simple Pendulum
Assemble Model
Update the block diagram. In the Modeling tab, click Update Model. Mechanics Explorer opens
with a 3-D view of the model in its initial configuration.
In the Mechanics Explorer toolstrip, check that the View convention parameter is set to Y up (XY
Front). This view convention ensures that gravity is vertically aligned on your screen. Select a
standard view button to refresh the Mechanics Explorer display. The figure shows a front view of the
model. Save the visualization settings by clicking the Save explorer configuration to model button
Simulate Model
Run the simulation. Mechanics Explorer plays a physics-based animation of the pendulum model.
Save Model
Save the model in a convenient folder under the name SimplePendulum. You reuse this model in the
tutorial “Analyze a Single Pendulum” on page 1-18.
See Also
Revolute Joint | Prismatic Joint
More About
• “Analyze a Single Pendulum” on page 1-18
• “Model a Simple Link” on page 1-10
1-17
1 Introduction to Simscape Multibody Software
This example shows how to analyse the dynamic response of a single pendulum. You can learn how to
measure the rotation, add damping, and apply torques for the revolute joint. For more information
about multibody dynamics simulations, see “Multibody Dynamics”. You can create a set of phase plots
for the joint by using MATLAB commands with the motion outputs.
First, create the simple pendulum model in “Model a Simple Pendulum” on page 1-15. By adding
forces and torques to this model, you incrementally change the pendulum from undamped and free to
damped and driven. The forces and torques that you apply include:
• Gravitational force (Fg) — Global force that acts on every body in direct proportion to its mass,
which you specify in terms of the acceleration vector g. You specify this vector using the
Mechanism Configuration block.
• Joint damping (Fb) — Internal torque between the pendulum and the joint fixture which you
parameterize in terms of a linear damping coefficient. You specify this parameter using the
Revolute Joint block that connects the pendulum to the joint fixture.
• Actuation torque (FA) — Driving torque between the pendulum and the joint fixture, which you
specify directly as a Simscape physical signal using the Revolute Joint block that connects the
pendulum to the joint fixture.
1-18
Analyze a Single Pendulum
1 Open the SimplePendulum model that you created in tutorial “Model a Simple Pendulum” on
page 1-15.
2 In the Z Revolute Primitive (Rz) > Sensing section of the Revolute Joint block dialog box,
select the following parameters:
• Position
• Velocity
The block exposes two additional physical signal ports, q and w, that output the angular position
and velocity of the pendulum with respect to the world frame.
3 Add these blocks to the model. You use the blocks to output the joint position and velocity to the
MATLAB base workspace.
6 Change the value of the Vector format parameter to 1-D array for both PS-Simulink Converter
blocks. Set the Output signal unit parameter to deg and deg/s for the PS-Simulink Converter
blocks connected to port q and port w respectively.
1-19
1 Introduction to Simscape Multibody Software
figure
hold on
plot(q)
plot(w)
3 Plot the joint angular velocity with respect to the angular position by entering this code at the
MATLAB command prompt.
figure
plot(q.data, w.data)
xlabel('θ (deg)')
ylabel('ω (deg/s)')
The result is the phase plot of the joint that corresponds to a starting position of zero degrees
with respect to the horizontal plane.
1-20
Analyze a Single Pendulum
Try simulating the model using different starting angles. In the Z Revolute Primitive (Rz) >
State Targets section, under Specify Position Target, specify the Value parameter of the
Revolute Joint block dialog box. This figure shows a compound phase plot for starting angles of
-80, -40, 0, 40, and 80 deg.
1-21
1 Introduction to Simscape Multibody Software
2 Ensure that Z Revolute Primitive (Rz) > State Targets > Specify Position Target > Value is
set to 0 deg.
3 Run the simulation.
4 Plot the joint position and velocity with respect to time. To do this, enter this code at the MATLAB
command prompt.
figure
hold on
plot(q)
plot(w)
The figure shows the resulting plot. Note that the pendulum oscillations decay with time due to
damping. At larger damping values, the pendulum becomes overdamped and the oscillations
disappear.
5 Plot the joint phase plot. To do this, enter this code at the MATLAB command prompt.
figure
plot(q.data, w.data)
xlabel('θ (deg)')
ylabel('ω (deg/s)')
1-22
Analyze a Single Pendulum
Try simulating the model using different starting angles. In the Z Revolute Primitive (Rz) >
State Targets section, under Specify Position Target, specify Value parameter of the Revolute
Joint block dialog box. The figure shows a compound phase plot for starting angles of -80, -40,
0, 40, and 80 deg.
1-23
1 Introduction to Simscape Multibody Software
Library Block
Simscape > Utilities Simulink-PS Converter
Simulink > Sources Sine Wave
The Sine Wave block provides a periodic torque input as a Simulink signal. The Simulink-PS
Converter block converts the Simulink signal to a physical signal compatible with Simscape
Multibody blocks.
3 Connect the blocks as shown in the figure.
4 In the Sine Wave block dialog box, set the Amplitude parameter to 0.06. In the Simulink-PS
Converter block, set the Input signal unit parameter to N*m. An actuation torque that oscillates
between -0.06 N*m and 0.06 N*m applies to the joint.
5 In the Revolute Joint block dialog box, in the Z Revolute Primitive (Rz) > State Targets
section, under Specify Position Target,set Value parameter to 0 deg.
6 Run the simulation.
7 Plot the joint position and velocity with respect to time. To do this, enter this code at the MATLAB
command prompt.
figure
hold on
plot(q)
plot(w)
1-24
Analyze a Single Pendulum
8 Plot the joint phase plot. To do this, enter this code at the MATLAB command prompt:
figure
plot(q.data, w.data)
xlabel('θ (deg)')
ylabel('ω (deg/s)')
See Also
PS-Simulink Converter | Revolute Joint | To Workspace
1-25
1 Introduction to Simscape Multibody Software
More About
• “Force and Torque Sensing”
• “Model a Simple Pendulum” on page 1-15
1-26