0% found this document useful (0 votes)
57 views

SimMechanics Getting Started

Uploaded by

linh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

SimMechanics Getting Started

Uploaded by

linh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

SimMechanics™

Getting Started Guide

R2012a
How to Contact MathWorks

www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support

[email protected] Product enhancement suggestions


[email protected] Bug reports
[email protected] Documentation error reports
[email protected] Order status, license renewals, passcodes
[email protected] Sales, pricing, and general information

508-647-7000 (Phone)

508-647-7001 (Fax)

The MathWorks, Inc.


3 Apple Hill Drive
Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
SimMechanics™ Getting Started Guide
© COPYRIGHT 2002 - 2012 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or
reproduced in any form without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States. By accepting delivery of the Program
or Documentation, the government hereby agrees that this software or documentation qualifies as
commercial computer software or commercial computer software documentation as such terms are used
or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and
conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern
the use, modification, reproduction, release, performance, display, and disclosure of the Program and
Documentation by the federal government (or other entity acquiring for or through the federal government)
and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the
government’s needs or is inconsistent in any respect with federal procurement law, the government agrees
to return the Program and Documentation, unused, to The MathWorks, Inc.

Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
March 2012 Online only New for Release 2012a (Version 4.0)
Contents

Getting Started

Introduction to SimMechanics Software


1
Product Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

Required and Related Products . . . . . . . . . . . . . . . . . . . . . 1-3


Required Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Related Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

First and Second Generation Technologies .......... 1-5

SimMechanics Components . . . . . . . . . . . . . . . . . . . . . . . . . 1-6


Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6
Connection Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

SimMechanics Block Libraries . . . . . . . . . . . . . . . . . . . . . . 1-9


Description of SimMechanics Block Libraries . . . . . . . . . . . 1-9
Opening SimMechanics Libraries . . . . . . . . . . . . . . . . . . . . 1-10

Starting a New SimMechanics Model . . . . . . . . . . . . . . . . 1-13


Opening a New Simulink Editor Window . . . . . . . . . . . . . . 1-13
Adding a SimMechanics Block to a Model . . . . . . . . . . . . . . 1-14
Connecting SimMechanics Blocks . . . . . . . . . . . . . . . . . . . . 1-15
Essential SimMechanics Blocks . . . . . . . . . . . . . . . . . . . . . . 1-17

Double Crank Aiming Mechanism Demo . . . . . . . . . . . . . 1-19


What the Demo Describes . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19
Opening the Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

iii
Modeling Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

Essentials of SimMechanics Software


2
A Simple Mechanical Model . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Examining a Four-Bar Mechanism Model . . . . . . . . . . . . . . 2-2

Rigid Bodies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5


Specifying a Rigid Body with the Solid Block . . . . . . . . . . . 2-5
Examining the Solid Block . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

Modeling an H-Shaped Bar with the Solid Block . . . . . . 2-7


H-Bar Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Selecting and Connecting the Blocks . . . . . . . . . . . . . . . . . . 2-8
Specifying Solid Properties for the H-Shaped Bar . . . . . . . 2-9
Visualizing the H-Shaped Bar Model . . . . . . . . . . . . . . . . . . 2-10

Coordinate Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12


Specifying Coordinate Frames with the Rigid Transform
Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
Examining the Rigid Transform Block . . . . . . . . . . . . . . . . 2-13

Specifying a Joint Attachment Frame with the Rigid


Transform Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Specifying a Joint Attachment Frame . . . . . . . . . . . . . . . . . 2-15
Selecting and Connecting the Blocks . . . . . . . . . . . . . . . . . . 2-15
Specifying Rigid Transform Properties . . . . . . . . . . . . . . . . 2-16
Adding Visualization Aids . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Visualizing the H-Shaped Bar Model . . . . . . . . . . . . . . . . . . 2-19

Joints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
Specifying Joints with Joint Blocks . . . . . . . . . . . . . . . . . . . 2-21
Examining the Joint Blocks . . . . . . . . . . . . . . . . . . . . . . . . . 2-22

Specifying a Joint Between Two Binary Bars . . . . . . . . 2-23


Specifying a Joint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23
Modeling a Complete Four-Bar Mechanism . . . . . . . . . . . . 2-24

iv Contents
Specifying Joint Initial State Targets . . . . . . . . . . . . . . . . . 2-27

Forces and Torques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30


Forces and Torques in SimMechanics . . . . . . . . . . . . . . . . . 2-30

Applying a Force or Torque on a Joint . . . . . . . . . . . . . . . 2-31


Actuation and Internal Forces . . . . . . . . . . . . . . . . . . . . . . . 2-31
Actuating a Joint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31
Applying Damping and Spring Forces to a Joint . . . . . . . . 2-32

Applying a Force or Torque on a Rigid Body . . . . . . . . . 2-34


Forces and Torques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34
Applying a Force or Torque Between Two Rigid Bodies . . . 2-34
Force Parameters and Signals . . . . . . . . . . . . . . . . . . . . . . . 2-35
Specifying Force Parameters . . . . . . . . . . . . . . . . . . . . . . . . 2-36
Specifying an External Force or Torque . . . . . . . . . . . . . . . 2-36

Force and Motion Sensing . . . . . . . . . . . . . . . . . . . . . . . . . 2-38


Sensing in SimMechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38
Sensing Forces and Torques . . . . . . . . . . . . . . . . . . . . . . . . . 2-38
Sensing Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-41

Model and Machine Configuration . . . . . . . . . . . . . . . . . . 2-45


Preparing to Simulate a Model . . . . . . . . . . . . . . . . . . . . . . 2-45
Configuring the Model Environment . . . . . . . . . . . . . . . . . . 2-45
Configuring the Machine Environment . . . . . . . . . . . . . . . . 2-46
Choosing a Simulink Solver . . . . . . . . . . . . . . . . . . . . . . . . . 2-46

Model Visualization and Animation . . . . . . . . . . . . . . . . . 2-48


Assembling and Visualizing a SimMechanics Model in its
Initial State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-48
Simulating and Animating a Mechanical Model . . . . . . . . . 2-50

v
vi Contents
_

Getting Started

Chapter 1, Introduction to Description of SimMechanics™


SimMechanics Software (p. 1-1) software
Chapter 2, Essentials of Overview of SimMechanics
SimMechanics Software (p. 2-1) techniques
1

Introduction to
SimMechanics Software

• “Product Description” on page 1-2


• “Required and Related Products” on page 1-3
• “First and Second Generation Technologies” on page 1-5
• “SimMechanics Components” on page 1-6
• “SimMechanics Block Libraries” on page 1-9
• “Starting a New SimMechanics Model” on page 1-13
• “Double Crank Aiming Mechanism Demo” on page 1-19
1 Introduction to SimMechanics™ Software

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

You can parameterize your models using MATLAB® variables and


expressions, and design control systems for your multibody system in
Simulink®. You can add electrical, hydraulic, pneumatic, and other
components to your mechanical model using Simscape™ and test them all in
a single simulation environment. To deploy your models to other simulation
environments, including hardware-in-the-loop (HIL) systems, SimMechanics
supports C-code generation (with Simulink Coder™).

Key Features
• Blocks and modeling constructs for simulating and analyzing 3D
mechanical systems in Simulink
• Rigid body definition using standard geometry and custom extrusions
defined in MATLAB
• Automatic calculation of mass and inertia tensor
• Simulation modes for analyzing motion and calculating forces
• Visualization and animation of multibody system dynamics with 3D
geometry
• SimMechanics Link utility, providing an interface to Pro/ENGINEER®,
SolidWorks®, and Autodesk Inventor, and an API for interfacing with other
CAD platforms
• Support for C-code generation (with Simulink Coder)

1-2
Required and Related Products

Required and Related Products


In this section...
“Required Products” on page 1-3
“Related Products” on page 1-4

