Products & Services Solutions Academia Support User Community Company

Learn more about SimMechanics   

Creating a Simple Mechanical Model

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. We strongly recommend that users work through this tutorial first before moving on to the next section, Visualizing a Simple Mechanical Model.

A Simple Pendulum: A Swinging Steel Rod

Opening the SimMechanics Block Library

Following one of the ways described earlier in the Accessing the Libraries section in this chapter, open the SimMechanics library. From there, open a new, empty Simulink model window.

The World Coordinate System and Gravity

Before you configure a Ground block, you need to understand the internally defined fixed or "absolute" SimMechanics coordinate system (CS) called World. The World CS sits at rest in the inertial reference frame also called World. The World CS has an origin (0,0,0) and a triad of right-handed, orthogonal coordinate axes.

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 in Running Mechanical Models for displaying global mechanical properties of SimMechanics models.

Configuring the Ground Block

World serves as the single absolute CS that defines all other CSs. But you can create additional 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.

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:

  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.

Properties of Grounds

At every ground point, a Grounded CS is automatically created:

Configuring the Body Block

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 translate the components of a real machine into block representations. This section explains how you use a Body block to represent each rigid body in your system:

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 gravity, its orientation, and the coordinate systems attached to the body. The Representing Motion chapter 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, its position and orientation in space, and its attached Body coordinate systems (CSs).

The mass properties include the mass and inertia tensor. The mass is a real, positive scalar. The inertia tensor is a real, symmetric 3-by-3 matrix. It does not have to be diagonal.

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 Block.

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.

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 geometric center of the rod. Take the CG CS axes to be parallel to the World 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 Izz controls the swinging about the z-axis, in the x-y plane. The inertia tensor is always evaluated with the origin of coordinates at the CG. For a rod of length L = 1 m and radius r = 1 cm, the mass m = ρπr2L = 2490 gm (grams), and the inertia tensor I reads

in gm-cm2 (gram-centimeters2). The x-axis is the cylinder's symmetry axis. Thus Iyy = 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.

Body Data for the Simple Pendulum

PropertyValue
Mass (gm)2490
Inertia tensor (kg-m2)[1.25e-4 0 0;
0 0.208 0;
0 0 0.208]
CG Position/Origin (m)[ 2.5 4 5 ]
CS1 Origin (m)[ 3 4 5 ]

Configuring the Body Dialog

Take the steps to configuring a Body block in several stages.

Equivalent Ellipsoid of Simple Pendulum with Body Coordinate Systems

Adding the Body Block.   To start working with the Body block:

  1. Open the Bodies library in the SimMechanics library.

  2. Drag and drop a Body block into your model window.

  3. Open the Body block dialog box. Note the two main areas you need to 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.

Specifying the Body's Mass Properties.   Now enter the body's mass and inertia tensor:

  1. Use the data from the table Body Data for the Simple Pendulum.

    In the Mass field, enter 2490 and change the units to g (grams).

  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-m2.

Specifying Body Coordinate Systems (Position).   Enter the translational position of the body and its Body CS origins in space:

  1. Use the data from the table Body Data for the Simple Pendulum, 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 by selecting its line in the Body CS list and clicking the Delete button in the Body CS controls.

    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 [0 0 0]

    • The Adjoining CS on the neighboring body, in this case the Grounded CS origin at [3 4 5]

  3. Specify the CG and CS1 origins relative to World:

    1. In the pull-down menu under Translated from Origin of, choose World for both coordinate systems, CG and CS1.

    2. 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 World for both CSs. Leave the units as m (meters).

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, the CS1 and CG axes are oriented parallel to the World 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 [0 0 0] and the Specified Using Convention at default Euler X-Y-Z. Close the Body dialog.

Configuring the Joint Block

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:

One (but not both) of the members of such a pair of Bodies can be a Ground. The other member Body 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 specific 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.

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 Joint.

Choosing a Revolute Joint for the Simple Pendulum

In spite of the complexity of the concepts implicit 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.

A Simple Pendulum Connected to Ground by a Revolute

Configuring the Revolute Joint Block.   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.

  3. Rotate the Revolute block so that you can connect the base (B) side of the Joint to the Ground block and the follower (F) side of the Joint to the Body block. Make the two connections.

  4. Open the Revolute dialog box. In the Parameters area, on the Axes tab, configure the rotation axis to the World z-axis:

    1. Enter [0 0 1] under Axis of Action [x y z].

    2. Leave the Reference CS at World.

    3. Ignore the Advanced tab.

    Note several important things:

    • Under Connection parameters, the Current 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 parameters, the Current 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.

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

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. Open the Revolute 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 Sensor. 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 your model window. From the Signal Routing library, drag and drop a Mux block as well. Connect the Simulink outports > on the Joint Sensor block to the Scope and XY Graph blocks as shown.

    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 your model for future reference as spen.mdl.

You now need to configure the global parameters of your model before you can run 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.

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

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

    If you want the simulation to continue running without stopping, change Stop time to inf. The pendulum period is approximately 1.6 seconds.

  3. Close the Configuration Parameters dialog box.

A special feature of SimMechanics models is the Machine Environment block.

  1. Open your block diagram's Machine Environment block dialog.

    Note the default Gravity vector, [0 -9.81 0] m/s2, which points in the -y direction, as shown in the figure Equivalent Ellipsoid of Simple Pendulum with Body Coordinate Systems. The gravitational acceleration g = 9.81 m/s2.

  2. Close the Machine Environment dialog.

Starting 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.

    Parameter Value
    x-min0
    x-max200
    y-min-500
    y-max500

    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.

    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:

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

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.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS