Mathworks SIMMECHANICS 3 Installation Guide

SimMechanics™ 3
Getting Started Guide
How to Contact The MathWorks
www.mathworks. comp.soft-sys.matlab Newsgroup www.mathworks.com/contact_TS.html Technical Support
bugs@mathwo doc@mathworks.com Documentation error reports service@mathworks.com Order status, license renewals, passcodes
info@mathwo
com
rks.com
rks.com
Web
Bug reports
Sales, prici
ng, 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 2001–20 10 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 MathW orks, 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 theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand 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 Docu mentation, 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
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
October 2008 Online only New for Version 3.0 (Release 2008b) March 2009 Online only Revised for Version 3.1 (Release 2009a) September 2009 Online only Revised for Version 3.1.1 (Release 2009b) March 2010 Online only Revised for Version 3.2 (Release 2010a)
Introducing SimMechanics Software
1
Product Overview ................................. 1-2
Product Definition Mechanical Simulation and Physical Modeling
................................. 1-2
......... 1-2
Contents
Related Products
Required Products Other Related Products
Running a Demo Model
WhattheDemoRepresents WhattheDemoIllustrates Opening the Model Running the Model Modifying the Model Visualizing and Animating the Model
What Can You Do with SimMechanics Software?
About SimMechanics Software Modeling Mechanical Systems Bodies, C oord i nate Systems, J oints, and Cons tra i nts Sensors, Actuators, Friction, and Force Elements Simulating and Analyzing Mechanical Motion Visualizing and Animating Models For More Information
Learning M ore
Using the MATLAB Help System for Documentation and
Demos
Finding Special SimMechanics Help
........................................ 1-27
.................................. 1-3
................................. 1-3
............................ 1-4
............................ 1-6
......................... 1-6
.......................... 1-7
................................ 1-8
................................ 1-11
............................... 1-12
................. 1-14
....................... 1-18
....................... 1-18
.......... 1-20
................... 1-22
.............................. 1-26
.................................... 1-27
.................. 1-27
..... 1-18
.... 1-19
....... 1-20
iii
Modeling, Simulating, and Visualizing Simple
Machines
2
Introducing the SimMechanics Block Libraries ...... 2-2
About the SimMechanics Block Library Accessing the Libraries Using the Libraries
Essential Steps to Building and Running a Mechanical
Model
About Machine Modeling and Simulation Essential Steps to Build a Model Essential Steps to Configure and Run a Model
.......................................... 2-7
............................. 2-2
................................ 2-4
..................... 2-7
............... 2-2
.............. 2-7
.......... 2-9
Modeling and Simulating a Simple Machine
Modeling the Simple Pendulum Opening the SimMechanics Block Library The W orld Coordinate System and Gravity Configuring the Ground Configuring the Body Configuring the Joint Adding a Sensor and Starting the Simulation
Visualizing a Simple Machine
Visualizing and Animating the Simple Pendulum Starting Visualization Selecting a Body Geometry Displaying the Pendulum Modeling and Visualizing More Complex Machines
Modeling and Simulating a Closed-Loop Machine
Modeling the Four Bar Mechanism Counting the Degrees of Freedom Configuring the Mechanical Environment Setting Up the Block Diagram Configuring the Ground and Joints Configuring the Bodies Sensing Motion and Running the Model ForMoreAbouttheFourBarMechanism
............................ 2-13
.............................. 2-15
.............................. 2-21
.............................. 2-32
............................. 2-49
...................... 2-11
....................... 2-32
.......................... 2-34
........................... 2-34
................... 2-38
.................... 2-39
....................... 2-42
................... 2-45
.......... 2-11
............. 2-12
............. 2-12
.......... 2-25
............. 2-40
............... 2-54
.............. 2-59
....... 2-32
...... 2-37
.... 2-38
iv Contents
Representing Motion
3
Kinematics and the Machine’s State of Motion ....... 3-2
About Kinematics Degrees of Freedom The State of Motion Home,Initial,andAssembledConfigurations For More Information
................................. 3-2
................................ 3-2
................................ 3-2
.......... 3-3
.............................. 3-3
Body Motion in Sim Mech anics Representations
About Body Motion Machine Geometry and Motion Reference Frames and Coordinate Systems Relating Coordinate Systems in Relative Motion Observing Body M otio n in Different Coordinate Systems Representing Body Transla tions and Rotation s References
Body Orientation in SimMechanics Representations
About Body Orientation Representations Axis-Angle R epresentation Quaternion Representation Rotation Matrix Representation Euler Angle Representation Converting Rotation Representations Converting the Angular Velocity
Orienting a Body and Its Coordinate Systems
About the Body Orientation Examples Setting Up the Test Body RotatingtheBodyandItsCGCSRelativetoWorld Rotating the Body Relative to Its Center of Gravity Creating and Rotating Body Coordinate Systems
....................................... 3-11
................................ 3-5
...................... 3-5
............ 3-6
.............. 3-12
.......................... 3-12
......................... 3-13
...................... 3-13
......................... 3-14
................. 3-15
..................... 3-18
................ 3-19
........................... 3-19
...... 3-5
........ 3-6
......... 3-10
........ 3-19
..... 3-22
...... 3-23
........ 3-25
.. 3-8
.. 3-12
v
A
Technical Conventions
Mechanical Conv
Right-Hand Rule Vector Multipl Common Abbrevi Glossary Terms
Mechanical Un
B
entions and Abbreviations
Is Assumed
ication
its
..............................
ations
...................................
..................................
........................
.............................
.........
Bibliograp
A-2 A-2 A-2 A-2 A-2
A-3
hy
Glossar
Index
y
vi Contents
1

Introducing S imMechanics Software

SimMechanics™ models and simulates mechanical systems, together with Simulink
“Product Overview” on page 1-2
“Related Products” on page 1-3
“Running a Demo Model” on page 1-6
“What Can You Do with SimMechanics Software?” on page 1-18
“Learning More” on page 1-27
®
and MATLAB®.
1 Introducing SimMechanics™ Software

Product Overview

In this section...
“Product Definition” on page 1-2
“Mechanical Simulation and Physical Modeling” on page 1-2

Product Definition

SimMechanics software is a block diagram modeling environment for the engineering design and simulation of rigid multibody machines and their motions, using the standard Newtonian dynamics of forces and torques.
With SimMechanics software, you can model and simulate mechanical systems with a suite of tools to specify bodies and their mass properties, their possible motions, kinematic constraints, and coordinate systems, and to initiate and measure body motions. You represent a mechanical system by a con n ecte d block diagram, like other Simulink models. You can also incorporate hierarchical subsystems.
1-2
The visualization tools of SimMechanics software displ ay and animate 3-D machine geometries, before and during simulation.

Mechanical Simulation and P hysical Modeling

SimMechanics software is based on the Simscape™ software, the platform product for the Simulink Physical Modeling family, encompassing the modeling and design of systems according to basic physical principles. Simscape software runs within the Simulink environment and interfaces seamlessly with the rest of Simulink and with MATLAB. Unlike other Simulink blocks, which represent mathematical operations or operate on signals, Simscape blocks represent physical components or relationships directly.
Note This SimMechanics User’s Guide assumes that you already have some experience with modeling mechanical systems and with building and running models in Simulink.

Related Products

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

Required Products

You must have current versions of the following products installed to use SimMechanics software:
MATLAB
Simulink
Simscape
SimMechanics Visualization Requirements
The SimMechanics visualization window requires Silicon Graphics OpenGL graphics support on your system in order to display and animate mechanical systems.
Related Products
®
You can improve your s p e ed and graph ics 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 to find a reasonable compromise between quality and speed for your system.
STL Graphics Files for Customized Body Shapes. To switch from the SimMechanics visualization default bodysurfacegeometriestocustomized body shapes, you need a stereolithographic (STL) graphics file for each customized body. You can obtain these from computer-aided design (CAD) assemblies via the SimMechanics Link exporter, from graphical editors, or by manual creation.
Support for Recorded Animations
You can record simulation animations in Microsoft Audio Video Interleave (AVI) format using the SimMechanics visualization. To play back AVI
®
1-3
1 Introducing SimMechanics™ Software
files, you need an AVI-compatible media application. MATLAB has an internalmovieplayercompatiblewithAVI.Youcanalsouseanexternal AVI-compatible player.
If you want to compress your SimMechanics AVI recordings, you need the Indeo 5 codec installed on your system to re cord them. Your AVI player mig ht also require this codec to view compressed recordings.

Other Related Products

The related products listed on the SimMechanics product page at the MathWorks™ Web site include toolboxes and blocksets that extend the capabilities of MATLAB and Simulink. These products will enhance your SimMechanics experience in various applications.
SimMechanics Link Utility
The S i m M echanics Link utility interfaces MATLAB with externa l mechanical applications such as CAD platforms. It generates Physical Modeling XML files that you can import to automatically generate SimMechanics models representing CAD assemblies. See the SimMechanics Link documentation and the SimMechanics Visualization and Import Guide.
1-4
Physical Modeling Product Family
Use the Physical Modeling product family to model physical systems in Simulink. In addition to SimMechanics software, they include:
Simscape, the platform and unifying environment for Physical Modeling
products
SimElectronics
SimDriveline™, for modeling and simulating drivetrain systems
SimHydraulics
SimPowerSystems™, for modeling and simulating electrical power systems
®
, for modeling and simu l ati ng el ectronic systems
®
, for modeling and simulating hydromechanical systems
For More Information About MathWorks Products
For more information about any MathWorks software products, see either
The online documentation for that product if it is installed
Related Products
TheMathWorksWebsiteat
Services” section.
www.mathworks.com; see the “Products &
1-5
1 Introducing SimMechanics™ Software

Running a Demo Model

In this section...
“What the Demo Represents” on page 1-6
“What the Demo Illustrates” on page 1-7
“Opening the M odel” on page 1-8
“Running the Model” on page 1-11
“Modifying the Model” on page 1-12
“Visualizing and Animating the Model” on page 1-14

What the Demo Represents

This demo model uses a few blocks in the library to simulate a simple machine with feedback control. You will see how SimMechanics features build upon standard Simulink features to model a mechanical system.
1-6
The demo model simulates a conveyor belt loading mechanism. A simple controller (not shown), with a sensor and an actuator, guides the mechanism with a saturation limit and anti-windup logic for the applied torque. You can adjust the controller and set the stopping point for the pusher.
Running a Demo Model
Conveyor Loader Mechanism

What the Demo Illustrates

The conveyor mechanism demo illustrates some important SimMechanics features:
Representing bodies and degrees of freedom with Body and Joint blocks,
respectively
Using SimMechanics blocks with normal Simulink blocks
Feeding Simulink signals to and from SimMechanics blocks with Actuator
and Sensor blocks, respectively
Encapsulating groups of blocks into subsystems
1-7
1 Introducing SimMechanics™ Software
Visualizing and animating a mechanism by its component bodies
Caution You might want to make modifications to this demo model. To
avoid errors,
Do not attempt to connect Simulink signal lines directly to SimMechanics
blocks other than Actuators and Sensors.
Keep the collocation of the Body coordinate system origins on either side of
each assembled Joint to within assembly tolerances.
Saving modified demo mo de ls in a different folder from the dem os is recommended.

Opening the Model

To get started quickly with the conveyor demo model, follow either of these steps:
1-8
Enter
If you are working with the MATLAB Help browser, click the model name
mech_conveyor at the MATLAB command line.
mech_conveyor here.
Opening General SimMechanics Demos
You can open the complete SimMechanics demos list by:
1 Clicking the Start button on the lower left of the MATLAB desktop.
2 In the pop-up menu, selecting Simulink,thenSimMechanics,andthen
Demos.
This opens the SimMechanics demos list in the MATLAB Help browser.
You can locate and select any specific demo entry from the list of models.
Running a Demo Model
Alternatively, you can open the same SimMechanics demos list by entering
demo simulink simmechanics or demo('simulink','simmechanics') at
the MATLAB command line.
The Block Diagram Model
The block diagram model opens in a model window.
What the Model Contains
Here are some critical features of the model:
1-9
1 Introducing SimMechanics™ Software
Ignore the Position Controller, Joint Sensor, and Joint Actuator blocks for
a m oment. Note that the loading mechanismfollowsthetreeofbodiesand joints show n in the figure, Con veyor Loader Mechanism on page 1-7:
- There are four rotating link bodies and one sliding pusher body, as
well as three ground points on the immobile mounting represented by Ground blocks. D ouble -click the Body and Ground blocks to see their dialog boxes.
- The pusher slides and the links rotate relative to one another and to
the ground points on the mounting. There are seven apparent degrees of freedom (DoFs) in the system, represented by seven Joints, but the geometry constrains the motion to one actual DoF. Double-click the Revolute blocks to see how rotational DoFs a re expressed in their dialog boxes.
- The Prismatic block expresses the linear motion of Pusher relative to
Ground_2. The Revolute block expresses the angular motion of Link4 (the crank of the whole mechanism) relative to Ground_1.
The Joint Sensor detects the position of Pusher via the Prismatic block. The
Joint Actuator applies torque to Link4 via the Revolute block. Double-click the Sensor and Actuator blocks to view how the mechanical motions and forces/torques are transformed into Simulink signals.
1-10
The Position Controller subsystem converts the Pusher position information
into a feedback signal to actuate Revolute and thus Link4. You can open the Position Controller block to view this subsystem, which is made of normal Simulink blocks.
Running a Demo Model
The Reference Position block gives you control over the stopping position
of the pusher by modulating the control signal that actuates Revolute. Maintaining the initial pusher positio n requires a fixed torque on Revolute.
Open the S cope block. You can view both the Pusher position in millimeters
(
mm) relative to Ground_2 as the Measured Position plot and the torque in
newton-meters ( N-m) applied to Link4 relative to Ground_1 as the Torque plot.

Running the Model

You can now run the model as it is when you first open it:
1 In the Simulation menu, select Configuration Parameters.The
Configuration Parameters dialog box appears. Select the Solver node:
a The preset Stop time is inf, so the simulation keeps running once you
start it. You should leave it at first few times you run it.
Later you can apply a finite stop time (in seconds) if you want.
b Leave the Solver options entries at default values and close th e box.
2 From the Simulation menu, select Start. In Microsoft Windows
also click the Start button in the model window toolbar.
inf and stop the simulation manually the
®
,youcan
1-11
1 Introducing SimMechanics™ Software
Themeasuredpositionofthepusherandthetorqueappliedtomaintain that position start and remain essentially constant in the Scope plots. The applied torque is adjusted to maintain the initial pusher position.
1-12
3 Toseegreaterdetailatthesimulationstart, stop the simulation before the
time passes 20 seconds and zoom in on the Scope plots.

Modifying the Model

Here is a modification of the demo you can try. It illustrates the simple controller that you can adjust to change the motion of the pusher.
To make these modifications, it is best to close and restart the demo.
Changing the Pusher Reference Position
The Reference Position block is actually a Simulink Slider Gain block (from the Simulink Math Library) and controls where the pusher comes to rest.
You can adjust the Reference Position block to change where the pusher stops:
Running a Demo Model
1 Open the Reference Position block. You see an adjustable slider to set the
position of the pusher’s rest point.
2 Enter values in the Low and High fields to set the lower and upper limits
of the allowed slider range. The defaults in this demo are implied units of meters (
3 Enter a value in the central field to set the pusher stopping point, which
m).
0 and 0.2,with
you can also adjust by clicking and dragging the slider between the lower and upper limits. The default is
0 (meters).
You can apply changes to the reference position to the simulation in two ways:
Reset the Reference Position block first, then start the demo. You see the
pusher trajectory track differently now, toward the new stopping point.
For example, resetting the Reference Positio n to
0.1 and restarting the
demo produces these Scope plots, with Autoscale and zooming applied. The asymptotic measured position now tends to 100 mm (0.1 m), and the torque applied to keep the pusher there has changed:
1-13
1 Introducing SimMechanics™ Software
Start the demo with the Reference Position block open and move the slider
up and down as the simulation runs. Watch the Scope. The measured position and necessary torque change to follow the new re ference position.

Visualizing and Animating the Model

Another modification you can ma ke illustrates a powerful SimMechanics feature, visualization of a mechanism and an imation of its si m ulated motion.
You can visualize and animate the conveyor mechanism by opening the SimMechanics visualization wi nd ow. This window lets you display the bodies in two standard abstract forms:
Equivalent ellipsoids use the inertia tensors and masses of the bodies.
Each body has a unique homogeneous ellipsoid equivalent to it in mass and inertia tensor.
Convex hulls use the attached Body coordinate systems (CSs) of the bodies
to define a shape outlined by the CS origins.
1-14
Convex Hulls
First try visualizing the conveyor with bodies displayed as convex hulls:
1 From the Simulation menu, select Configuration Parameters.The
Configuration Parameters dialog box appears.
2 Select the SimMechanics node. In the Visualization area, select the
Display machines after updating diagram and Show animation during simulation check boxes.
3 Leave the other defaults as they are and close the dialog. From the Edit
menu, select Update Diagram.
A S imMechanics visualization windo w appears, displaying the conveyor at rest in its initial state.
The bodies are displayed in the default geometry, as convex hulls. The bodies and Body coordinate sy stem axistriadsarealsodisplayedas defaults.
4 Change Reference Position to a nonzero value such as 0.1 or 0.2.
Running a Demo Model
5 Restart the simulation. The window animates the conveyor in motion. You
can compare this motion to the plots in the scope.
6 Click a body in the visualization window. In the model window, the
corresponding Body block is highlighted in red. The block name appears at the lower left of the visualizatio n window.
amine the visualization w indow menus and tool bar.
7 Ex
1-15
1 Introducing SimMechanics™ Software
Here, you can reconfigure the display properties: bodies, Body CS axis triads, colored fill-in body surface patches connecting Body CSs on the same body, and viewpoint orientation.
8 Leave the visualization window open for the next set of steps.
Equivalent ellipsoids
Now visualize the conveyor with bodies displayed as ellipsoids:
1 From the Model menu in the menu bar, select Body Geometries >
Ellipsoids, so that a check mark appears beside the menu entry.
Thedisplayinthevisualizationwindowchanges. Theconveyorappearsat rest in its initial state but with the bodies displayed as equivalent ellipsoids.
2 Restart the simulation. The viewer now animates the conveyor in motion.
3 Use the menus to experiment with the visualization settings. The toolbar
contains most of these functions as well.
1-16
Running a Demo Model
4 While the animation is running, open the Reference Position block and
move the slider up and down. In addition to what you can see in the Scope plots, the window directly animates the pusher trajectory in space as the mechanism responds to your adjustment.
1-17
1 Introducing SimMechanics™ Software

What Can You Do with SimMechanics Software?

In this section...
“About SimMechanics Software” on page 1-18
“Modeling Mechanical Systems” on page 1-18
“Bodies, Co ordinate Systems, Joints, and Constraints” on page 1-19
“Sensors, Actuators, Friction, and Force Elements” on page 1-20
“Simulating and Analyzing Mechanical Motion” on page 1-20
“Visualizing and Animating Models” on page 1-22
“For More Information” on page 1-26

About SimMechanics Software

SimMechanics software is a set of block libraries and mechanical modeling and simula t ion tools for use wi th Simulink. You connect SimMechanics blocks to normal Simulink blocks through Sensor and Actuator blocks.
1-18
The blocks in these libraries are the elements you need to model mechanical systems consisting of any number of rigid bodies, connected by j oints representing translational and rotational degrees of freedom. You can represent mechanical systems with components organized into hierarchical subsystems, as in normal Simulink models. You can impose kinematic constraints, apply forces/torques, integrate the Newtonian dynamics, and measure resulting motions. You can see some of these features at work in the Conveyor Loader demo model.
Glossary Terms For an explanation of important terms, see the “Glossary”.

Modeling Mechanical Systems

These are the major steps you follow to build and run a model representation of a machine:
What Can You Do with SimMechanics™ Software?
1 Specify body inertial p roperties, degrees of freedom, and constraints, along
with coordinate systems attached to bodies to measure motions and forces.
2 Set up sensors to record motions and forces, as well as actuators and force
elements to initiate motions and apply forces, including continuous and discontinuous friction.
3 Start the simulation, calling the Simulink solvers to find the motions of the
system, wh i le maintaining a ny imposed constraints. You can also gen era t e, compile, and run generated code versions of your models.
4 Visualize the machine while building the model and animate the simulation
while running it, using the SimMechanics visualization window.

Bodies, Coordinate S ystems, Joints, and Constraints

You model bodies with Body blocks specified by their masses, inertia tensors, and attached Body coordinate systems (CSs). You connect the bodies to one another with joints representing the possible motions of bodies relative to one another, the system’s degrees of freedom (DoFs). You can impose kinematic constraints on the allowed relative motions of the system’s bodies. These constraints restrict the DoFs or drive the DoFs as explicit functions of time.
The SimMechanics interface gives you m any ways to specify CSs, constraints/drivers, and forces/torques. You can
Attach Body CSs to different points on Body blocks to specify local axes and
origins for actuating and sen sing.
Take Joint blocks from the SimMechanics library or extend the existing
Joint library by constructing your own custom Joints.
Use other Simulink tools as well as MATLAB expressions.
Defining Local Coordinate Systems
SimMechanics models automatically contain a single inertial referen ce frame and CS called World. You can also set up your own Local CSs:
Grounded CSs attached to Ground blocks at rest in World but displaced
from the World CS origin
Body CSs fixed on and moving rigidly with the bodies
1-19
1 Introducing SimMechanics™ Software
Kinematic Constraints
Specifying kinematic relations between any two bodies, yo u can constrain the m otion of the system by connecting Constraint blocks to pairs of Bodies. Connecting Driver blocks applies time-dependent constraints.

Sensors, Actuators, Friction, and Force Elements

Sensors and Actuators are the blocks you use to interface between normal Simulink blocks and SimMechanics blocks. Force Elements represent internal forces that require no external input.
Sensor blocks detect the motion of Bodies and Joints.
- Sensor block outputs are Simulink signals that you can use like any
other Simulink signal. You can connect a Sensor block to a Simulink Scope block and display the motions in a system.
- You can feed these Sensor output signals back to a SimMechanics system
via A ctuator blocks, to specify forces/torques in the system.
Actuator blocks specify the motions of Bodies or Joints.
1-20
- They accept force/torque signals from Simulink and can apply
forces/torques on a body or joint from these s ignals. The Simulink signals can include Sensor block outputs fed back from the system itself.
- They detect discrete locking and unlocking of Joints to implement
discontinuous static friction forces.
- They specify the position, velocity, and acceleration of bodies or joints as
explicit functions of time.
- They prepare a system’s initial kinematic state ( po sitions and velocities)
for the forward integration of Newtonian dynamics.
Force Elements model internal forces between bodies or acting on joints between bodies. Internal forces depend only on the positions and velocities of the bodies themselves, independent of exte r na l signals.

Simulating and Analyzing Mechanical Motion

SimMechanics software provides four modes for analyzing the mechanical systems you simulate: Forward Dynamics, Trimming, Inverse Dynamics, and
What Can You Do with SimMechanics™ Software?
Kinematics. You can also convert any mechanical model, in any mode, to a portable, generated code version.
Mathematical Determination of Rigid Body Motion
For the forward dynamics to be mathema tically solvable, the system must satisfy certain conditions:
The masses and inertia tensors of all bodies are known.
All forces and torques acting on each body at each instant of time are
known.
Any kinematic constraints among DoFs are specified as constraints among
positions and/or velocities a lo ne. If the constraints are mutually consistent and are fewer in number than the DoFs, the system’s motion is nontrivial and can be found by integration.
Initial conditions (initial positions and velocities) are specified and
consistent with all constraints.
For inverse dynamic analysis, you specify the motions instead and obtain the forces/torques needed to produce those motions.
Forward Dynamics, Trimming, and Linearization
In the Forward Dynamics mode, a SimMechanics simulation uses the Simulink suite of ordinary differential equation (ODE) solvers to solve Newton’s equations, integrating applied forces/torques and obtaining the resulting motions. The ODE solvers project the motion of the DoFs onto the mathematical manifold of the kinematic constraints and yield the forces/torques of constraint acting within the system.
Trimming. The Trimming mode allows you to use the Simulink trimming features to sea rch for steady or e qu ilibriu m states in mechanical motion. These states, once found, are the starting point for linearization analysis.
Linearization. You can use the Simulink linearization tools to linearize the forward motion of a system and obtain its response to small perturbations in forces/torques, constraints, and initial conditions.
1-21
1 Introducing SimMechanics™ Software
Inverse Dynamics
A SimMechanics simulation can solve the reverse of the forward dynamics problem, determining the forces/torques needed to produce a given set of motions that you apply to the system. Depending on the topology of your system, you choose from two SimMechanics modes for efficiently analyzing its inverse dynamics:
The Inverse Dynamics mode works with open topology systems (model
diagrams without closed loops).
The Kinematics mode analyzes the motion of closed-loop m odels, including
the invisible constraints imposed by loop closures.
Constraint and Driver blocks can appear only in closed loops, so you use the Kinem atics mode to analyze constraint forces/torques as well.
Tip YoucanusetheForwardDynamicsmodetoanalyzeinversedynamics. But the Inverse Dynamics and Kinematics modes are optimized for such analysis and solve such problems faster and m ore efficiently than does Forward Dynamics.
1-22
Generating Code
SimMechanics software is compatible with Simulink Acceleration modes, Real-Time Workshop versions of the models you create originally in Simulink with block diagrams, enhancing simulation speed and model portability.
The presence of static friction in a mechanical model creates dynamical discontinuities and triggers mode iterations in Simulink. These discontinuities and m ode iterations place certain restrictio n s on code generation.
®
and xPC Target™ software. They let you generate code

Visualizing and Animating Models

SimMechanics software supports an internal visualization window as a powerful aid in building, animating, and debugging models. For an example of its use, see “Running a Demo Model” on page 1-6.
The window displays the bodies and their Body coordinate systems (CSs) in:
What Can You Do with SimMechanics™ Software?
Abstract, simplified shapes, convex hulls or equivalent ellipsoids. These
are the standard geometries.
Custom geometries specified by external graphics fil es.
You can also automatically generate SimMechanics models from a data file representing a computer-aided design (CAD) assembly e xported from external CAD platforms.
Visualizing Bodies During Modeling
One way to use the visualization window is while you’re building your model:
You can open a SimMechan ics visualization window before you start to
build and then watch the bodies appear and be configured in the display as you create and configure them in your model window.
This approach is especially useful if you’re just starting to learn how to create com plex SimMechanics models. In that case, visualization can guide you in assembling the body geometries and connections.
You can also build a model without visualization, then open a visualization
window when you have finished to see the completed model.
Displaying Bodies in Standard Geometries
The visualization window has two standard abstract shapes to display the bodies, one derived from body mass properties, the other from bodies’ attached Body coordinate systems (CSs). These shapes are geometric schematics, based on the limited body information specified in the Body block dialog.
Mass Properties. A rigid body’s dynamics are partly determined by the body’s total mass and how that mass is distributed in space, as encapsulated in its inertia tensor. Any rigid body has a unique corresponding homogeneous ellipsoid w ith the same mass and inertia tensor.
Using these equivalent ellipsoids is o ne visualization mode of displaying a body. The relative sizes of the ellipsoid axes indicate the relative inertial moments about each axis.
1-23
1 Introducing SimMechanics™ Software
Here is a rigid body display ed as an equivalent ellipsoid.
1-24
Geometric Properties. Every SimMechanics body is represented by a Body block with at least one attached Body CS. The minimum Body CS origin is located at the body’s center of gravity (CG).
You can also create other Body CSs on a Body. Any Joint, Constraint/Driver, Actuator, or Sensor attached to a Body must be attached at a Body CS origin.
The set of Body CS origins can be enveloped by a surface; if there are more than three non-coplanar origins, the surface encloses a volume. The minimal surface with outward-bending curvature enveloping this set is the convex hull, which is the other abstract shape available for visualizing a body in space. Fewer than four CS origins produce simpler Body figures. The convex hull excludes the Body CG CS.
What Can You Do with SimMechanics™ Software?
Here is the same body as a convex hull. The four Body CS origins are non-coplanar in this case, and the hull is a tetrahedron.
Animat
Besides displaying your model’s bodies either while you build the model or as a co m pleted model, you can also keep the visualiz ation window open while a model is running in the Simulink model window. The window animates the simulation of the bodies’ m otio ns , whether you choose to display the bodies as ellipsoids or as convex hulls, and moves in parallel with model changes on the Simulink side.
Inte
You can use the SimMechanics importer to automatically generate a SimMechanics model based on an external data file previously exported from a supporte d CAD platform. This data file captures the dynamically important features of a CAD assembly representing a mechanical system. The resulting model, once generated, can be modified and expanded like any other SimMechanics model.
ing Motion During Simulation
rfacing with Computer-Aided Design
1-25
1 Introducing SimMechanics™ Software

For More Information

See these other sections of the SimMechanics documentation for more details on working with SimMechanics software.
User’s Guide
The SimMechanics User’s Guide covers modeling and simulation and includes chapters on:
“Modeling Mechanical Systems”, about machines, bodies, joints,
constraints, drivers, sensors, actuators, and force elements
“Running Mechanical Models”, about simulation and code generation
“Analyzing Motion”, about motion analysis modes
“Motion, Control, and Real-Time Simulation”, a b out adv an c ed applications
combining motion analysis, control design, code generation, and hardware in the loop
1-26
Visualization and Import Guide
The SimMechanics Visualization and Import Guide covers visualizing machines in space and importing externally defined mechanical design information. It includes chapters on:
“Introducing Visualization and Animation”, an overview
“Getting Started with the Visualization Window”, practical steps to
visualizing machines
“Customizing Visualization and Animation”, extending visualization with
your own body shapes and colors
“Importing Mechanical Models”, getting started with importing external
mechanical information to generate models
“Computer-Aided Design Translation”, about CAD-to-SimMechanics model
conversion

Learning More

In this section...
“Using the MATLAB Help System for Documentation and Demos” on page 1-27
“Finding Special SimMechanics Help” on page 1-27

Using the MATLAB Help System for Documentation and Demos

You can get h elp online in a number of ways to assist you while using SimMechanics software. The MATLAB Help browser allows you to access the documentation and demo models for a ll the MATLAB and Simulink based products that you have installed. The online help includes an online index and search system.
Consult the MATLAB Getting Started Guide formoreabouttheMATLAB help system.
Learning More

Finding Special SimMechanics Help

This user’s guide also includes these reference chapters.
“Technical Conventions” explains mechanical conventions, abbreviations,
and units.
The “Bibliography” lists external references on mechanics, mechanical
simulation, and related topics.
The “Glossary” explains special termsandphrasesusedinthisguide.
In addition, many SimMechanics demos have help links represented by the information symbol
in the Help browser.
. Click this symbol to open that demo’s documentation
1-27
1 Introducing SimMechanics™ Software
1-28

Modeling, Simulating, and Visualizing Simple Machines

Constructing simple SimMechanics models is easy to learn if you already knowhowtomakeSimulinkmodels. Ifyouarenotalreadyfamiliarwith Simulink, see the Simulink docum entation.
“Introducing the SimMechanics Block Libraries” on page 2-2
2
“Essential Steps to Building and Running a Mechanical Model” on page 2-7
“Modeling and Simulating a Simple Machine” on page 2-11
“Visualizing a Simple Machine” on page 2-32
“Modeling and Simulating a Closed-Loop Machine” on page 2-38
2 Modeling, Simulating, and Visualizing Simple Machines

Introducing the SimMechanics Block Libraries

In this section...
“About the SimMechanics Block Library” on page 2-2
“Accessing the Libraries” on page 2-2
“Using the Libraries ” on page 2-4

About the SimMechanics Block Library

SimMechanics software is organized into a set of libraries of closely related blocks. This section shows how to view these libraries and gives you a summary of what they contain.

Accessing the Libraries

There are several ways to open the SimMechanics block library.
2-2
Introducing the SimMechanics™ Block Libraries
You can access the blocks through the Simulink Library Browser. Open the
browser by clicking the Simulink button
. Expand the Simscape entry,
then the SimMechanics subentry, in the contents tree.
You can also access the blocks directly inside the SimMechanics library in several ways:
In the Simulink Library Browser, right-click the SimMechanics subentry
under Simscape and select Open SimMechanics Library.Thelibrary appears.
2-3
2 Modeling, Simulating, and Visualizing Simple Machines
Click the Start button in the lower left corner of your MATLAB desktop.
In the pop-up menu, select Simulink,thenSimMechanics,thenBlock Library.
Enter
mechlib at the MATLAB command line.
SimMechanics Library
Once you perform one of these steps, the SimMechanics library opens.
Tip This library displays the top-level block groups. You can expand each library by double-clicking its icon. The Joints library contains second-level sublibraries.
The next section summarizes the blocks of each library and their use. For explanations of individual blocks, consult the SimMechanics “Block Reference” reference.
2-4

Using the Libraries

The SimMechanics block library is organized into separate libraries, each with a different type of mechanical block.
Bodies
The Bodies library provides the Body block for representing bodies defined by their mass properties (masses and inertia tensors), their positions and orientations, and their attached Body coordinate systems (CSs). This library also contains the Ground block representing immobile ground points, w hich
Introducing the SimMechanics™ Block Libraries
have their own Grounded CSs, and the Machine Environment block, for configuring the mechanical settings of a SimMechanics block diagram.
Joints
The Joints library provides blocks to represent the relative motions betw een bodies as degrees of freedom (DoFs). The library is made up of assembled Joints listed individually and two sublibraries of specialized Joint b lock s .
An assembled joint restricts the Body CSs on the two bodies to which it is connected. The assembled Joints are the primitive Prismatic, Revolute, and Spherical blocks and ready-made composite Joints. Un less it is explicitly labeled as disassembled, you can assume a generic Joint block is assembled.
Joints/Disassembled Joints. The Disassembled Joints sublibrary provides blocks for disassembled joints, modified joints that do not restrict the Body CSs on the two connected bodies or the DoF axes of the two bodies. You can only use Disassembled Joints to close a loop in your machine. You cannot sense or actuate Disassembled Joints.
Joints/Massless Connectors. The Massless Connectors sublibrary provides blocks for massless connectors, composite joints whose DoFs are separated by a fixed distance. You cannot actuate or sense Massless Connectors.
Constraints & Drivers
The Constraints & Drivers library provides blocks to specify prior restrictions on DoFs between Bodies. These restrictions can be time-independent constraints or time-dependent driving of DoFs with Simulink signals.
Sensors & Actuators
The Sensors & Actuators library provides blocks for sensing and initiating the motions of joints and bodies. These blocks play a special role in connecting SimMechanics blocks to other Simulink blocks, as described in “Connecting SimMechanics Blocks”, “Applying Motions and Forces”, and “Sensing Motions and Forces”.
2-5
2 Modeling, Simulating, and Visualizing Simple Machines
Force Elements
The Force Elements library provides blocks for creating forces or torques between bodies. These blocks model forces internal to your machine.
Interface Elements
The Interface Elements libraries includes blocks to connect three-dimensional machines modeled with SimMechanics blocks and one-dimensional mechanical Simscape circuits.
Utilities
The Utilities library contains miscellaneous blocks useful in building models.
2-6

Essential Steps to Building and Running a Mechanical Model

Essential Steps to Building and Running a Mechanical Model
In this section...
“About Machine Modeling and Simulation” on page 2-7
“Essential Steps to Build a Model” on page 2-7
“Essential Steps to Configure and Run a Model” on page 2-9
About Machi
To become c to work thr configure simple ma process b
“Essent
“Essent
The spe
Essent
You us
dless of its complexity. The steps are similar to those for building a
regar
ar Simulink model. More complex models add steps without changing
regul
ebasics.
thes
1 Sele
libr mac blo
omfortable building mechanical models, you might find it helpful
ough the guided examples in subsequent sections of how to
and put together elements of SimMechanics software to simulate
chines. This section gives you an overview of the model-building
efore you start:
ial Steps to Build a Model” on page 2-7
ial Steps to Configure and Run a Model” on page 2-9
cial terms used in this guide are sum marized in the “Glossary”.
ial Steps to Build a Model
e the same basic procedure for building a SimMechanics model
ct Ground, Body, and Joint blocks. From the Bodies and Joints
aries, drag and d rop the Body and Joint blocks needed to represent your
hine, including a Machine Environment block and at least one Ground
ck, into a Simulink model window.
ne Modeling and Simulation
The Machine Environment block represents your machine’s mechanical settings.
2-7
2 Modeling, Simulating, and Visualizing Simple Machines
Ground blocks represent immobile g round points at rest in absolute (inertial) space.
Body blocks represent rigid bodies.
Joint blocks represent relative motions between the Body blocks to which they are connected.
2 Position and connect blocks. Place Joint and Body blocks in proper relative
position in the model window and connect them in the proper order. The essential result of this step is creation of a valid tree block diagram made of
Machine Env — Ground — Joint — Body — Joint — Body — ... — Body
with an open or closed topology and where at least one of the bodies is a Ground block. Connect exactly one environment block to a Ground.
A Body can have more than two Joints attached, marking a branching of the sequence. But Joints must be attached to two and only two Bodies.
3 Configure Body blocks. Click the Body blocks to open their dialog boxes;
specify their mass properties (masses and moments of inertia), then position and orient the Bodies and Grounds relative to the World coordinate system (CS) or to other CSs. You set up Body CSs here.
2-8
Look for intensive explanation and examples of positioning and orienting bodies in Chapter 3, “Representing Motion”.
4 Configure Joint blocks. Click each of the Joint blocks to open its dialog box
and set translation and rotation ax es and spherical pivot points.
5 Select, connect, and configure Constraint and Driver blocks. From the
Constraints & Drivers library, drag, drop, and connect Constraint and Driver blocks in between pairs of Body blocks. O pe n and configure each Constraint/Driver’s dialog box to restrict or drive the relative motion between the two respective bodies of each constrained/driven pair.
6 Select, connect, and configure Actuator and Sensor blocks. From the
Sensors & Actuators library, drag and drop the Actuator and Sensor blocks that you need to impart and sense motion. Reconfigure Body, Joint, and Constraint/Driver blocks to accept Sensor and Actuator connections. Connect Sensor and Actuator blocks. Specify control signals (applied
Essential Steps to Building and Running a Mechanical Model
forces/torques or motions) through Actuators and measure motions through Sensors.
Actuator and Sensor blocks connect SimMechanics blocks to normal Simulink blocks. You cannot connect SimMechanics blocks to regular Simulink blocks otherwise. Actuator blocks take inport signals from normal Simulink blocks (for example, from the Simulink Sources library) to actuate motion. Sensor block output ports generate Simulink signals that you can feed to normal Simulink blocks (for example, from the Simulink Sinks library).
In the m ost straightforward case, you apply forces/torques and initial conditions, then start the simulation in the Forward Dynamics mode to obtain the resulting motions. In the Kinematics and In verse Dynamics modes, you apply motions to all independent degrees of freedom. With these modes, you can find the forces/torques needed to produce these imposed motions.
7 Encapsulate subsystems. Systems made from Sim M echanics blocks can
function as subsystems of larger mode ls, like subsystems in normal Simulink models. You can connect an entire SimMechanics model as a subsystem to a larger model by using the Connection Port block in the Utilities library.

Essential Steps to Configure and Run a Model

After you’ve built your model as a connected block diagram, you need to decide how you want to run your model, configure SimMechanics and Simulink settings, and set up visualization.
You can choose from among four SimMechanics analysis modes for
simulating a machine. The mode you will probably use most often is Forward Dynamics.
But a more complete analysis of a machine makes use of the Kinematics, Inverse Dynamics, and Trimming modesaswell. Youcancreatemultiple versions of the model, each with the same underlying machine, but connected to Sensors and Actuators and configured differently for different modes.
You can also use the powerful SimMechanics visualization and animation
features. You can visualize your model as you build it or after you are
2-9
2 Modeling, Simulating, and Visualizing Simple Machines
finished but before you start the simulation, as a tool for debugging the model’s geometry. You can also animate the model as you simulate.
Choose the analysis mode, as well as other important mechanical settings,
in your Machine Environment dialog. Start visualization and adjust Simulink settings in the Simulink Configuration Parameters dialog. See “Modeling and Simulating a Closed-Loop Machine” on page 2-38 for an example.
The tutorials of this chapter introduce you to most of these steps. The first, in the next section, shows you how to configure the most basic blocks in any model: Machine Environment, Ground, Body, and a Joint, in order to create a simple pendulum model. The second tutorial explains how to visualize and animate the pendulum.
Caution You might want to make modifications to these tutorial models. To avoid errors,
Do not attempt to connect Simulink signal lines directly to SimMechanics
blocks other than Actuators and Sensors
2-10
Keep the collocation of the Body coordinate system origins on either side of
each assembled Joint to within assembly tolerances
You should save multiple versions of models as you try different analysis modes and configurations.

Modeling and Simulating a Simple Machine

Modeling and Simulating a Simple Machine
In this section...
“Modeling the Simple Pendulum” on page 2-11
“Opening the SimMechanics Block Library” on page 2-12
“The World Coordinate System and Gravity” on page 2-12
“Configuring the Ground” on page 2-13
“Configuring the Body” on page 2-15
“Configuring the Joint” on page 2-21
“Adding a Sensor and Starting the Simulation” on page 2-25

Modeling the Simple Pendulum

In this first tutorial, you drag, drop, and configure the most basic blocks needed for any mechanical model, as well as add some sensors to measure motion. The tutorial guides you through the most basic aspects of model-building.
The end result is a model of a simple pendulum, a system with one body and open topology. The pendulum is a swinging steel rod. W e strongly recommend that you work through this tutorial first before m oving on to, “Visualizing a Simple Machine” on page 2-32.
2-11
2 Modeling, Simulating, and Visualizing Simple Machines
A Simple Pe
Opening t
Followin page 2-2 s open a ne
The Wor
Before define
World
World
gonal coordinate axes.
ortho
ndulum: A Swinging Steel Rod
he SimMechanics Block Library
g one of the ways described earlier in the “Accessing the Libraries” on
ection in this chapter, open the SimMechanics library. From there,
w, empty Simulink model window.
ld Coordinate System and Gravity
you configure a Ground block, you need to understand the internally d fixed or “absolute” SimMechanics coordinate system (CS) called . The World CS sits at rest in the inertial reference frame also called . The World CS has an origin (0,0,0) and a triad of right-handed,
2-12
Modeling and Simulating a Simple Machine
The default World coordinate axes are defined so that
+x points right
+y points up (gravity in -y direction)
+z points out of the screen, in three dimensions
The vertical direction or up-and-down is determined by the gravity vector direction (acceleration g) relative to the World axes. Gravity is a background property of a model that you can reset before starting a simulation, but does not dynamically change during a simulation.
See “Configuring SimMechanics Models in Simulink” for displaying global mechanical properties of SimMechanics models.

Configuring the Ground

World serves as the single absolute CS that defines all other CSs. But you can create a dditional ground points at rest in World, at positions other than the World origin, by using Ground blocks. Ground blocks, representing ground points, play a dynamical role in mechanical models. They function as immobile bodies and also serve to implement a machine’s mechanical environment.
Minimum Ground Blocks Every machine model must have at least one Ground block. Exactly one Ground block in every machine must be connected to a Machine Environment block.
2-13
2 Modeling, Simulating, and Visualizing Simple Machines
A Ground Point Relative to World
Steps to Configuring the Ground Block
Now place a fixed ground point at position (3,4,5) in the World CS:
2-14
1 In the SimMechanics library, open the Bodies library.
2 Drag and drop a Ground and a Machine Environment block from the Bodies
library into the model window.
3 Open the Ground block dialog box. Into the Location [x y z] field, enter
the vector
[3 4 5]. Select the Show Machine Environment port check
box. Click OK to close the dialog. Connect the environment block.
Modeling and Simulating a Simple Machine
Properties of Grounds
At every ground point, a Grounded CS is automatically created:
The origin of each Grounded CS is the ground point itself.
The Grounded CS axes are always fixed to be parallel to the World CS axes,
as shown in the figure A Ground Point Relative to W orld on page 2-14.

Configuring the Body