Required Products
To use SimMechanics software, you must have installed current versions of
the following products:

• MATLAB
• Simulink
• Simscape

SimMechanics Visualization Requirements


SimMechanics visualization requires Silicon Graphics OpenGL® graphics
support on your system to display and animate mechanical systems.

You can improve your speed and graphics resolution by adding a graphics
accelerator hardware card to your system. Animation of simulations
is sensitive to central processor and graphics card speed and memory.
Experiment with graphics hardware and system settings to find a reasonable
compromise between quality and speed for your system.

Support for Recorded Animations


You can record simulation animations in Microsoft Audio Video Interleave®
(AVI) format using SimMechanics visualization. Animations are recorded
as compressed AVI files with the default Motion JPEG codec. This codec is
available on most operating systems.

To play back AVI files, you need an AVI-compatible media application.


MATLAB has an internal movie player compatible with AVI. You can also use
an external AVI-compatible player.

1-3
1 Introduction to SimMechanics™ Software

Note SimMechanics visualization does not support uncompressed AVI


recording.

Related Products
You can extend the capability of SimMechanics using other physical modeling
products found in the Simscape family. Each physical modeling product gives
you a set of block libraries with which you can model common components
found in industry and academia: rigid bodies, gears, valves, solenoids, etc.

With the physical modeling products, you can model not only mechanical
systems, but also electrical, hydraulic, and power systems. You can model
each system separately, and then integrate them into a single multiphysics
model where you can analyze their combined performance.

Physical Modeling Product Family


The physical modeling family includes five products:

• SimDriveline™, for modeling and simulating drivetrain systems


• SimElectronics®, for modeling and simulating electronic systems
• SimHydraulics®, for modeling and simulating hydraulic systems
• SimMechanics, for modeling and simulating three-dimensional mechanical
systems
• SimPowerSystems™, for modeling and simulating electrical power systems

1-4
First and Second Generation Technologies

First and Second Generation Technologies


SimMechanics software contains two technologies: First Generation and
Second Generation. These are reflected in the structure of SimMechanics
block libraries and documentation, both of which are organized into First
Generation and Second Generation categories.

First Generation technology includes the SimMechanics block libraries and


computational engine included in all releases prior to R2012a. SimMechanics
continues to support First Generation technology, so that you can run and
edit any First Generation models that you may have.

Second Generation technology includes a completely redesigned set of block


libraries and computational engine. The new blocks are based on a new
approach to mechanical modeling centered on coordinate frames. You can
connect these blocks to First Generation blocks indirectly through Simulink
signals.

This guide is for Second Generation technology only. For information on


First Generation technology, see the SimMechanics User’s Guide for First
Generation technology.

1-5
1 Introduction to SimMechanics™ Software

SimMechanics Components
Blocks, ports, and connection lines form the backbone of any SimMechanics
model.

In this section...
“ Blocks” on page 1-6
“ Ports” on page 1-6
“ Connection Lines” on page 1-7

Blocks

What a Block Is
A block is a ported entity that represents a physical component used in a
machine, a geometric relationship or constraint, or a dynamic element like
force and torque. You can connect blocks to each other using ports and
connection lines. For more information, see “Description of SimMechanics
Block Libraries” on page 1-9.

Ports

What a Port Is
A port allows you to connect one block to other blocks, establishing a
relationship between them.

Types of Ports
In SimMechanics, there are two types of ports, frame and physical signal:

• Frame ports represent a coordinate frame, identifying a location and


orientation in space relative to a reference frame. Frame ports can be:
- Reference—identifies a local reference frame for a SimMechanics
component
- World—identifies a global reference frame for a whole model

1-6
SimMechanics™ Components

- Base—identifies the frame which a block transforms to obtain a new


(follower) frame
- Follower—identifies a new frame obtained by transforming a base frame
• Physical signal ports transmit force and motion signals. Physical signal
ports can be:
- Inports—accept physical signals as input for actuation
- Outports—provide physical signals as output for sensing

Connecting Ports
To connect two compatible ports, you draw a connection line between them.
You can connect a frame port only to another frame port. Likewise, you can
connect a physical signal port only to another physical signal port. You cannot
mix frame and physical signal ports.

Connection Lines

What a Connection Line Does


A connection line connects two or more blocks to each other. Use it to
establish a geometric relationship between two blocks or to transfer physical
signals between them.

Connection Line Types


SimMechanics software uses two types of connection lines:

• Frame connection line—makes two frame ports coincident with each other,
sharing the same location and orientation in space. To specify two different
frames, see .

Note A frame connection line represents a single frame along its length.
When you connect one connection line directly to other connection lines, all
lines represent the same frame along their lengths. Their frames share the
same origin and orientation in space for all time.

1-7
1 Introduction to SimMechanics™ Software

• Physical signal connection line—transmits physical signals, like force and


motion parameters.

Frame and physical signal connection lines look identical in a model. You
identify them by the ports they connect to: a frame connection line always
connects two or more frame ports; a physical signal connection line always
connects two or more physical signal ports.

Drawing Connection Lines


When you hover the mouse over a port, the arrow assumes a cross-hair shape.
Click the port of one block, and hold it while dragging the mouse onto a port
on a second block. This draws a connection line between the two ports.

Note You can connect a frame connection line only to a frame port or to
another frame connection line. You can connect a physical signal connection
line only to a physical signal port or to another physical signal connection line.
You cannot mix frame and physical signal connection lines.

1-8
SimMechanics™ Block Libraries

SimMechanics Block Libraries


In this section...
“Description of SimMechanics Block Libraries” on page 1-9
“Opening SimMechanics Libraries” on page 1-10

Description of SimMechanics Block Libraries


SimMechanics contains two block libraries: First Generation and Second
Generation. This section is about the Second Generation block library. For
information about the First Generation block library see “Block Reference” in
the SimMechanics First Generation documentation.

The SimMechanics Second Generation block library contains six sublibraries.


With the six sublibraries you can define every element in a mechanical model:
bodies, joints and constraints, forces and torques, and more.

SimMechanics™ Product Library

Body Elements
The Body Elements library gives you the basic blocks to model a rigid body,
including blocks for specifying geometry, inertia, and graphic properties. You
can model rigid bodies with simple predefined, solid shapes and colors, or
with custom geometry and inertia. You can also rigidly connect multiple solid
shapes to form compound rigid bodies.

1-9
1 Introduction to SimMechanics™ Software

Constraints
The Constraints library provides blocks to restrict the relative motion
between two body frames. You can constrain two body frames to maintain a
specified distance or a specified angle between them.

Forces and Torques


The Forces and Torques library provides blocks to actuate and otherwise
influence a mechanical model. You can apply different forces and torques to
model the different interactions between components, or between a component
and the external environment.

Frames and Transforms


The Frames and Transforms library provides blocks that allow you to define
and measure spatial relationships between different coordinate frames in
your model.

Joints
The Joints library provides blocks that connect bodies to one another in
kinematic relationships representing different degrees of freedom between
two body frames. These are time-varying relationships that restrict
translation and rotation between the bodies to a specified set of axes.

Utilities
The Utilities library contains blocks to configure solver and simulation
parameters in the SimMechanics environment.

Opening SimMechanics Libraries


You can open the SimMechanics in two ways: by navigating the Simulink
Library browser, or at the MATLAB command line.

From the MATLAB Toolbar


You can open the SimMechanics block library directly from the MATLAB
window.

1-10
SimMechanics™ Block Libraries

1 On the MATLAB toolbar, click the Simulink icon to open the Simulink
Library Browser.

2 In the Libraries section of the Simulink Library browser, click


Simscape > SimMechanics.

3 Select First Generation or Second Generation for the respective


libraries.

4 Click a sublibrary to view its blocks—e.g. Body Elements in the Second


Generation library.

1-11
1 Introduction to SimMechanics™ Software

At the MATLAB Command Prompt


You can open the SimMechanics product library through the MATLAB
command window. At the MATLAB prompt, enter sm_lib at the command
line. The library opens, displaying the six sublibraries. Double-click each
sublibrary to open it.

1-12
Starting a New SimMechanics™ Model

Starting a New SimMechanics Model


In this section...
“Opening a New Simulink Editor Window” on page 1-13
“Adding a SimMechanics Block to a Model” on page 1-14
“Connecting SimMechanics Blocks” on page 1-15
“Essential SimMechanics Blocks” on page 1-17

Opening a New Simulink Editor Window


You build a SimMechanics model in a Simulink Editor window. To start a
new model, you must first open a new Simulink Editor window.

From the MATLAB Window


To open a new Simulink Editor window from the MATLAB window:

• In the MATLAB toolbar, click File > New > Model.

1-13
1 Introduction to SimMechanics™ Software

At the MATLAB Command Line


To open a new Simulink Editor window at the MATLAB command line:

• At the MATLAB command line, enter sm_new. A new Simulink Editor


opens, with some commonly used blocks and the SimMechanics Block
library. For more information, see “Opening SimMechanics Libraries”
on page 1-10.

Adding a SimMechanics Block to a Model


1 Open the Simulink Library Browser. See “Opening SimMechanics
Libraries” on page 1-10.

2 In the Libraries section, select Simscape→SimMechanics to access the


SimMechanics block libraries.

3 Select one of the SimMechanics block libraries.

1-14
Starting a New SimMechanics™ Model

4 Select and add a block to the Simulink Editor window containing your
model.

Connecting SimMechanics Blocks

Connecting Two Ports


You can connect two SimMechanics blocks by drawing a connection line
between two ports. To do this:

1 Click and hold the appropriate port on the first block you wish to connect.

2 Drag the mouse to a compatible port on the second block you wish to
connect.

Note You can only connect a frame port to another frame port. Likewise,
you can only connect a physical signal port to another physical signal port.
For more information, see “ Ports” on page 1-6.

An alternate procedure is to:

1 Click the first block you want to connect.

2 On your keypad, press and hold the Ctrl key.

3 Click the second block you want to connect.

Connecting a Port to a Connection Line


You can also connect two blocks by drawing a connection line from a port to a
connection line. To do this:

1-15
1 Introduction to SimMechanics™ Software

1 Click and hold the appropriate port on the first block you wish to connect.

2 Drag the mouse to the connection line you wish to connect.

Note You can only connect a frame port to a frame connection line.
Likewise, you can only connect a physical signal port to a physical signal
connection line. For more information, see “ Ports” on page 1-6.

An alternate procedure is to:

1 Right-click and hold the connection line you wish to connect.

2 Drag the mouse to a compatible port on the block you wish to connect.

Connecting Two Connection Lines


Finally, you can connect two blocks by drawing a connection line between two
existing connection lines. To do this:

1 Right-click and hold the first connection line you wish to connect

2 Drag the mouse to the second connection line you wish to connect.

1-16
Starting a New SimMechanics™ Model

Note You cannot arbitrarily connect a connection line to another


connection line. You can only connect a frame connection line to another
frame connection line. Likewise, you can only connect a physical signal
connection line to another physical signal connection line. For more
information, see “ Ports” on page 1-6.

Essential SimMechanics Blocks


Most SimMechanics models use three essential blocks: World Frame,
Mechanism Configuration, and Solver Configuration.

To begin building a SimMechanics model, drag and connect these three


blocks in a new Simulink window. When you enter sm_new at the MATLAB
command line, SimMechanics automatically inserts and connects the blocks
for you in a new Simulink window. For more information see “At the
MATLAB Command Prompt” on page 1-12. The following figure shows the
three essential blocks connected by a branched connection line.

1-17
1 Introduction to SimMechanics™ Software

World Frame
World Frame provides a unique inertial frame in a model, against which all
other frames are referenced. Most SimMechanics models employ at least
one World Frame block. This block belongs to the SimMechanics Frames
and Transforms sublibrary.

Mechanism Configuration
Mechanism Configuration provides a gravity vector and a numerical
linearization parameter. Each SimMechanics model can have multiple
Mechanism Configuration blocks, but only one per machine. This block
belongs to the SimMechanics Utilities sublibrary.

Solver Configuration
Solver Configuration provides solver settings for numerical simulation of
a kinematic model. Each SimMechanics model can have multiple Solver
Configuration blocks, but only one per machine. This block belongs to the
Simscape Utilities sublibrary.

1-18
Double Crank Aiming Mechanism Demo

Double Crank Aiming Mechanism Demo


In this section...
“What the Demo Describes” on page 1-19
“Opening the Demo” on page 1-23
“Modeling Workflow” on page 1-23

For the suggested workflow to build a model, see the double crank aiming
mechanism demo on How To Build A Model.

What the Demo Describes


The demo on How to Build a Model models and simulates a double-crank
aiming mechanism, illustrated in the following figure.

1-19
1 Introduction to SimMechanics™ Software

In the model, you can see the rigid bodies and joints that make up the
mechanism. There are four links, connected by four joints: three revolute and
one prismatic. This system is an instance of a planar four-link mechanism, an
important topic in mechanical design.

Bodies
Each body is modeled as a self-contained subsystem, composed of other
SimMechanics blocks behind a mask. You can inspect and even modify the
subsystems in the demo model. To open a subsystem, right click its mask and
select Look Under Mask.

1-20
Double Crank Aiming Mechanism Demo

Inside each subsystem, there are blocks that specify geometry and inertia.
There are also blocks that specify any relevant coordinate frames — such as
those connected to joints. Subsystems are self-contained, and you can alter
them without affecting other subsystems or model architecture. The figure
below shows the block diagram for Rigid Body A in the demo model.

1-21
1 Introduction to SimMechanics™ Software

Joints
Each joint connects two rigid bodies. The joint confers relative degrees of
freedom (DOF) to the two connecting bodies. In the model:

• Prismatic joint Pg allows exactly one translational DOF between rigid


bodies A and C — they can move along a single axis relative to each other.
• Revolute joint Rg allows exactly one rotational degree of freedom between
rigid bodies B and C — they can rotate about one axis relative to each other.
• Revolute joint Ri allows exactly one rotational degree of freedom between
rigid bodies B and D — they can rotate about one axis relative to each other.
• Revolute joint Ro allows exactly one rotational degree of freedom between
rigid bodies C and D — they can rotate about one axis relative to each other.

In the joint block dialog box, you can specify initial state conditions. These
include position and velocity parameters. You can also actuate the two
connecting bodies at the joint with force or torque, and sense their relative
motion parameters — position, velocity and acceleration. To open the dialog
box, double-click the corresponding joint block.

Essential Blocks
Finally, note the use of the three essential blocks: World Frame, Solver
Configuration, and Mechanism Configuration.

World Frame and Solver Configuration are required in every model. The
former provides a common ground to all frame networks in a model; the latter
specifies model-level simulation parameters. Mechanism Configuration is not
required, but important in SimMechanics models — it specifies machine-level
simulation parameters, including the gravity vector. For more information,
see “Essential SimMechanics Blocks” on page 1-17.

1-22
Double Crank Aiming Mechanism Demo

Opening the Demo


To open the demo in a new Simulink window, at the MATLAB command
window type sm_dcrankaim_assembly.

For a guided discussion of the demo, open its supporting documentation:

• At the MATLAB command prompt, type showdemo


sm_double_crank_assembly.
• Alternatively, in the Simulink Help browser, navigate to SimMechanics
Second Generation. Under Demos, click Modeling Techniques, and
then click How To Build A Model.

Modeling Workflow
The demo illustrates the suggested workflow for building a model. It is good
practice to follow this workflow. The key steps highlighted in the demo are:

1 Identify the rigid bodies and joints that comprise the mechanism to model

2 Build an isolated model for each body

3 Assemble the rigid bodies with joints

4 Refine and troubleshoot assembly using Mechanics Explorer and the Model
Report tool

5 Specify the initial configuration using state targets in joint dialog boxes

For more information, refer to the supporting documentation for the demo
(see “Opening the Demo” on page 1-23).

1-23
1 Introduction to SimMechanics™ Software

1-24
2

Essentials of SimMechanics
Software

• “A Simple Mechanical Model” on page 2-2


• “Rigid Bodies” on page 2-5
• “Modeling an H-Shaped Bar with the Solid Block” on page 2-7
• “Coordinate Frames” on page 2-12
• “Specifying a Joint Attachment Frame with the Rigid Transform Block”
on page 2-15
• “Joints” on page 2-21
• “Specifying a Joint Between Two Binary Bars” on page 2-23
• “Forces and Torques” on page 2-30
• “Applying a Force or Torque on a Joint” on page 2-31
• “Applying a Force or Torque on a Rigid Body” on page 2-34
• “Force and Motion Sensing ” on page 2-38
• “Model and Machine Configuration” on page 2-45
• “Model Visualization and Animation” on page 2-48
2 Essentials of SimMechanics™ Software

A Simple Mechanical Model

Examining a Four-Bar Mechanism Model


In SimMechanics, you model a mechanical system as a set of rigid bodies
connected by joints. One example is the four-bar mechanism illustrated
below. This mechanism contains four separate bars, each with a well defined
position and orientation, shape and size, mass and inertia.

To model a system like this four-bar mechanism, you must specify a set
of properties and coordinate frames for each bar. You do this by adding
and connecting SimMechanics blocks on the Simulink Editor window, and
providing any relevant parameters through the block dialog box.

X
Z

Inertia

The following figure shows an elementary SimMechanics model of the


four-bar mechanism. It is a block diagram, with blocks specifying the rigid
bodies that make up the mechanism, and the joints used to connect them.
Frame ports and connection lines identify a location and orientation for each
key point in a rigid body—for example, a joint attachment point. In this
model, the constituent bodies are four binary bars (dyads), interconnected
by four revolute joints.

2-2
A Simple Mechanical Model

Each binary bar has two joints, one at each end. In this model, a binary bar
is represented by one solid block, specifying its physical properties, and two
Rigid Transform blocks, specifying its joint attachment points.

There are three highlighted areas. Each represents a key piece of the model:
a rigid body, a joint, and other essential blocks. The rigid body area has two
types of blocks:

• Solid
• Rigid Transform

You use these blocks to specify a set of properties and coordinate frames for
each rigid body. For more information, see “Rigid Bodies” on page 2-5 . See
also “Coordinate Frames” on page 2-12.

The Joint area has one block:

2-3
2 Essentials of SimMechanics™ Software

• Revolute Joint

You use this block specify the allowed degrees of freedom between two rigid
bodies. There are fourteen different Joint blocks that you can use. For more
information, see “Joints” on page 2-21.

The essential blocks area has three blocks:

• World Frame
• Mechanism Configuration
• Solver Configuration

You use these blocks to specify a unique inertial reference frame, a gravity
vector, as well as linearization and solver parameters. For more information,
see “Essential SimMechanics Blocks” on page 1-17.

The blocks shown above give you the basic tools to build a simple model.
With them, you can begin exploring the capability of SimMechanics. You are
not limited to these blocks. Add others as needed—to actuate your model,
constrain its motion, and sense force or motion parameters.

2-4
Rigid Bodies

Rigid Bodies
In this section...
“Specifying a Rigid Body with the Solid Block” on page 2-5
“Examining the Solid Block” on page 2-5

Specifying a Rigid Body with the Solid Block


To specify a rigid body, you use one or more blocks from the Body Elements
library. You can use Solid, Inertia, or Graphic blocks. The Solid block
combines inertia and graphic options into a single block, and is recommended
for new users. This block represents the simplest body that you can define.

Examining the Solid Block


The Solid block provides:

• A single frame port identifying a local reference frame.


• A set of adjustable properties used to define a rigid body.

nce
e fere e
R ram
F Y’
X’
.
C.M Geometry
Z’

Inertia
Graphic

For solids with simple predefined shapes, the local reference frame has an
origin at the center of geometry, and axes aligned with the solid’s axes of
symmetry. The following table lists the solid properties which you can specify.

2-5
2 Essentials of SimMechanics™ Software

Property What it specifies


Geometry Shape and size
Inertia Mass, density, moments and
products of inertia
Graphic Graphical representation
For more information, see the Solid block reference documentation.

2-6
Modeling an H-Shaped Bar with the Solid Block

Modeling an H-Shaped Bar with the Solid Block


In this section...
“H-Bar Example” on page 2-7
“Selecting and Connecting the Blocks” on page 2-8
“Specifying Solid Properties for the H-Shaped Bar” on page 2-9
“Visualizing the H-Shaped Bar Model” on page 2-10

H-Bar Example
With the Solid block, you can select a pre-specified geometry (brick, cylinder,
or sphere) or a custom geometry with constant cross-section (regular and
general extrusion). A more advanced alternative allows you to import a
custom geometry using an .STL file.

In this example, you use the Solid block to specify an H-shaped bar. Later,
you can use Rigid Transform blocks to specify multiple joint attachment
points. For more information, see “Specifying a Joint Attachment Frame with
the Rigid Transform Block” on page 2-15.

The following figure illustrates the cross-section of the H-shaped bar modeled
in this example.

[-5 12] [5 12]


[-5 10] [5 10]
[-2.5 10] [2.5 10]

[-2.5 -10] [2.5 -10]


[-5 -10] [5 -10]
[-5 -12] [5 -12]

2-7
2 Essentials of SimMechanics™ Software

Selecting and Connecting the Blocks


1 Open a new Simulink Editor window. See “Opening a New Simulink Editor
Window” on page 1-13.

2 Make sure the Simulink Library Browser is open. See “Opening


SimMechanics Libraries” on page 1-10

3 In the Libraries section of the Simulink Library Browser, select


Simscape > Utilities.

4 In the Utilities library, select one Solver Configuration block and drag it
onto the Simulink Editor window.

5 In the Libraries section of the Simulink Library Browser, select


Simscape > SimMechanics > Second generation.

6 Select and drag one each of the following blocks onto the Simulink Editor
window:

Block Sublibrary
World Frame Frames and Transforms
Mechanism Configuration Utilities
Solid Body Elements library

7 Connect the blocks as shown in the following figure. See “Connecting


SimMechanics Blocks” on page 1-15.

2-8
Modeling an H-Shaped Bar with the Solid Block

Specifying Solid Properties for the H-Shaped Bar

Specifying Geometry

1 In your model, double-click the Solid block to open its dialog box.

2 In the Geometry section of the dialog box, select General Extrusion from
the Shape drop-down list.

Tip The General Extrusion option allows you to specify a solid with an
arbitrary cross-sectional shape.

3 In the Cross-section field, enter a matrix containing the cross-sectional


vertices for the H-shaped bar: [5 12; 5 10; 2.5 10; 2.5 10; 5 10;
5 12; 5 12; 5 10; 2.5 10; 2.5 10; 5 10; 5 12].

4 In the unit drop-down list, select mm (millimeter).

5 In the Length field, enter 200, and select mm for the units.

Specifying Inertia

1 In the Inertia section of the dialog box, leave Type as Calculate from
Geometry.

Tip Leaving Type as Calculate from Geometry lets SimMechanics


