| SimMechanics™ | ![]() |
| On this page… |
|---|
Simulink® can simulate a SimMechanics™ model only if it is valid. A model is valid if it satisfies the following rules:
Each machine in the model contains at least one Ground, and exactly one Ground in each machine is connected to a Machine Environment block. Each submachine connected to a full machine by a Shared Environment block must have at least one Ground.
See Representing Machines with Models in this chapter.
Every machine in the model is topologically valid. See Verifying Machine Topology.
The model contains at least one degree of freedom. See Counting Degrees of Freedom.
Any machine in the model interfaced to Simscape™ mechanical circuits satisfies both SimMechanics and Simscape modeling rules. See Combining One- and Three-Dimensional Mechanical Elements in this chapter.
To avoid simulation failures, you must ensure that the topology of your block diagram is valid. A block diagram is topologically valid if each machine that it contains is valid. A machine is valid if its spanning tree is valid. Thus to determine if your model is valid, first determine the spanning tree of each machine that it contains and then the validity of each resulting tree.
When examining your model's topology, be sure to inspect all its subsystems, including masked subsystems, down to the bottom of the model's subsystem hierarchy.
To determine the spanning tree of a machine, remove all blocks from the machine except Body and Joint blocks and open every closed loop in the resulting reduced machine. To open a closed loop, follow the loop-cutting rules in Cutting Closed Loops.
For example, here is a machine with two closed loops.

Cutting the top loop at the Disassembled Prismatic and removing the Parallel Constraint block (thus simultaneously cutting the bottom loop) yields the machine's spanning tree, as shown here.

To be valid, a spanning tree must meet these requirements:
The spanning tree must have at least one Ground block to serve as a reference to World.
Every Joint block must be connected to exactly two Body blocks.
Every non-Ground Body block must have a unique path to a Ground block. (This need not be true of the machine itself.) This ensures that, while each body moves via joints relative to other bodies, the simulation can resolve all bodies' motions into absolute motions with respect to World.
Every non-Ground Body block at an end of a sequence of Bodies must have nonzero inertia (mass or inertial moment) associated with all joint primitives that can move. Each translational DoF must carry a nonzero mass, and each rotational DoF a nonzero inertial moment. This prevents infinite accelerations when forces and torques are applied.
Here are some examples of invalid topologies:
This one-loop machine lacks a Ground block.

This open machine has a dangling Joint block.

Another open machine features a zero-mass body at one end of a chain of bodies.

The last two invalid examples are dynamically (but not topologically) equivalent, because a zero-mass body is dynamically no body at all.
Identifying and counting the independent degrees of freedom (DoFs) of a machine are important for trimming and linearizing SimMechanics models (see Trimming Mechanical Models and Linearizing Mechanical Models in theAnalyzing Motion chapter) and for correcting simulation errors (see Troubleshooting Simulation Errors in the Running Mechanical Models chapter).
Your SimMechanics model must have at least one DoF to be valid. A free physical body has six DoFs: three translational and three rotational. But in a machine, connections between bodies by joints, constraints, and drivers, and motion actuation by joint and body actuators reduce the machine's independent DoFs to a smaller number. You also reduce a body's DoFs if you confine the machine's motion to one or two spatial dimensions.
A SimMechanics Body block has no DoFs. Connecting Joints to a Body adds DoFs to the machine. The joint primitives represent the Body's DoFs relative to other connected Bodies or Grounds. Connecting Constraint and Driver blocks to Bodies or motion-actuating joint primitives in Joints removes DoFs from the machine. A locked Joint Stiction Actuator also removes a DoF.
When you examine your model to identify and count its DoFs, be sure to open and inspect all its subsystems, including masked subsystems, to the bottom of the model's subsystem hierarchy.
Here is the formula for determining the number of independent DoFs your model has:
# of independent DoFs = # of body DoFs + # of primitive
DoFs -
# of motion restrictions
The following three steps define each term on the right side:
Calculate the number of body DoFs from the number of Body and Joint blocks in your model:
# of body DoFs = 6 * (number of Bodies - number of Joints)
If you have confined the machine to move in only two dimensions, replace the 6 by 3. If you have confined the machine to move in only one dimension, replace the 6 by 1.
Calculate the number of primitive DoFs by adding up the primitive DoFs from the Joint dialog boxes:
Count one for each prismatic (P) or revolute (R) primitive.
Count three for each spherical (S) primitive.
Count zero for each weld (W) primitive.
Do not count a primitive DoF that is motion-actuated by a Joint Actuator.
Calculate the number of motion restrictions by adding up the motion restrictions of each Constraint and Driver block and from each locked Joint Stiction Actuator. Different blocks from the Constraints & Drivers library impose different numbers of motion restrictions. Stiction actuators apply to individual joint primitives.
| Constraint Block | Restrictions | Driver Block | Restrictions |
|---|---|---|---|
| Gear | One | Angle | One |
| Parallel | Two | Distance | One |
| Point-Curve | Two | Linear | One |
| Velocity | One |
Be sure not to count redundant motion restrictions. These are restrictions that forbid the motion of joint primitives that could not move anyway even if the constraint were removed, because of how the joints are configured.
Example: A body is connected to a ground by a single prismatic. You place a constraint on the body that prevents it from moving perpendicularly to the prismatic axis. The body could not move in that direction even if you removed the constraint. So the constraint is redundant, and you would not count it as a motion restriction.
A Joint Stiction Actuator can remove or restore a DoF during a simulation. It is the only block that can change the number of independent DoFs after you start simulating. You must count an additional motion restriction during the period when a stiction-actuated primitive is locked. The primitive counts as another DoF if it is unlocked.
The mech_dpen model from the Demos library represents planar double pendulum motion actuated by a Joint Actuator.

The double pendulum has two rigid bodies, such as two rods, confined to move in two dimensions. Ignoring the Joint Actuator temporarily, there are two bodies, two joints, and two revolute primitives, and thus 3 * (2 - 2) + 2 = 2 independent DoFs. There are many ways to represent these two DoFs, but the two revolute primitives are the simplest way.
Including the Joint Actuator in the DoF count removes the revolute primitive in the Revolute block as an independent DoF. So this model actually only has one independent DoF, the revolute primitive in the Revolute1 block.
The example in Creating a Closed-Loop Mechanical Model in the Building and Visualizing Simple Machines chapter has four revolutes. You can establish that only 3 * (3 - 4) + 4 = 1 of these DoFs is actually independent and arrive at the same result obtained in the example.
![]() | Combining One- and Three-Dimensional Mechanical Elements | Running Mechanical Models | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |