SimMechanics    

Modeling Machines

In SimMechanics the term machine refers to a dynamic system that includes at least one rigid body. SimMechanics provides a library of Simulink blocks that allow you to create Simulink models of machines.

About SimMechanics Models

A SimMechanics model consists of a block diagram comprising one or more schematics, each of which is a set of connected blocks representing a machine. For example, the following model contains two schematics.

Comparison to Other Simulink Models

A SimMechanics model differs significantly from other Simulink models in how it represents a machine. An ordinary Simulink model represents the mathematics of a machine's motion, i.e., the algebraic and differential equations that predict the machine's future state from its present state. The mathematical model enables Simulink to simulate the machine. By contrast, a SimMechanics model represents the structure of a machine, the geometric and kinematic relationships of its component bodies. SimMechanics converts this structural representation to an internal, equivalent mathematical model. This saves you from having to develop the mathematical model yourself.

Creating a SimMechanics Model

You create a SimMechanics model in much the same way you create any other Simulink model. First, you create a Simulink model window. Then you drag instances of Simulink blocks from the Simulink block library into the window and draw lines to interconnect the blocks (see Connecting SimMechanics Blocks).

The SimMechanics block library provides the following blocks specifically for modeling machines:

You can use blocks from other Simulink libraries in SimMechanics models. For example, you can connect the output of SimMechanics Sensor blocks to Scope blocks from the Simulink Sinks library to display the forces and motions of your model's bodies and joints. Similarly, you can connect blocks from the Simulink Sources library to SimMechanics Driver blocks to specify relative motions of your machine's bodies.

Connecting SimMechanics Blocks

In general, you connect SimMechanics blocks in the same way you connect other Simulink blocks: by drawing lines between them. Significant differences exist, however, between connecting standard Simulink blocks and connecting SimMechanics blocks. The following sections discuss these differences.

Connection Lines

The lines that you draw between standard Simulink blocks, called signal lines, represent inputs to and outputs from the mathematical functions represented by the blocks. By contrast, the lines that you draw between SimMechanics blocks, called Connection Lines, represent physical connections and relationships among the bodies represented by the blocks. Also, you can draw Connection Lines only between specialized connection ports available only on SimMechanics blocks (see next section) and you cannot branch existing Connection Lines. Connection Lines appear as solid black when connected and as dashed red lines when either end is unconnected.

Connector Ports

Standard Simulink blocks have input and output ports. By contrast, most SimMechanics blocks contain only specialized Connector Ports that permit you to draw Connection Lines among SimMechanics blocks. SimMechanics Connector Ports are of two types: Body CS ports and general-purpose ports. Body CS ports appear on Body and Ground blocks and define connection points on a body or ground. Each is associated with a local coordinate system whose origin specifies the location of the associated connection point on the body.

General-purpose Connector Ports appear on Joint, Constraint, Driver, Sensor, and Actuator blocks. They permit you to connect Joints to Bodies and connect Sensors and Actuators to Joints, Constraints, and Drivers. General-purpose Connector Ports appear as circles on the block icon. The circle is unfilled if the port is unconnected and filled if the port is connected.

Interfacing SimMechanics Blocks to Simulink Blocks

SimMechanics Actuator blocks (see Modeling Actuators) contain standard Simulink input ports. Thus, you can connect standard Simulink blocks to a SimMechanics model via Actuator blocks. Similarly, SimMechanics Sensor blocks contain output ports (see Modeling Sensors). Thus, you can connect a SimMechanics model to Simulink blocks via Sensor blocks.

Setting SimMechanics Block Properties at the Command Line

You cannot use the Simulink set_param and get_param commands to set or get SimMechanics block parameters. Instead, you must set block parameters via the block dialog boxes. You can open the dialogs by double-clicking the block, or by right-clicking the block and selecting Open block.

Creating SimMechanics Subsystems

Large, complex block diagram models are often hard to analyze. Enclosing functionally-related groups of blocks in subsystems alleviates this difficulty and facilitates reuse of block groups in different models.

You can create subsystems containing SimMechanics blocks that you can connect to other SimMechanics blocks. You do this in two ways:

The Simulink User's Guide explains more about creating subsystems.

Creating a Subsystem Automatically

To create a SimMechanics subsystem automatically:

  1. Create the subsystem block diagram in your model window, leaving unconnected ports for external connections.

  2. Group-select the subsystem block diagram.
  3. Select the Make subsystem command from the Simulink window.

The command replaces the block diagram with a Subsystem block containing the selected block diagram. The command also creates and connects SimMechanics Connection Port blocks for the ports that you left unconnected in the block diagram. The Connection Port blocks in turn create Connector Port icons on the subsystem icon, enabling you to connect external SimMechanics blocks to the new subsystem.

Creating a Subsystem Manually

Sometimes you need to make a subsystem configured differently from an automatically created one. To create a SimMechanics subsystem manually:

  1. Drag a Subsystem block into your model window.
  2. Open the Subsystem block.
  3. Create the subsystem block diagram in the subsystem window.
  4. Drag a Connection Port block from the SimMechanics Utilities library into the subsystem window for each port that you want to be available externally.
  5. Connect the external Connector Ports to the Connection Port blocks.

Creating Custom SimMechanics Blocks with Masks

You can create your own SimMechanics blocks from subsystems, for example, a spring-loaded Joint block or a sphere Body block. To do this, create a block diagram that implements the functionality of your custom block, enclose the diagram as a subsystem, and add a mask (i.e., user interface) to the subsystem. To facilitate sharing your custom blocks across models or with other users, create a Simulink block library and add these masked subsystem blocks to the library. The Simulink User's Guide explains how to create custom blocks with masks.


  Modeling Mechanical Systems Modeling Bodies