compute the moments of inertia for you. When you select this option, you
do not need to specify the moments of inertia directly.

2 Check that the Based on field is set to Density.

3 In the Density field, enter the density of steel, 7750 kg/m3.

2-9
2 Essentials of SimMechanics™ Software

Specifying Graphic

1 In the Graphic section of the dialog box, leave Type as From Geometry.

2 In the Visual Properties field, select Simple.

3 Expand the Visual Properties expandable menu.

4 In the Color field, select the color you wish to apply to the H-shaped bar.
You can also specify the [R G B] color vector, for example [1 0.8 0.8].

5 In the Opacity field, specify a value smaller than 1.0 to make the H-shaped
bar transparent.

Visualizing the H-Shaped Bar Model


You can visualize the H-shaped bar model using the Mechanics Explorers
window. On your keyboard, press Ctrl+D. Mechanics Explorers opens up,
displaying the H-shaped bar you just modeled.

Note Mechanics Explorers is an advanced visualization and animation tool.


You can use it to visualize, animate, and optimize your mechanical model.

2-10
Modeling an H-Shaped Bar with the Solid Block

2-11
2 Essentials of SimMechanics™ Software

Coordinate Frames
In this section...
“Specifying Coordinate Frames with the Rigid Transform Block” on page
2-12
“Examining the Rigid Transform Block” on page 2-13

Specifying Coordinate Frames with the Rigid


Transform Block
Coordinate frames allow you to specify both position and orientation for any
rigid body and joint in your model. This spatial information allows two rigid
bodies to connect via a joint placed at the right location and with the proper
orientation. It also allows you to exert a force or torque anywhere, and in any
direction, on a rigid body. You must define a coordinate frame for every point
of interest in a model. To define an arbitrary frame with respect to another
frame, use the Rigid Transform block.

The Rigid Transform block operates on one frame (the base frame) to define a
second frame (the follower frame). You can use this block to specify a frame
with arbitrary position and orientation. Use multiple Rigid Transform blocks
to specify multiple frames in your model.

Note Itself, the Rigid Transform block does not represent a coordinate frame.
Instead, it represents the mathematical operation that is used to create one
frame from another.

The Rigid Transform block performs two operations:

• Translation
• Rotation

2-12
Coordinate Frames

Translate Rotate

Base Follower

When using a Rigid transform block, you are free to specify translation
only, rotation only, or both. When you specify both translation and rotation
operations, translation applies first, followed by rotation. If you do not
specify a transform operation, the Rigid Transform block behaves as a frame
connection line, making the base and follower frames coincident with each
other.

Note The follower frame of the Rigid Transform block is rigidly defined with
respect to the base frame. There is a static relationship between these two
frames. They cannot move independently, but only as a set.

Examining the Rigid Transform Block


The Rigid transform block provides two frame ports:

Frame Frame Port Connect this port to


identify...
Base B The frame on which
the specified transform
operates
Follower F The frame which results
from the specified
transform

2-13
2 Essentials of SimMechanics™ Software

e2
ram
rF
Y’ lo we
X’ Fol
.
C.M

Z’
me
Fra
Base

e1
ram
rF
lo we
Fol

The following table lists the properties which you can specify using the
Rigid Transform block. These properties correspond to the Rigid Transform
operations listed above (translation along and rotation about a single axis).

Property Function
Rotation Specify a method to rotate the
follower frame with respect to the
base frame
Translation Specify a method to translate the
follower frame with respect to the
base frame
For more information, see theRigid Transform block reference documentation.

2-14
Specifying a Joint Attachment Frame with the Rigid Transform Block

Specifying a Joint Attachment Frame with the Rigid


Transform Block
In this section...
“Specifying a Joint Attachment Frame” on page 2-15
“Selecting and Connecting the Blocks” on page 2-15
“Specifying Rigid Transform Properties ” on page 2-16
“Adding Visualization Aids” on page 2-17
“Visualizing the H-Shaped Bar Model” on page 2-19

Specifying a Joint Attachment Frame


In SimMechanics, you specify any frame of interest using the Rigid Transform
block. Frames of interest include joint, actuation, and sensing points in a
rigid body. In this example, you use two Rigid Transform blocks to specify two
joint attachment frames in the H-shaped bar modeled above (see “Modeling
an H-Shaped Bar with the Solid Block” on page 2-7). Once you’ve specified
the joint attachment points in a binary bar, you can connect them with joints
to assemble a four-bar mechanism.

Note This example does not show you how to use the Joint block. For an
example showing how to connect two binary bars with a joint block, see
“Specifying a Joint Between Two Binary Bars” on page 2-23

Selecting and Connecting the Blocks


1 In the Libraries section of the Simulink Library Browser, select
Simscape > SimMechanics > Second Generation > Frames and
Transforms.

2 Select and drag two Rigid Transform blocks to the Simulink Editor window
containing your model.

3 Connect the Base (B) frame ports to the connection line attached to the
Reference (R) frame port belonging to the Solid block.

2-15
2 Essentials of SimMechanics™ Software

Note You can rotate a block to better position its base frame port. To
rotate a block, on your keyboard press Ctrl+R. Each time you use this
shortcut, the selected block rotates 90 degrees clockwise.

Recall that a connection line represents a single frame along its entire length.
Also, two connection lines connected to each other share the same frame along
their entire lengths. In this figure, the two Rigid Transform base frames are
coincident with the Solid reference frame. The follower frames are defined
relative to the Solid reference frame.

Specifying Rigid Transform Properties

Rotation
You can rotate the follower frame relative to the base frame. You do this in the
Rotation section of the Rigid Transform dialog box. With the graphic markers
added to your model, it is easy to visualize the orientation of each frame.

1 In your model, double-click the Rigid Transform block to open its dialog box.

2 In the dialog box, expand the Rotation menu.

2-16
Specifying a Joint Attachment Frame with the Rigid Transform Block

3 Set the Rotation Method to Aligned Axes.

4 Specify Pair 1 and Pair 2:

Frame Base Follower


Pair 1 -X +Z
Pair 2 +Z +X

Translation
You can translate the follower frame relative to the base frame. You do this in
the Translation section of the Rigid Transform dialog box. With the graphic
markers added to your model, it is easy to visualize the location of each frame.

1 In the Rigid Transform dialog box, expand the Translation menu.

2 Set the Method field to Standard Axis.

3 Set the Axis field to +Z.

4 In the Offset field, specify the distance from the bar’s center of geometry to
the joint location. In the H-shaped bar example, specify +100 mm for the
first transform, and -100 mm for the second transform.

Adding Visualization Aids

Selecting and Connecting the Blocks


You can add a Graphic block to visualize any frame in your model. This block
has no physical properties, and does not affect model dynamics. The Graphic
block functions strictly as a visual aid.

1 In the SimMechanics Second Generation library, select Body Elements.

2 Select and drag three Graphic blocks to the Simulink Editor window
containing your model.

3 Connect two Graphic blocks to the follower frame port (F) on the Rigid
Transform blocks.

2-17
2 Essentials of SimMechanics™ Software

4 Connect the remaining Graphic block to the frame connection line attached
to the solid block.

Specifying Graphic Properties


You can specify different graphic icons to represent a frame. The Frame icon
is particularly useful to visualize the relative orientation of different frames.
You can select a different color for each frame, and you can specify a size
that’s convenient for you.

1 Double-click a Graphic block to open its dialog box.

2 Set the Shape field to Frame to visualize the attached frame as a


coordinate frame.

3 Specify a size that’s convenient for you, for example 30 pixels.

Note Graphic icon size is defined in pixel units. The size remains constant
regardless of the zoom setting in the Mechanics Explorers window.

4 In the Visual Properties field, select a unique color for your graphic.

5 Repeat for the remaining Graphic blocks.

2-18
Specifying a Joint Attachment Frame with the Rigid Transform Block