While you need one Machine Environment and at least one Ground block to make a mechanical model, a real machine consists of one or more rigid bodies. So you need to trans late the components of a real machine into block representations. This section explains how you use a Body block to represent each rigid b ody inyoursystem:
“Characteristics of a Body Block” on page 2-15
“Properties of the Simple Pendulum Body” on page 2-16
“Configuring the Body Dialog” on page 2-17
Although the body is the most complicated component of a machine, the Body block does not use the full geometric shape and mass distribution of the body. A SimMechanics model uses only certain mass properties and simplified geometric information about the body’s center of gr avity, its orientation, and the coordinate systems attached to the body. Chapter 3, “Representing Motion” explains in detail how to orient bodies and their coordinate systems.
Setting these properties sets the body’s initial conditions of motion, if you do nothing else to the Body block or its connected Joints before simulating.
Characteristics of a Body Block
The main characteristics of a Body block are its mass properties,itsposition and orientation in space, and its attached Body coordinate systems (CSs).
The mass properties include the mass and inertia tensor.Themassisareal, positive scalar. The inertia tensor is a real, symmetric 3-by-3 matrix. It does nothavetobediagonal.
2-15
2 Modeling, Simulating, and Visualizing Simple Machines
The position of the body’s center of gravity (CG) and orientation relative to some coordinate system axes indicate where the body is and how it is rotated. These are the body’s initial conditions during construction of the model and remain so when you start the simulation, unless you change them before starting.
The attached Body CSs (their origins and coordinate axes) are fixed rigidly in the body and move with it. The minimum CS set is one, the CS at the CG (the CG CS), with its CS origin at the center of gravity of the body. The default CS set is three, the CG CS and two additional CSs called CS1 and CS2 for connecting to Joints on either side. See the next section, “Configuring the Joint” on page 2-21.
Beyond the minimum CS at the CG, you can attach as many Body CSs on one Body as you want. You need a separate CS for each connected Joint, Constraint, or Driver and for each attached Actuator and Sensor.
The inertia tensor components are interpreted in the CG CS, setting the orientation of the body relative to the CG CS axes. The orientation of the CG CS axes relative to the World axes then determines the absolute initial orientation of the body. Since the CG CS axes remain rigidly fixed in the body during the simulation, this relative orientation of the CG CS axes and the body does not change during motion. The inertia tensor components in the CG CS also do not change. As the body rotates in inertial space, however, the CG CS axes rotate with it, measured with respect to the absolute World axes.
2-16
Properties of the Simple Pendulum Body
The simple pendulum is a uniform, cylindrical steel rod of length 1 meter and diameter 2 cm. The initial condition is the rod lying parallel to the negative x-axis, horizontal in the gravity field. One end of the rod, the fixed pivot for the rod to swing, is located at the ground point (3,4,5). Its coordinate system is called CS1. The center of gravity and the origin of the CG CS is the geometriccenteroftherod. TaketheCGCSaxestobeparalleltotheWorld axes as you set up the pendulum.
Uniform steel has density ρ = 7.93 gm/cc (grams per cubic centimeter). In the CG CS here, the inertia tensor I is diagonal, and I about the z-axis, in the x-y plane. The inertia tensor is always evaluated with
controls the swinging
zz
Modeling and Simulating a Simple Machine
the origin of coordinates at the CG. For a rod of length L = 1 m and radius r = 1cm,themassm = ρπr
I
⎛ ⎜ ⎜
⎜ ⎝
00
xx
I
00
yy
00
I
zz
2
L = 2490 gm (grams), and the inertia tensor I reads
2
mr
⎜ ⎜
=
⎟ ⎠
⎜ ⎜
⎜ ⎝
2
0
00
2
mL
12
00
⎞ ⎟⎟ ⎟
1250 0 0
0 2 08 10 0
0
mL
12
2
⎝ ⎟ ⎟
.
0020810
6
⎞ ⎟ ⎟ ⎟
6
×
.
in gm-cm2(gram-centimeters2). The x-axisisthecylinder’ssymmetryaxis. Thus I
yy
= Izz.
The mass and geometric properties of the body are summarized in the following table and depicted in the figure Equivalent Ellipsoid of Simple Pendulum with Body Coordinate Systems on page 2-18.

Body Data for the Simple Pendulum

Property Value
Mass (gm)
Inertia tensor (kg-m2)
CG Position/Origin (m)
CS1 Origin (m)
2490
[1.25e-4 0 0; 0 0.208 0; 0 0 0.208]
[2.545]
[345]
Configuring the Body Dialog
Take the steps to configuring a Body block in several stages.
2-17
2 Modeling, Simulating, and Visualizing Simple Machines
Equivalent Ellipsoid of Si m ple Pendulum with Body Coordinate Systems
2-18
Adding the Body Block. To start working with the Body block:
1 Open the Bodies library in the SimMechanics library.
2 Drag and
3 Open the Body block dialog box. Note the two m ain areas you need to
drop a Body block into your model window.
configure:
Mass properties — These are the mass and inertia tensor.
Body coordinate systems — These are the details about the position
and orientation of the Body CSs.
Modeling and Simulating a Simple Machine
Specifying the Body’s Mass Properties. Now enter the body’s mass and inertia tensor:
1 UsethedatafromthetableBodyDatafortheSimplePendulumonpage
2-17.
In the Mass field, enter
2490 and change the units to g (grams).
2-19
2 Modeling, Simulating, and Visualizing Simple Machines
2 In the Inertia field, enter [1.25e-4 0 0; 0 0.208 0; 0 0 0.208] and
leave the default units as
kg-m
2
.
Specifying Body Coordinate Systems (Position). Enter the translational position of the body and its Body CS origins in space:
1 UsethedatafromthetableBodyDatafortheSimplePendulumonpage
2-17, and work on the Position tab. Vectors are assumed translated from the World origin and oriented to the World axes.
2 Note the three default CSs in the Body dialog box. The CS at the CG
is necessary for any Body, and you will connect CS1 to the Ground with a Joint shortly.
Delete CS2 b y selecting its line in the Body CS list and clicking the Delete buttonintheBodyCScontrols.
You have two already existing CSs not on this Body that you can use to specify the positions of the Body CS origins that are on this Body:
Preexisting World origin at
[000]
The Adjoining CS on the neighboring body, in this case the Grounded
CS origin at
3 Specify the CG and CS1 origins relative to World:
[3 4 5]
2-20
a In the pull-down menu under Translated from Origin of,choose
World for both coordinate systems, CG and CS1.
b Under Origin Position Vector, specify the position of the origin of each
CS, translated from the World origin:
[3 4 5] for CS1
[2.5 4 5] for CG
4 Select a CS relative to whose coordinate axes the components of the
vectors in the last step are measured. You choose these CS axes in the Components in Axes of menu. Select units as
m (meters).
World for b oth CSs. Leave the
Modeling and Simulating a Simple Machine
Specifying Body Coordinate Systems (Orientation). Enter the rotational orientation of the body and its Body CS axes in space:
1 Work on the Orientation tab. The default orientation for all CS axes is
parallel to World. The sign of all rotations is determined by the right-hand rule.
In the figure Equivalent Ellipsoid of Simple Pendulum with Body Coordinate Systems on page 2-18, the CS1 and CG axes are oriented parallel to the W orld axes, so the CS1 and CG axes need no rotation.
2 For both CSs, set the Relative to CS menu to World.
3 For CG and CS1, leave the Orientation Vector at default [000]and
the Specified Using Convention at default
Euler X-Y-Z.Closethe
Body dialog.

Configuring the Joint

A mechanical system is made up of Bodies with geometric and mass information. But Bodies carry no information of how they move. The possible directions of motion that a Body can take are called its degrees of freedom (DoFs), and this section explains how you represent these DoFs by Joint blocks:
“How to Connect a Joint Between Two Bodies” on page 2-22
“Choosing a Revolute Joint for the Simple Pendulum” on page 2-22
2-21
2 Modeling, Simulating, and Visualizing Simple Machines
DoFs Are Relative SimMechanics DoFs and the Joints that represent them
are relative DoFs. That is, DoFs represent the possible motions between one body and another. So a DoF is defined by a pair of bodies, and you must connect every Joint to two and only two Bodies.
One (but not both) of the members of such a pair of Bodies can be a Ground. The other member B ody of such a pair then has its motion defined relative to a fixed ground point. This fixed ground point does not have to be the same as the World origin. A system can have many such Ground-Body pairs and
must have at least one.
How to Connect a Joint Between Two Bodies
You represent relative motion of bodies with respect to one another by connecting their Body blocks with Joints. You can connect a Body to one or more Joints.
A Joint block is always connected to a spe cific point on the Body on either side of the Joint. The specific point for anchoring a Joint on a Body is the origin of a Body CS, and a Joint is therefore connected on one side to one Body at a Body CS origin, and on the other side to the other Body at a Body CS origin.
2-22
Usually a Body is connected to a Joint on either side, so the default you saw earlier in this tutorial for Body CSs in the Body dialog box is three Body CSs: the CS at the center of gravity (CG) and two other CSs (CS1 and CS2). But a Body at the end of a Body — Joint — ... — Body chain is connected to only one J oint.
Choosing a Revolute Joint for the Simple Pendulum
In spite of the complexity of the concepts im plicit in a Joint, the actual configuration of a Joint block is fairly simple. Here you insert and configure one revolute Joint block between the Ground and Body blocks you’ve already put into the model window.
Modeling and Simulating a Simple Machine
A Simple Pendulum Connected to Ground by a Revolute
Configuring the Revolute Joint B lock. The geometry of the Joint
connection is shown in the figure preceding. The ground point at (3,4,5) and the CS1 at (3,4,5) are actually the same point in space, but have been separated in the figure for clarity. The revolute rotation axis is along the +z direction:
1 Open the Joints library in the block library.
2 Drag and drop a Revolute block into your model window.
atetheRevoluteblocksothatyoucanconnectthebase(B)sideofthe
3 Rot
nt to the Ground block and the follower (F) side of the Joint to the Body
Joi
ock. Make the two connections.
bl
2-23
2 Modeling, Simulating, and Visualizing Simple Machines
4 Open the Revolute dialog box . In the Parameters area, on the Axes tab,
configure the rotation axis to the World z-axis:
a Enter [0 0 1] under Axis of Action [x y z].
b Leave the Reference CS at World.
c Ignore the Advanced tab.
Note several important things:
Under Connection parameters,theCurrent base is located at
GND@Ground, which is the Grounded CS associated with the Ground
block located at (3,4,5) in World.
Under Connection param eters,theCurrent follower is located at
CS1@Body, which is the CS1 on Body1 located at (3,4,5) in World.
This Joint’s directionality runs from Ground to Body along the +z-axis.
5 Close the Revolute dialog box.
2-24
Modeling and Simulating a Simple Machine
Congratulations — you have now finished the simplest possible model of a machine: a connected block diagram of Ground–Joint–Body. Your model window should look like this.

Adding a Sensor and Starting the Simulation

To measure the motion of the pendulum as it swings, you need to connect one or more Simulink Scope blocks to your model. The SimMechanics library of Actuators and Sensor blocks gives you the means to input and output Simulink signals to and from SimMechanics models. Sensors allow you to watch the mechanical motion once you start the simulation, as the following explain:
“Connecting and Configuring the Pendulum Sensor” on page 2-25
“Configuring the Machine Environment and Configuration Parameters”
on page 2-27
“Starting and Interpreting the Motion” on page 2-29
Connecting and Configuring the Pendulum Sensor
In this example, you measure the angular motion of the revolute joint:
1 In the block library, open the Sensors & Actuators library. Drag and drop a
Joint Sensor block into your model window.
2-25
2 Modeling, Simulating, and Visualizing Simple Machines
2 Open the R ev olute block. Change Number of sensor/actuator ports
from
0 to 1 using the spinner menu. An open connector port appears on
the side of Revolute. Close Revolute.
3 Connect this connector port to the connector port on the Joint Sensor block.
The open connector port changes to solid
4 Open Joint S ensor. Select the Angle and the Angular velocity check
boxes. Unselect the Output selected parameters as one signal check box.
Leave the other defaults. Close the Joint Sensor block.
5 Open the Simulink Library Browser. From the Sinks library, drag and
drop a Scope block and an XY Graph block into y our model window. From the Signal Routing library, drag and d rop a Mux block as well. Connect the Simulink outports > on the Joint Sensor block to the Scope and XY Graphblocksasshown.
.
2-26
Modeling and Simulating a Simple Machine
The lines from the outports > to the Scope and XY Graph blocks are normal Simulink signal lines and can be branched. You cannot branch the lines connecting SimMechanics blocks to each another at the round connector ports
6 Save y
You no can r
.
our model for future reference as
spen.mdl.
w need to configure the global parameters of your model before you
un it.
Configuring the Machine Environment and Configuration Parameters
The Configuration Parameters dialog box is a standard feature of Simulink. Reset its entries for this model to obtain more accurate simulation results.
2-27
2 Modeling, Simulating, and Visualizing Simple Machines
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 Max step size to
If you want the simulation to continue running without stopping, change Stop time to
3 Close the Configuration Parameters dialog box.
A special feature of SimMechanics modelsistheMachineEnvironmentblock.
1 Open your block diagram’s Machine Environment block dialog.
0.2.
inf. The pendulum period is approximately 1.6 seconds.
1e-6 and Absolute tolerance to 1e-4. Change
Note the default Gravity vector,
[0 -9.81 0] m/s
2
, which points in the -y direction, as shown in the figure Equivalent Ellipsoid of Simple Pendulum with Body Coordinate Systems on page 2-18. The gravitational acceleration g = 9.81 m/s
2
.
2-28
2 Close the Machine Environment dialog.
Modeling and Simulating a Simple Machine
Starti
ng and Interpreting the Motion
You can now start your simulation and watch the pendulum motion via the Scope and XY Graph blocks:
1 Open the XY Graph block dialog box. Set the following parameters.
meter
Para
x-mi
ax
x-m
min
y-
-max
y
n
Val u
200
-5
5
e
0
00
00
2-29
2 Modeling, Simulating, and Visualizing Simple Machines
Leave Sample time at default and close the dialog.
2 Open the Scope block and start the model. The XY Graph opens
automatically when you start the simulation.
3 View the full motion of both angle and angular velocity (in degrees and
degrees per second, respectively) as functions of time in Scope . Click
Autoscale if the motion is not fully visible.
2-30
The motion is periodic but not simple harmonic (sinusoidal), because the amplitude of the swing is so large (180 degrees from one turning point to the other). Note that the zero of angle is the initial horizontal angle, not the vertical. The zeros of motion are always the initial conditions.
The XY Graph shows the angle versus angular velocity, with no explicit time axis. These two variables trace out a figure similar to an ellipse, because of the conservation of total energy E:
1
J
2
2
d
mgh E
⎜ ⎝
+∗− ==( sin ) constant
dt
1
Modeling and Simulating a Simple Machine
where J=Izz+mL2/4 is the inertial moment of the rod about its pivot point (not the center of gravity). The two terms on the left side of this equation are the kinetic and potential energies, respectively. The coordinate-velocity space is the phase space of the system.
Phase Space Plot of Simple Pendulum Motion: Angular Velocity Versus Angle
The directionality of the Revolute Joint assumes that the rotation axis lies in the +z direction. Looking at the pendulum from the front, follow the figures
A Ground Point Relative to World on page 2-14
Equivalent Ellipsoid of Simple Pendulum with Body Coordinate Systems
on page 2-18
A Simple Pendulum Connected to Ground by a Revolute on page 2-23
Positive angular motion from this perspective is counterclockwise, following the right-hand rule.
The next tutorial walks you through visualizing and animating this same simple pendulum model.
2-31
2 Modeling, Simulating, and Visualizing Simple Machines

Visualizing a Simple Machine

In this section...
“Visualizing and Animating the Simple Pendulum” on page 2-32
“Starting Visualization” on page 2-3 2
“Selecting a Body Geometry” on page 2-34
“Displaying the Pendulum” on page 2-34
“Modeling and Visualizing M ore Complex Machines” on page 2-37

Visualizing and Animating the Simple Pendulum

In this section, you learn how to view the swinging steel rod of the model introduced in the last section using the SimM ech a nics visualization window. Use y our saved
SimMechanics visualization displays a machine by displaying its bodies. You can display the bodies in two standard ways, by equivalent ellipsoids and by closed surfaces (convex hulls) enveloping the bodies’ coordinate systems. This section explains how to visualize your pendulum using either standard body geometry.
spen.mdl model, or use the mech_spen demo model.
2-32
You can view the pendulum before you start and, separately, choose to animate it during simulation as well.

Starting Visualization

The first step is to configure the Configuration Parameters dialog.
1 On the Simulink menu bar, open the Simulation menu and select the
Configuration Parameters entry. The Configuration Parameters dialog
appears. Select the SimMechanics subnode, under the Simscape node, at the lower left.
Visualizing a Simple Machine
2 To view the pendulum in its static initial state, select the Display
machines after updating diagram check box.
To animate the pendulum visualization while the simulation is running, select the Show animation during simulation check box as well.
3 Click OK. S elect Update Diagram from the Edit menu to open the
visualization window.
2-33
2 Modeling, Simulating, and Visualizing Simple Machines
Selecting a Body
The information model is enough t an external bod have enough inf
that you use to specify body properties in a SimMechanics
o display each body in a standard abstract shape. Without
y geometry definition, SimMechanics visualization does not
ormation to display its full shape.
Geometry
Equivalent Ellipsoids
A rigid body h with the same
Because the its three ge
equivalent ellipsoid are a
1.12 cm.
Convex Hu
Each Body coordinate system (CS) has an origin point, and the collection of all these points, in general, defines a volume in space. The minimum outward-bending surface enclosing such a volume is the convex hull of the Body CSs.
You created the pendulum body with only two Body CSs , CG and CS1. The convex hull excludes the CG CS and thus, for the pendulum rod, is just the CS1origin,apoint.
as a unique equivalent ellipsoid, a homogeneous solid ellipsoid
inertia tensor.
rod has an axis of symmetry, the x -axisinthiscase,twoof
neralized radii are equal: a
53 2/(/)L
=
x
= az. The generalized radii of the
y
=0.646manday= az=
52(/)r
lls
=
2-34
Imple
In the Model menu of the visualization window, you can choose how the pendulum or any machine bodies are displayed. In the Body Geometries submenu, choose Convex Hulls or Ellipsoids.
menting Your Body Geometry Choice

Displaying the Pendulum

You can access the SimMechanics visualization windo w from any SimMechanics model. To open it or to synchronize it at any time with your model, select Update Diagram in your model window’s Edit menu.
Visualizing a Simple Machine
Displaying the Pendulum as a Convex Hull
The displayed figure depends on the body geometry you choose. If you chose Convex Hulls in the Model > Body Geometries menu, a convex hull appears.
Pendulum Rod Displayed as a Convex Hull
You can change the viewpoint and manipulate the image with the controls in the toolbar and menus. Experiment with the SimMechanics menu’s settings to see various ways of displaying the pendulum.
2-35
2 Modeling, Simulating, and Visualizing Simple Machines
When you start the model, the body in the graphics w indow moves in step with the simulation.
Displaying the Pendulum as an Equivalent Ellipsoid
To display the pendulum as an equivalent ellipsoid, follow the previous steps, but change the body geometry choice:
1 Open the Model menu and select Body G eometries.
2 In the submenu, select Ellipsoids.
The display changes. The equivalent ellipsoid looks like this.
2-36
Pendulum Rod Displayed as an Equivalent Ellipsoid
Visualizing a Simple Machine
Modeling and Vis
The next tutoria complex machine Joint blocks no the first two tu
l shows how to create, run, and visualize a model for a more
, a four bar mechanism. To configure Ground, Body, and
w means repeating and expanding upon the three blocks of
torials.
ualizing More Complex Machines
2-37
2 Modeling, Simulating, and Visualizing Simple Machines

Modeling and Simulating a Closed-Loop Machine

In this section...
“Modeling the Four Bar Mechanism” on page 2-38
“Counting the Degrees of Freedom” on page 2-39
“Configuring the Mechanical Environment” on page 2-40
“Setting Up the Block Diagram” on page 2-42
“Configuring the Ground and Joints” on page 2-45
“Configuring the Bodies” on page 2-49
“Sensing Motion and Running the Model” on page 2-54
“For More About the Four Bar Mechanism” on page 2-59

Modeling the Four Bar Mechanism

In this tutorial, you build a model of a planar, four bar mechanism and practice using some of the important SimMechanics features.
2-38
You are urged to work through “Modeling and Simulating a Simple Machine” on page 2-11 and “Visualizing a Simple Machine” on page 2-32 before proceeding with this section. Learn more about how to position and orient bodies in Chapter 3, “Representing Motion”.
The system consists of three moving bars of homogeneous steel, two connected at one end each to ground points and a third crossbar connecting the first two. The base acts as an immobile fourth bar, with a Ground at each end. The mechanism forms a single closed loop, and its motion is confined to two dimensions.
A Four Bar Mechanism
Modeling and Simulating a Closed-Loop Machine
The elementary parts of the mechanism are the bodies, w hile the revolute joints are the idealized rotational degrees of freedom (DoFs) at each body-to-body contact point. The bodies and the joints expressing the bodies’ relative motions must be translated into corresponding SimMechanics blocks. If you want, you can add elaborations such as Constraints, Drivers, Sensors, and Actuators to this essential block diagram.

Counting the Degrees of Freedom

The three moving bars are constrained to move in a plane. So each bar has two translational and one rotational DoFs, and the total number of mechanical DoFs, before counting constraints, is 3*(2+1) = 9.
Because the motion of the bars is constrained, however, not all of these nine DoFs are independent:
In two dimensions, each connection of a body with another body or with a
ground point imposes two restrictions (one for each coordinate direction).
2-39
2 Modeling, Simulating, and Visualizing Simple Machines
Such a restriction effectively eliminates one of the two body ends as independently moving points, because its motion is determined by the next body’s end.
There are four such body-body or body-ground connections and therefore
eight restrictions implicit in the machine’s geo metry.
The eight restrictions on the nine apparent DoFs reduce the DoFs to one, 9 - 8 = 1. There are four rotational DoFs betwe en bars or between bars and grounds. But three of these are dependent. Specifying the state of one rotational DoF fully specifies the other three.

Configuring the Mechanical Environment

Open a new blank model window from the SimMechanics library. From the Bodies library, drag in and drop a Machine Environment block and a Ground block. Enable the Ground’s Machine Environment port and connect the environment block to the Ground.
First you need to configure the machine’s mechanical settings. Open the Machine Environment block. The block dialog box appears.
2-40
Modeling and Simulating a Closed-Loop Machine
The Machine Environment Dialog Box Tabs
Click the four tabs in succession to display each pane.
Tab Function
Parameters
Constraints Sets constraint tolerances and how constraints are
Linearization
Visualization
Controls general settings for mechanical simulations
interpreted
Controls how SimM echanics models are linearized with Simulink
Chooses whether or not to visualize the machine
2-41
2 Modeling, Simulating, and Visualizing Simple Machines
Note some important features of this dialog box:
The Gravity vector field specifies the magnitude and direction o f
gravitational acceleration and sets the vertical or up-down direction.
The Linear and Angular assembly tolerance fields are also set here.
Change Angular assembly tolerance to “Controlling Machine A ssembly”.)
Leave the other defaults.
Close the dialog by clicking OK.
Starting V isualization
Tip If possible, open the visualization window before building a model. With
it, you can keep track of your mo del components and how they are connected, as well as correct mistakes.
1e-3 deg (degrees). (See
2-42
To visualize the bodies as you build the model, go to the SimMechanics node of the Configuration Parameters dialog:
1 Select the Display machines after updating diagram check box. If you
want to animate the simulation later when you run the model, select the
Show animation during simulation check box as well. Click OK or Apply.
Then select Update Diagram from the Edit menu or enter Crtl+D at the keyboard. The visualization window opens.
2 In the Model menu, select Body Geometries,thenEllipsoids.
As you add and change bodies in your model, you can update the display in yourwindowatanytimebyupdatingyourdiagram.

Setting Up the Block Diagram

In this set of steps, you create Bodies, position them, connect them with Joints, then configure the Body and Joint properties. The Body dialog boxes
Modeling and Simulating a Closed-Loop Machine
give you many ways to represent the same system in the same physical state. This section explains one way.
Alternative, equivalent ways of configuring Bodies are discussed in “Body Coordinate Systems”.
MAT-File Data Entry
The geometric and mass properties you need to specify for the Grounds and Bodies in this model are listed in the tables of the following two sections, “Configuring the Ground and Joints” on page 2-45 and “Configuring the Bodies” on page 2-49.
Instead of typing the numerical values of these properties into the dialog boxes, you can load the variable set you need into the workspace by entering
load fourbar_data
at the MATLAB command line. The variable name for each property is given in the tables. Just enter the appropriate variable names in the appropriate fieldsasyoucometotheminthedialogboxes.
Block Diagram Setup
Your model already has one environment block and one ground block. Assemble the full model with these steps:
1 In the block library, open the Bodies library. Drag and drop another
Ground block and three Body blocks into the new model window. Close the Bodies library.
2 From the Joints library, drag and drop fo ur Revolute blocks into the model
window.
3 Rotate and connect the blocks in the pattern shown in the following figure
or with an equivalent block diagram topology.
Use the block names shown in this figure for later consistency.
2-43
2 Modeling, Simulating, and Visualizing Simple Machines
2-44
Connected Environment, Ground, Body, and Joint Blocks for the Four Bar
Block Diagram Topology. The topology of the block diagram is the
connectivity of its elements. The elements are the Bodies and Grounds, connected by the Joints. Unlike the model of “Modeling and Simulating a Simple Machine” on page 2-11, the four bar mechanism is a closed-loop mechanism. The two Ground blocks represent points on the same absolute, immobile body, and they close the loop of blocks. The simple pendulum has only one ground and does not close its block connections.
To ma i nta in consistent Body motion direction, make sure the Body coordinate system (CS) port etc., for each bar, moving from Ground_1 to Ground_2, from right to left, as shown. To make the Joints consistent with the Body motion, the base-follower pairs
B-F, B-F, etc., should follow the sam e right-to-left sequence.
pairs on each Body follow the sequence CS1-CS2, CS1-CS2,
Modeling and Simulating a Closed-Loop Machine

Configuring the Ground and Joints

Now configure the Ground blocks with the data from the following ta bl e. Grounded coordinate systems (CSs) are automatically created.
Geometry of the Four Bar Base
This table summarizes the geome try of ground points.

Geometric Properties of the Four Bar Grounds

Property Value MAT-File Variable
Ground_1 point (m)
Ground_2 point (m)
The base of the mechanism has these measurements:
The base is horizontal, with length 86.7 cm.
[ 0.433 0.04 0 ] gpoint_1
[-0.434 0.04 0 ] gpoint_2
Ground_1 represents the ground point 43.3 cm to the right of the World
CS origin.
Ground_2 represents the ground point 43.4 cm to the left of the W orld
CS origin.
The bottom rev olute s are 4 cm above the origin (x-z)plane.
Setting Up the Grounds
To represent ground points on the immobile base, you need to configure the Ground blocks. Use the variable names if you’ve loaded into your workspace:
1 Open Ground_1 and enter [ 0.433 0.04 0 ] or gpoint_1 in the Location
field.
2 Open Ground_2 and enter [-0.434 0.04 0 ] or gpoint_2 in the Location
field.
3 Leave both pull-down menus for units at default m (meters).
fourbar_data.mat
2-45
2 Modeling, Simulating, and Visualizing Simple Machines
2-46
Configuring the Revolute Joints
The thre you need
1 Open ea
2 Leave these Revolute joint block defaults and ignore the Advanced tab.
The Body CS and base-follower joint directionality should be set up as shown in the block diagram of the figure Connected Environment, Ground, Body, and Joint Blocks for the Four Bar on page 2-44. In the Connection parameters area, the default Joint directionality for each Revolute automatically follows the right-to-left sequence of Grounde d and Body CSs:
e nongrounded bars move in the plane of your screen (x-y plane), so
to make all the Revolute axes the z-axis (out of the screen):
ch Revolute’s dialog box in turn. In its Parameters area, note on
the Axe
in ea
1]
s tab that the z-axisisthedefault: Axis of Action is set to
ch, relative to Reference CS
World. Leave these defaults.
[0 0
A Revolute block contains only one primitive joint, a single revolute DoF. So the Primitive is automatically
revolute. Its name within the block is R1.
Modeling and Simulating a Closed-Loop Machine
Revolute1: Base to follower: GND@Gound_1 to CS1@Bar1
Revolute2: Base to follower: CS2@ Bar1 to CS1@Bar2
Revolute3: Base to follower: CS2@ Bar2 to CS1@Bar3
Revolute4: Base to follower: CS2@Bar3 to GND@Ground_2
In this Joint directionality convention,
At each Joint, the leftward Body moves relative to the rightward Body.
The rotation axis points in the +z direction (out of the screen).
Looking at the mechanism from the front in the figure, A Four Bar
Mechanismonpage2-39,thepositiverotational sense is counterclockwise. All Joint Sensor and Actuator data are interpreted in this sense.
2-47
2 Modeling, Simulating, and Visualizing Simple Machines
2-48
Modeling and Simulating a Closed-Loop Machine
Configur
Setting t paramet
Mass pro
Length
Center
Body co
trast to the first tutorial, where you specify Body CS properties with
In con
ct to the absolute World CS, in this tutorial, you specify Body CS
respe
ins on the bars in relative coordinates, displacing Bar1’s CS1 relative to
orig
nd_1, B ar2’s CS1 relative to Bar1, and so on, around the loop. You can
Grou
r the definition of a Body CS to three types of coordinate systems:
refe
To W
To t
ing the Bodies
he Body properties is similar for each bar, but with different
er values entered into each dialog box:
perties
s and orientations
of gravity (CG) positio ns
ordinate systems ( CSs)
orld
he other Body CSs on the same Body
2-49
2 Modeling, Simulating, and Visualizing Simple Machines
To the Adjoining CS (the coordinate system on a neighboring body or
ground directly connected by a Joint to the selected Body CS).
The components of the displacement vectors for each Body CS origin continue to be oriented with respect to the World axes. The rotation of each Body’s CG CS axes is also with respect to the World axes, in the Euler X-Y-Z convention.
The following three tables summarize the body properties for the three bars.

Bar1MassandBodyCSData(MKSUnits)

Property Value Variable Name
Mass
Inertia tensor
CG Origin [0.03 0.282 0] from CS1 in
CS1 Origin [0 0 0] from Adjoining in
CS2 Origin [0.063 0.597 0] from CS1 in
CG Orientation [0 0 83.1] from World in
5.357 m_1
[1.07e-3 0 0; 0 0.143 0; 0 0 0.143]
axes of
axes of
axes of
convention
World
World
World
Euler X-Y-Z
inertia_1
cg_1
cs1_1
cs2_1
orientcg_1
2-50

Bar2MassandBodyCSData(MKSUnits)

Property Value Variable Name
Mass
Inertia tensor
CG Origin [-0.427 0.242 0] from CS1
9.028 m_2
[1.8e-3 0 0; 0 0.678 0; 0 0 0.678]
inertia_2
cg_2
in axes of World
Modeling and Simulating a Closed-Loop Machine
Bar2 Mass and Body CS Data (MKS Units) (Continued)
Property Value Variable Name
CS1 Origin [0 0 0] from Adjoining in
axes of
World
CS2 Origin [-0.87 0.493 0] from CS1 in
axes of
World
CG Orientation [0 0 29.5] from World in
convention
Euler X-Y-Z
cs1_2
cs2_2
orientcg_2

Bar3MassandBodyCSData(MKSUnits)

Property Value Variable Name
Mass
Inertia tensor
CG Origin [-0.027 -0.048 0] from CS1
0.991 m_3
[2.06e-4 0 0; 0 1.1e-3 0; 0 0 1.1e-3]
inertia_3
cg_3
in axes of World
CS1 Origin [0 0 0] from Adjoining in
axes of
World
CS2 Origin [0 0 0] from Adjoining in
axes of
World
CG Orientation [0 0 60] from World in
convention
Euler X-Y-Z
cs1_3
cs2_3
orientcg_3
Configuring the Bodies
Here are the common steps for configuring the Body dialogs of all three bars. See the three preceding tables for Bodydialogboxmassproperty(massand inertia tenso r) entries. The units are MKS: lengths in meters (m), masses in kilograms (kg), and inertia tensors in kilogram-meters
1 Open all three Body dialogs for each bar. Enter the mass properties for
each from the tables in the Mass and Inertia fields.
2
(kg-m2).
2-51
2 Modeling, Simulating, and Visualizing Simple Machines
2 Now work in the Body coordinate systems area, the Position tab:
a Set the Components in Axes of me nu, for each Body CS on each bar,
to
World.
b Leave units as default m (meters).
3 Set the Body CS properties for each Body CS on each bar from the data of
the preceding tables:
a Enter the Body CS origin position data for CG, CS1, and CS2 on each
bar from the tables or from the corresponding MAT-file variables.
b Set the Translated from Origin of menu entries for each Body CS on
each bar according to the values in the tables.
4 Select the Orientation tab by clicking its tab:
a Enter the Orientation Vector for the CG on each bar from the tables
or from the corresponding MAT-file variables.
b Choose World for Relative CS in each case.
2-52
c Lea ve the other fields in their default values.
Modeling and Simulating a Closed-Loop Machine
2-53
2 Modeling, Simulating, and Visualizing Simple Machines
Visualizing the Bodies
Thefrontviewofthefourbarmechanism, with the bodies displayed as equivalent ellipsoids, looks like this:
2-54

Sensing Motion and Running the Model

You finish building your model by setting initial conditions a n d inserting Sensors.
Before you start a simulation, you need to set its kinematic state or initial conditions. These include positions/angles and linear/angular velocities. This information, the machine’s initial kinematic state, is discussed further in
Modeling and Simulating a Closed-Loop Machine
“Kinematics and the Machine’s State of Motion” on page 3-2 and “Applying Motions and Forces”.
You can se ns e motion in any model in two basic ways: se ns ing bodies or sensing joints. Here you sense Joint motion, using Joint Sensor blocks and feeding their Simulink signal outputs to Scope blocks.
Caution Because they are immobile, ground points cannot be moved, nor do they have any motion to measure.
Therefore, you cannot co nnect Ground blocks to Actuator or Sensor blocks.
Connecting the Joint Sensors
To sense the motion of the R evolute2 and Revolute3 blocks,
1 From the Sensors & Actuators library, drag and drop two Joint Sensor
blocks into the model window. Drag Joint Sensor next to Revolute2 and Joint Sensor1 next to Revolute3.
2 Before you can attach a Joint Sensor block to a Revolute block, you need
to create a new open round connector port
on the Revolute. Open
Revolute2’s dialog box:
a In the Connection parameters area in the middle, adjust the spinner
menu Number of sensor/actuator ports to the value
A new connector port
b Connect this connector port to the open round connector port on Joint
appears on Revolute2.
1.ClickOK.
Sensor.
3 Now repeat the same steps with Revolute3:
a Create one new connector port on Revolute 3.
b Connect this port to Joint Sensor1.
4 Be sure to connect the outports > of the Sensor blocks to a Simulink Sink
block. These outports are normal Simulink signals.
2-55
2 Modeling, Simulating, and Visualizing Simple Machines
Graphical Plot of Joint Motion with a Scope Blo ck
Here you can view the Joint Sensor measurements of Revolute2 and Revolute3’s motions using a Scope block from the Simulink Sinks library:
1 Open the Simulink Library Browser. From the Sinks library, drag and
drop a Scope block into your model window in between Joint Sensor and Joint Sensor1 blocks. Rename the Scope block “Angle.”
2 Open the Angle block. In this scope window’s toolbar, open the Parameters
box. Under Axes,resetNumber of axes to appears on the Angle block.
3 Expand the scope window for ease of viewing.
4 Connect the Joint Sensor and Joint Sensor1 block outports > to the Angle
block inports
5 Open Joint Senso r and Joint Sensor1:
a In the Measurements area, Connected to primitive is set to R1
in both blocks, indicating the first and only primitive revolute inside Revolute2 and Revolute3 to which each Sensor can be connected.
>.
2.ClickOK. A second inport >
2-56
b Select the Angle check box to measure just the angle. Leave the units in
default as
deg (degrees). The Simulink line will contain one scalar.
Modeling and Simulating a Closed-Loop Machine
Your completed model should look similar to the mech_four_bar demo model.
Caution Sensor and Actuator blocks are the only blocks that can connect SimMechanics blocks to normal Simulink blocks.
Configuring and Running the Simulation
Now take the final steps to prepare and start the model:
1 In the model window Simulation menu, select Co nfiguration
Parameters:
a In the Solver node, change Absolute tolerance to 1e-6.
b Leave the other defaults and click OK.
2-57
2 Modeling, Simulating, and Visualizing Simple Machines
2 Now run the model by clicking Start in the Simulink toolbar. The four bar
mechanism will fall under the influence of gravity.
Note some features of the simulation:
In this example, the mechanism starts from rest, with the initial velocities
at zero. Thus the initial state of the four bar system is just the geometric state that you set up in “Setting Up the Block Diagram” on page 2-42.
The assembly at first falls over to the right, and the Revo lute2 angle
decreases.
Bar3 turns all the way around, and Bar2 and Bar1 turn back to the left.
The Revolute2 angle reverses direction. Revolute3 sweeps through a complete turn. Angles are mapped to the interval (-180 discontinuities.
The motion repeats periodically, as there is no friction.
o
,+180o] and exhibit
2-58
Modeling and Simulating a Closed-Loop Machine
Animation
If you leave your visualization window open at the time you sta rt the simulation and select the Animate machine d uring simulation check box in the SimMechanics node of the Configuration Parameters dialog, the visualized machine moves in step with the simulation.
YoucannowcomparetheanimatedmotionwiththeScopeplotsofthe Revolute2 and Revolute3 angles.

For More About the Four B ar Mechanism

The four bar system is also discussed in the context of advanced SimMechanics features and methods: “Modeling Degrees of Freedom”, “Validating Mechanical M odels”, “Finding Forces from Motions”, “Trimming Mechanical Models”, and “Linearizing Mechanical Models”.
2-59
2 Modeling, Simulating, and Visualizing Simple Machines
2-60

Representing Motion

This chapter explains the SimM echanics representation of body position, orientation, and motion. It connects mechanics concepts commonly used in physics and engineering with specific SimMechanics implementations. The last section is a case study on configuring a SimMechanics Body block to represent position and orientation.
This chapter assumes some familiarity with mechanics and vector analysis. You should work through it as a single unit. Consult “References” on page 3-11 for more.
3
“Kinematics and the Machine’s State of Motion” on page 3-2
“Body Motion in SimMechanics Representations” on page 3-5
“Body Orientation in SimMechanics Representations” on page 3-12
“Orienting a Body and Its Coordinate Systems” on page 3-19
3 Representing Motion

Kinematics and the Machine’s State of Motion

In this section...
“About Kinematics” on page 3-2
“Degrees of Free do m” on page 3-2
“The State of Motion” on page 3-2
“Home, Initial, and Assembled Configurations” on page 3-3
“For More Information” on page 3-3

About Kinematics

Kinematics is the description of a machine’s motion without regard to forces, torques, and the mass properties of bodies. Because accelerations are proportional to forces a nd torques, if you know the mass properties of the bodies and the forces and torques applied to them, you need only the initial positions a nd their first derivatives (velo cities) to integrate a machine’s motion. You should also understand and keep in mind the following related concepts.
3-2

DegreesofFreedom

The relative position and orientation of a body with respect to a neighbor constitute up to six degrees of freedom (DoFs). The fundamental DoFs are translational (one body sliding relative to another along a prismatic axis) and rotational (one body rotating relative to another about a revolute axis, or one body pivoting relative to another about a spherical pivot point).
SimMechanics DoFs are represented by Joint blocks connected between Body blocks. Bodies without Joints have no DoFs and acquire DoFs only by having Joints connected to them. A SimMechanics machine’s motion state is represented b y the positions (prismatics), angles (revolutes or sphericals), and their first derivatives with respect to time (velocities).

The State of Motion

The state of motion of a mechanical system is the set of the instantaneous positions and orientations of all its bodies and their linear and angular
Kinematics and the Machin e’s State of Motion
velocities. SimM echanics body positions/orientations are relative:onebody’s state is specified with respect to its neighbors. The absolute positions and velocities of the bodies’ states are determined via the machine’s connections to one o r more grounds. These grounds are at rest in World, although they do not have to coincide w ith the World origin.

Home, Initial, and Assembled Configurations

When you start your model, the SimMechanics simulation configures your machines in preparation for motion by stepping them sequentially through three states.
The simulation starts by analyzing the machines in their home
configurations. A machine in its home con figur a tion has all its bodies
positioned and oriented purely according to the Body block dialog data. All body velocities are zero.
From the model’s initial condition actuators, the simulation then applies
initial condition (position, orientation, and velocity) data to the joints of the model, changing its machines to their initial configurations.
Finally, the simulation assembles any disassembled joints in the model,
transforming the machines to their assembled configurations.While doing this, it holds fixed any positions and orientations specified by initial condition actuators.
The a sse mbled configuration is the final premotion machine state.
Updating your SimMechanics diagram (from the Edit menu or by pressing Ctrl+D) resets the model to its currently valid home configuration.

For More Information

For a detailed explanation of h ow to represent body motio ns , see “Body Motion in SimMechanics Representations” on page 3-5.
“Modeling Mechanical Systems” contains full information on SimMechanics machine modeling.
“Modeling Rigid Bodies”
“Modeling Degrees of Freedom”
3-3
3 Representing Motion
“Specifying Initial Positions and Velocities”
“Counting Model Degrees of Freedom”
“How SimMechanics Software Works” e n umerates the co m plete SimMechanics simulation steps.
Refer also to the of SimM echanics DoFs and construction of the machine state.
mech_stateVectorMgr command reference for identification
3-4
Body Motion in SimMechanics™ Representations

Body Motion in SimMechanics Representations

In this section...
“About Body Motion” on page 3-5
“Machine Geometry and Motion” on page 3-5
“Reference Frames and Coordinate Systems” on page 3-6
“Relating C oordinate Systems in Relative Motion” on page 3-6
“Observing Body Motion in Different Co ordinate Systems” on page 3-8
“Representing Body Translations and Rotations” on page 3-10
“References” on page 3-11

About Body Motion

This section summarizes obse rver coordinate systems, measuring body motion, a nd the SimMechanics representation of a body’s motion. It a ssumes a basic knowledge of vector algebra and analysis. Goldstein [2]; Murray, Li, and Sastry [3]; and Shuster [4] present coordinate transformations, rotations, and rigid body kinematics in detail. The preceding section, “Kinematics and the Machine’s State of Motion” on page 3-2, should also be helpful.
Each topic in this section builds on the preceding one. Therefore, you should scan linearly through the whole section, then read it in detail.

Machine Geometry and Motion

Machines are composed of bodies, which have relative degrees of freedom (DoFs). Bodies have positions, orientations, mass properties, and sets of Body coordinate sy stems . Joints represent the motions of the bodies.
A machine’s geometry consists of its static body features before starting a
simulation: positions, orientations, and Body coordinate systems.
A machine’s kinematics consist of all degrees of freedom (D oFs) of all
bodies: the positions/orientations andtheirderivativesofatanyinstant during the machine’s motion.
3-5
3 Representing Motion
The full description of a machine’s motion includes not only its kinematics, but also specification of its observ ers, who define reference frames (RFs) and coordinate systems (CSs) for measuring the machine motion.
All vectors and tensors, unless otherwise noted, are represented by Cartesian matrices with three and nine, respectively, spatial components measured by rectangular coordinate axes.

Reference Frames and Coordinate Systems

The reference frame of an observer is an observer’s state of motion, which has to be measured by other observ ers. A SimMechanics model simulates a machine’s motion using its Newtonian dynamics, which takes its simplest form in the set of inertial RFs, the set of all frames unaccelerated with respect to inertial space. Within an RF, you can pick any point as a coordinate system origin, then se t up Cartesian (orthogonal) axes there.
The master SimMechanics inertial RF is called World. A CS origin and axis triad are also defined in World. World can mean either the RF or the CS, although in most contexts, it means the World coordinate system. World defines absolute rest and a universal coordinate origin and axes independent of any bodies and grounds in a machine.
3-6
A common synonym for coordinate system is working frame.

Relating Coordinate Systems in Relative Motion

Now add a second C S, called O, whose origin is translating with respect to the W orld origin and whose axes are rotating w ith respect to the World axes. Later in this section, this second CS is identified with a CS fixed in a moving body. (See “Representing Body Translations and Rotations” on page 3-10.)
Loading...