SimMechanics    

Sensing Motion and Running the Model

You finish building your model by setting initial conditions and inserting Sensors.

Before you start a machine 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 Sensors.

You can sense motion in any model in two basic ways: sensing bodies or sensing joints. Here you sense Joint motion, using Joint Sensor blocks and feeding their Simulink signal outputs to Scope blocks.

Connecting the Joint Sensors

To sense the motion of the Revolute2 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:
    1. In the Connection parameters area in the middle, adjust the spinner menu Number of sensor/actuator ports to the value 1. Click OK.
    1. Connect this connector port to the open round connector port on Joint Sensor.
  3. Now repeat the same steps with Revolute3:
    1. Create one new connector port on Revolute 3.
    2. Connect this port to Joint Sensor1.
  4. Be sure to connect the outports > of the Sensor blocks to non-SimMechanics blocks. These ports are normal Simulink signals.

Graphical Plot of Joint Motion with a Scope Block

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, reset Number of axes to 2. Click OK. A second inport > 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 Sensor and Joint Sensor1:
    1. Note in the Measurements area, that 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. 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.

Your completed model should look similar to the mech_four_bar Demo model.

Configuring and Running the Simulation

Now take the final steps to prepare and start the model:

  1. In the model window Simulation menu, select Simulation parameters:
    1. In the Solver pane, change Absolute tolerance to 1e-6.
    2. Leave the other defaults and click OK.
  2. Now run the model by clicking Start Simulation in the Simulink toolbar. The four bar machine will fall under the influence of gravity.

Note some features of the simulation:

Animation

If you leave your visualization tool open at the time you start the simulation and select the Animate machine during simulation check box in the Visualization pane of the Mechanical Environment Settings dialog box, the visualized machine moves in step with the simulation.

You can now compare the animated motion with the Scope plots of the Revolute2 and Revolute3 angles.


  Configuring the Body Blocks Summary of Technical Vocabulary