Visualizing the H-Shaped Bar Model


You can visualize the coordinate frames in the H-shaped bar model using the
Mechanics Explorers window. On your keyboard, press Ctrl+D. A Mechanics
Explorers opens up, displaying the H-shaped bar you just modeled. The
coordinate frames appear as frame icons, each corresponding to one Graphic
block in your model. For more information, see “Model Visualization and
Animation” on page 2-48.

Note Mechanics Explorers is an advanced visualization and animation tool.


You can use it to visualize, animate, and optimize your mechanical model.

2-19
2 Essentials of SimMechanics™ Software

2-20
Joints

Joints
In this section...
“Specifying Joints with Joint Blocks” on page 2-21
“Examining the Joint Blocks” on page 2-22

Specifying Joints with Joint Blocks


Once you’ve defined two rigid bodies in a model, you can connect them using a
Joint block. Joints specify how two connecting bodies can move. They limit
the degrees of freedom between the two connecting bodies, constraining them
to move along or about a limited set of axes.

In SimMechanics, every joint is defined in terms of joint primitives:


elementary joints, from which all other joints can be built. There are three
joint primitives:

• Prismatic primitive: constrains motion to translation along a single axis.

Base Follower

• Revolute primitive: constrains motion to rotation about a single axis.

er Base
low
Fol Y Y
X
X
Z

• Spherical primitive: constrains motion to rotation about three Cartesian


axes.

2-21
2 Essentials of SimMechanics™ Software

er Base
Follow

Examining the Joint Blocks


A Joint block specifies a time-varying relationship between two frames, a base
and a follower. . This transformation is similar to that in Rigid Transform
blocks, except that it is time dependent. For more information, see “Examining
the Rigid Transform Block” on page 2-13.

Every Joint block has two frame ports, base and follower:

• Base—identifies the frame to be transformed.


• Follower—identifies the resulting frame after the transformation.

Base Follower
Y Y’
X

X’
Z
Z

The Joint block gives you the option to specify an initial state, apply forces
and sense motion for each joint primitive.

Property Function
State Targets Specify the initial position and
velocity of a joint primitive
Internal Mechanics Specify damping and spring forces
acting on a joint primitive
Actuation Select a mode of actuation for a joint
primitive
Sensing Select the motion parameters you
wish to sense in a joint primitive

2-22
Specifying a Joint Between Two Binary Bars

Specifying a Joint Between Two Binary Bars


In this section...
“Specifying a Joint” on page 2-23
“Modeling a Complete Four-Bar Mechanism” on page 2-24
“Specifying Joint Initial State Targets” on page 2-27

Specifying a Joint
You can use a Joint block to connect any two rigid bodies with a desired set
of degrees of freedom. In this example, you use a Joint block to connect two
H-shaped binary bars as defined above (see “Specifying a Joint Attachment
Frame with the Rigid Transform Block” on page 2-15.

Selecting and Connecting the Blocks


1 Open the SimMechanics Second Generation sublibrary. See “Opening
SimMechanics Libraries” on page 1-10

2 In the Joints sublibrary, select and drag a Revolute Joint block into a
Simulink Editor window containing your model.

3 In each binary bar, identify the Rigid Transform block which specifies
the joint attachment point.

4 Connect the first Rigid Transform block to the base frame port on the
Revolute Joint block.

5 Connect the second Rigid Transform block to the follower frame port on the
Revolute Joint block.

The following figure shows portion of a SimMechanics model. In this model, a


revolute joint block connects two rigid body subsystems, giving them a single
rotational degree of freedom about a shared axis.

2-23
2 Essentials of SimMechanics™ Software

Modeling a Complete Four-Bar Mechanism


Each Joint block connects two and only two rigid bodies. You can use as many
joint blocks as needed to model a multi-body system. The following figure
shows a complete model of a simple four-bar mechanism.

2-24
Specifying a Joint Between Two Binary Bars

To build a complete model of a four-bar mechanism:

1 Select, drag and connect the three blocks outlined in “Essential


SimMechanics Blocks” on page 1-17 to your model window.

2 Model the four binary bars employed in the four-bar mechanism. For
more information, see “Specifying a Rigid Body with the Solid Block” on
page 2-5 and “Specifying Coordinate Frames with the Rigid Transform
Block” on page 2-12.

Tip When two rigid bodies are similar to each other, you can often build
a model for one body, then copy and paste it to model the second body.
You can change any properties as needed by opening the Solid and Rigid
Transform block dialog boxes.

2-25
2 Essentials of SimMechanics™ Software

3 Select and drag four Revolute Joint blocks from the SimMechanics Joints
library to your model window.

4 Connect each pair of binary bars with a single Revolute Joint box. For more
information, see “Specifying Joints with Joint Blocks” on page 2-21.

The following figure shows the model of a four-bar mechanism in its initial
state, using the Mechanics Explorers tool.

2-26
Specifying a Joint Between Two Binary Bars

Once you have a working SimMechanics model, you can simulate and
visualize its dynamic behavior using the Mechanics Explorers tool. The
following figure illustrates the model of a four-bar mechanism at different
points in time during the simulation. For more information, see “Model
Visualization and Animation” on page 2-48.

Specifying Joint Initial State Targets


SimMechanics can assemble your model automatically into an initial state
configuration. However, you can specify the desired initial state for any joint
in your model. The initial state of a joint includes the following parameters:

• Initial position
• Initial velocity

Specifying a joint’s initial state is especially important if there are multiple


possible initial states. In this case, you can guide SimMechanics assembly into
the right state simply by providing joint initial state targets. You do not have
to provide exact initial state values for a joint—approximate values suffice.

2-27
2 Essentials of SimMechanics™ Software

When you specify a joint’s initial state targets, there are two priority settings
which you can select:

• High—SimMechanics tries to match the specified joint initial state exactly.


• Low—SimMechanics tries to match the specified joint initial state
approximately.

To specify a joint’s initial state targets:

1 In your model window, double-click any joint block whose initial state you
wish to specify.

2 In the Properties area of the dialog box, click the State Targets
expandable menu to display more options.

3 Check the box for the parameter you wish to specify, Position or Velocity.
Additional fields appear.

4 Specify a priority setting for the initial state target: High or Low.

5 Enter an initial state value and select its physical units.

6 Close the joint block dialog box.

The following figure shows a four bar mechanism in its default assembly
configuration, and in a guided assembly configuration.

2-28
Specifying a Joint Between Two Binary Bars

Guided Assembly

Default Assembly

2-29
2 Essentials of SimMechanics™ Software

Forces and Torques

Forces and Torques in SimMechanics


Forces and torques act to alter the motion state of a rigid body. In mechanical
systems, there are different forces of interest, including actuation, damping,
and spring forces. In SimMechanics, you can input, output, and sense forces
and torques as time-dependent physical signals.

Depending on the application, you can apply a force or torque either at a joint
or on a rigid body. Because joint actuation is very common in mechanical
systems, SimMechanics Joints blocks are designed to accept actuation inputs.
To actuate a rigid body or subsystem instead of a joint, use one of the blocks
provided in the Forces and Torques library.

To input and output forces and torques, SimMechanics blocks employ two
types of ports, outlined in the following table.

Port Type What it does Where you can find


it
Physical signal inport Receive a physical External Force and
signal specifying one or Torque only
more forces and torques
Identify the frame All Forces & Torques
Frame subjected to a forces blocks
and torques
For more information, see “ Ports” on page 1-6.

2-30
Applying a Force or Torque on a Joint

Applying a Force or Torque on a Joint


In this section...
“Actuation and Internal Forces” on page 2-31
“Actuating a Joint” on page 2-31
“Applying Damping and Spring Forces to a Joint” on page 2-32

Actuation and Internal Forces


Joints blocks accept physical signals specifying forces and torques acting
on a joint. You have the option to actuate each joint primitive individually.
Each joint primitive is associated with a unique physical signal inport,
which receives the actuation signal. Each joint primitive provides a different
actuation mode, characteristic of the type of motion it allows, linear or
rotational. The following table lists the actuation modes that you can specify
for different joint primitives.

Joint Primitive Actuation Mode


Prismatic None, Force
Revolute None, Torque
Spherical None, Torque
Joints blocks also accept a set of parameters specifying internal forces,
including spring and damping forces. You can provide internal force
parameters individually for each joint primitive. Internal force parameters
that you can provide for each internal force include:

• Spring Force: Equilibrium Position, Spring Stiffness


• Damping Force: Damping Coefficient

Actuating a Joint
To actuate a joint, perform the following steps:

1 In the Simulink window for your model, double-click the joint you wish to
actuate.

2-31
2 Essentials of SimMechanics™ Software

2 In the joint block dialog box, click the expandable menu for the joint
primitive you wish to actuate (e.g. Z Prismatic Primitive (Pz)).

3 Click the Actuation expandable menu.

4 In the Mode drop-down list, select the appropriate actuation input type to
expose a physical signal inport: none, force, or torque.

Note Force actuation mode is present in the Actuation menu for prismatic
joint primitives only. Torque actuation mode is present in the Actuation
menu for revolute joint primitives only.

5 Attach a connection line to the exposed physical signal inport, specifying


a force input. For more information, see “Specifying an External Force or
Torque” on page 2-36.

Applying Damping and Spring Forces to a Joint


To add damping or spring mechanics to a joint primitive:

2-32
Applying a Force or Torque on a Joint

1 In the Simulink window for your model, double-click the joint you wish to
actuate.

2 In the joint block dialog box, click the expandable menu for the joint
primitive you wish to actuate (e.g. Z Prismatic Primitive (Pz)).

3 Click the expandable menu for Internal Mechanics.

4 Enter the equilibrium position, spring stiffness, and damping coefficient


for the joint.

For more information, see the “Joints” reference documentation.

2-33
2 Essentials of SimMechanics™ Software

Applying a Force or Torque on a Rigid Body


In this section...
“Forces and Torques” on page 2-34
“Applying a Force or Torque Between Two Rigid Bodies” on page 2-34
“Force Parameters and Signals” on page 2-35
“Specifying Force Parameters” on page 2-36
“Specifying an External Force or Torque” on page 2-36

Forces and Torques


Forces and Torques blocks allow you to specify external or internal forces.
You can input or output forces and torques acting on any frame in your model.

Applying a Force or Torque Between Two Rigid


Bodies
To add a force block to a model:

1 In the Simulink Library browser, expand the SimMechanics Second


generation block library.

2 From the Forces and Torques sublibrary, select and drag a force block
into the Simulink Editor window containing your model.

3 Connect the follower frame port of the force block to the frame you wish to
actuate.

4 Connect the base frame port of the force block to the frame where the
force originates.

Note Only two Forces and Torques blocks have a base frame port: Spring
and Damper Force, and Inverse Square Law Force. The External Force
and Torque block applies a force originating outside the system, and does
not need a base frame port.

2-34
Applying a Force or Torque on a Rigid Body

The following figure shows part of a SimMechanics model containing two rigid
bodies connected by a Spring and Damper Force.

Force Parameters and Signals


Force blocks accept either a set of force constants or a physical signal as input.
The following table outlines the method used in each block:

Force Block Specification Method


External Force and Torque Provide an external physical signal
as input.
Spring and Damper Force Provide a set of force constants.
Inverse Square Law Force Provide a set of force constants.

2-35
2 Essentials of SimMechanics™ Software

Specifying Force Parameters


To specify a force constant:

1 In your model, double-click the force block you wish to specify.

2 In the block diagram box, enter the appropriate force constant and other
required force parameters.

Specifying an External Force or Torque


The External Force & Torque block provides a physical signal inport, which
accepts a force input connection line. To connect a physical signal connection
line to the External Force & Torque force block:

1 Double-click the External Force & Torque block and select the force
components you wish to specify. The corresponding physical signal outports
appear on the affected block.

2 Connect the exposed physical signal outports to a physical signal connection


line defining the time-dependent force signal.

You can use Simulink source blocks to specify an arbitrary force or other
physical signal. However, Simulink signals are strictly numeric and carry no
physical units. To use a Simulink signal in a SimMechanics model, you must
first convert it to a physical signal.

1 Drag a Simulink-PS Converter block to the Simulink Editor window


containing your model.

2 Connect its physical signal outport to the physical signal inport on


the force block.

3 Connect its Simulink signal inport to the Simulink signal outport on


the desired Simulink Source block.

2-36
Applying a Force or Torque on a Rigid Body

4 Double-click the Simulink-PS Converter block and specify the desired


physical units.

The following figure shows portion of a SimMechanics model, using a


converted Simulink signal to specify a time dependent external force.

2-37
2 Essentials of SimMechanics™ Software

Force and Motion Sensing


In this section...
“Sensing in SimMechanics” on page 2-38
“Sensing Forces and Torques” on page 2-38
“Sensing Motion” on page 2-41

Sensing in SimMechanics
In SimMechanics, you can sense forces acting on a rigid body. When you
sense a force, SimMechanics records its value at each instant in time, so that
you can plot them in a chart or feed them into a control system. You can only
sense forces at points defined by a coordinate frame. Before you sense a force
at an arbitrary point, check that you’ve defined a coordinate frame at that
point. For more information, see“Coordinate Frames” on page 2-12.

Two blocks allow you to sense forces:

• Spring and Damper Force


• Inverse Square Law Force

You can only sense forces if your model includes one of these two Forces and
Torques blocks.

You can also sense motion parameters like the linear and angular position,
velocity, and acceleration at a point in a machine. Like forces, you can only
sense motion parameters at points defined by a coordinate frame. You can
sense motion parameters through all Joint blocks except the Weld Joint
block. You can only sense motion parameters if your model includes one of
these Joint blocks.

Sensing Forces and Torques


To sense force in a mechanical model:

1 Confirm that your model uses at least one of the two following blocks:

• Spring and Damper Force

2-38
Force and Motion Sensing

• Inverse Square Law Force

2 Double-click one of the above force blocks in your model.

3 In the block dialog box, check the Sense Force box. A physical signal port
is exposed allowing you to output the force signal. You can plot the force
signal using a Simulink Scope or XY Graph block, or you can feed it to a
feedback loop used to control your model.

Note To feed a Simscape-based physical signal to a Simulink block, you


must first convert it to a Simulink signal using a PS-Simulink Converter
block. For more information, see the documentation for the PS-Simulink
Converter block.

The following figure illustrates force-sensing in the model of a four-bar


mechanism as shown in “Modeling a Complete Four-Bar Mechanism” on page
2-24.

2-39
2 Essentials of SimMechanics™ Software

Adding spring and damping forces between two of the binary bars yields a
periodic force signal that decays as a function of time. In the model illustrated
above, you can double-click the scope block to open a plot of the time-varying
force signal between the two binary bars.

2-40
Force and Motion Sensing

Sensing Motion
To sense motion in a mechanical model:

1 Confirm that your model uses at least one Joint block other than Weld
Joint.

2 Double-click the Joint block at which you wish to sense motion parameters.

3 In the dialog box, click the expandable menu for the joint primitive you
wish to sense—for example Z Revolute Primitive (Rz).

4 click the Sensing expandable menu.

5 Check the motion parameters which you wish to sense. Options include
Position, Velocity, and Acceleration.

Note You can sense linear or angular motion parameters. Prismatic


primitives support sensing for linear motion parameters. Revolute and
spherical primitives support sensing for angular motion parameters.

2-41
2 Essentials of SimMechanics™ Software

For each motion parameters you choose to sense, a physical signal outport
appears on the selected joint block. You can plot each motion parameter in
a Simulink Sinks block—e.g. Scope or XY Graph.

Note To feed a Simscape-based physical signal to a Simulink block, you


must first convert it to a Simulink signal using a PS-Simulink Converter
block. For more information, see the documentation for the PS-Simulink
Converter block.

In the following figure, a Revolute Joint Block is configured to sense angular


position and angular velocity. Two physical signal outports are present in this
block, each connected to a PS-Simulink Converter block which makes them
compatible with Simulink Sink blocks. The model shown corresponds to the
four-bar mechanism as shown in “Modeling a Complete Four-Bar Mechanism”
on page 2-24.

2-42
Force and Motion Sensing

Configuring the Internal Mechanics section of the Joint dialog box to add
damping, yields periodic angle and angular velocity signals that decay as a
function of time. In the model illustrated above, you can double-click the
scope block during simulation to obtain a plot of the time-varying angle and
angular velocity signals.

2-43
2 Essentials of SimMechanics™ Software

2-44
Model and Machine Configuration

Model and Machine Configuration


In this section...
“Preparing to Simulate a Model” on page 2-45
“Configuring the Model Environment” on page 2-45
“Configuring the Machine Environment” on page 2-46
“Choosing a Simulink Solver” on page 2-46

Preparing to Simulate a Model


Before you can simulate and animate a mechanical model, you must verify
the following:

• Mechanism Configuration Settings—for each machine in your model.


• Simulation Configuration Parameters—for the whole model.

Configuration Level Access configuration parameters


with...
Model-wide Simulink Configuration Parameters
Machine-wide Mechanism Configuration block
dialog box

Note A machine is a complete, connected block diagram that represents one


mechanical system. It is topologically isolated from any other machine in your
model and has at least one World Frame and one Mechanism Configuration
block. One model can have multiple machines.

Configuring the Model Environment


The Configuration Parameters dialog box is a standard feature of Simulink.
Reset its entries for models in the SimMechanics environment to obtain more
accurate simulation results.

2-45
2 Essentials of SimMechanics™ Software

1 In the Simulink menu bar, open the Simulation menu and click
Configuration Parameters to open the Configuration Parameters dialog.

2 Select the Solver node of the dialog. Under Solver options, change
Relative tolerance to 1e-6 and Absolute tolerance to 1e-4. Change
Max step size to 0.2.

If you want the simulation to continue running without stopping, change


Stop time to inf. The pendulum period is approximately 1.6 seconds.

3 Close the Configuration Parameters dialog box.

Configuring the Machine Environment


A special feature of SimMechanics models is the Mechanism Configuration
block.

1 Open Mechanism Configuration block dialog box.

2 Note the default Gravity vector, [0 0 -9.81] m/s2, which points in the
–Z direction. The gravitational acceleration is g = 9.81 m/s2.

3 Note the default Linearization value, 0.001. This value specifies the
linearization delta perturbation value to compute the numerical partial
derivations for linearization. Change this value as necessary.

4 Close the Mechanism Configuration block dialog box.

Choosing a Simulink Solver


SimMechanics models support all Simulink solvers, depending on the model
design.

2-46
Model and Machine Configuration

If Your SimMechanics See...


Model
Is a simple mechanical Existing Simulink guidelines when choosing
system with few Simscape a solver for your mechanical system model.
blocks For more information on Simulink solvers in
general, see “Choosing a Solver Type” in the
Simulink User’s Guide.
Is a more complex Existing Simscape guidelines for solvers.
mechanical system with For more information on these solvers,
many Simscape blocks see “Changing the Simulink Solver and
Tolerances” and “Setting Up Solvers for
Physical Models” in the Simscape User’s
Guide.

2-47
2 Essentials of SimMechanics™ Software

Model Visualization and Animation


When you simulate a model, the Simulink environment displays changes
in the model in the model editor. The model editor does not visualize the
data from the mechanical animation. To visualize the animation, use the
Mechanics Explorer. By default, updating or simulating a SimMechanics
model starts the Mechanics Explorer for that model.

The Mechanics Explorer has a number of controls that allow you to control
the visualization of the animation. For more information on these controls,
see “SimMechanics Visualization”.

Note If you start to simulate your model, the machine automatically


attempts assembly as an intermediate step before simulation itself begins.

In this section...
“Assembling and Visualizing a SimMechanics Model in its Initial State”
on page 2-48
“Simulating and Animating a Mechanical Model” on page 2-50

Assembling and Visualizing a SimMechanics Model


in its Initial State
1 Open a Simulink Editor window with the mechanical model you wish to
visualize.

2 On your keyboard, press Ctrl+D to assemble and visualize the mechanical


model. A Mechanics Explorers window opens, with the mechanical model
in its initial state. By default, the Mechanics Explorer is docked in the
MATLAB Command Window.

2-48
Model Visualization and Animation

3 Press Ctrl+T to simulate the mechanical model. Alternatively, press the


Play button in either the Simulink Editor or the Mechanics Explorers
window. The Mechanics Explorers window displays a kinematic animation
of your model. For more information about using Mechanics Explorers, see
“Configuring Mechanics Explorer for Automatic Start-Up”.

To open an example model of a four-bar mechanism that you can visualize and
simulate, at the MATLAB command line, type sm_four_bar, or click here.
The following figure shows the sm_four_bar model in its initial state.

2-49
2 Essentials of SimMechanics™ Software

Simulating and Animating a Mechanical Model

Simulating a SimMechanics Model


To simulate and animate a mechanical model;

1 Check that your model has been properly configured. For more information,
see “Model and Machine Configuration” on page 2-45

2 Check that your model has been properly assembled in an initial state.
For more information, see “Assembling and Visualizing a SimMechanics
Model in its Initial State” on page 2-48

3 In the Mechanics Explorers toolbar, click the Start button


to start the
simulation. The Mechanics Explorers window plays a kinematic animation
of the simulated model.

2-50
Model Visualization and Animation

Note By default, the simulation runs for a time interval of 10 seconds.


To change the simulation run time, see Configuration Parameters in the
Simulink Reference documentation.

Playing Back a SimMechanics Animation


Each time you simulate a mechanical model, SimMechanics automatically
caches the animation data for future replay. This feature allows you to play
back an animation without the need to rerun the simulation. To control an
animation, use the animation toolbar at the bottom of the Mechanics Explorer
window.

• Click the play button to animate a model.

• Click the rewind button to restart an animation from the beginning.

2-51
2 Essentials of SimMechanics™ Software

• Click the backward step button or the forward step button , to


incrementally move the animation backward or forward in time.
• Click and drag the animation slider bar to the desired point in
time , or enter the desired time in the Time
field to move the animation to the desired point in time.

• Click the loop button to automatically restart the animation from the
beginning once it reaches the end.

• Click and drag the animation speed slider bar to adjust the
animation speed

Recording a SimMechanics Animation


You can record an animation as an .AVI file, and view it with any media
player that supports .AVI files.

1 To save the animation for later playback, in the Mechanics Explorers


toolbar, click the Save animation button . The Select video file dialog
box is displayed.

2-52
Model Visualization and Animation

2 Confirm the file directory and file name are correct, and click Save to save
the animation as a .AVI file in the given directory.

The simulation and recording start simultaneously. When the recording is


complete, a message is displayed.

2-53
2 Essentials of SimMechanics™ Software

Note The software records the animation with the view you select before
you start the recording. For example, if you change the view to the
isometric view of the model, then record the animation, the viewpoint of
the animation is isometric.

3 Navigate to the directory where your animation file was saved, and open
it to play the recorded animation.

2-54

You might also like