Model Simple Pendulum

Model Overview

The pendulum is the simplest mechanical system you can model. This system contains two rigid bodies, a link and a fixed pivot, connected by a revolute joint. In this tutorial, you model and simulate a pendulum using the custom link block you created in Model Simple Link. A Revolute Joint block provides the rotational degree of freedom between the link and the world frame.

Build Model

  1. At the MATLAB® command prompt, enter smnew. The Simscape™ Multibody™ block library and a model template with commonly used blocks open up.

  2. Delete blocks Simulink-PS Converter, PS-Simulink Converter, Scope, and Rigid Transform. You do not need them in this tutorial.

  3. Drag the Simple Link custom block you created in the tutorial Model Simple Link into the model.

  4. Drag a Revolute Joint block into the model. You can find this block in the Simscape > Multibody > Joints library. This block provides one rotational degree of freedom between its port frames.

  5. Connect the blocks as shown in the figure. The port orientation of the Revolute Joint block becomes important when you specify joint state targets, prescribe joint actuation inputs, or sense joint dynamic variables. The Revolute Joint block interprets each quantity as that applied to the follower frame with respect to the base frame, so switching the port connections can affect model assembly and simulation.

  6. In the Solid block dialog box, specify the following parameters. This block connects rigidly to the World frame and therefore has no effect on model dynamics. You can leave the inertia parameters in their default values.

    Geometry > Dimensions[4 4 4]Change to cm
    Graphic > Visual Properties > Color[0.80 0.45 0]Not applicable

Specify Gravity

The Revolute Joint block uses the common Z axis of the base and follower frames as the joint rotation axis. To ensure the pendulum oscillates under the effect of gravity, change the gravity vector so it no longer aligns with the Z axis. To do this, in the Mechanism Configuration block dialog box, set the Uniform Gravity > Gravity parameter to [0 -9.81 0].

Set Pendulum Starting Position

You can specify the desired joint angle using the State Targets menu in the Revolute Joint block dialog box. To do this, select State Targets > Position and enter the desired joint angle. For this tutorial, you can leave the angle in its default value, which corresponds to a horizontal pendulum starting position.

Configure Solver

  1. In the Simulink® Editor menu bar, select Simulation > Model Configuration Parameters.

  2. In the Solver tab, set the Solver parameter to ode15s (stiff/NDF). This solver is the recommended choice for physical models.

  3. Set Max step size to 0.01 and click OK. The small step size increases the simulation accuracy and produces a smoother animation in Mechanics Explorer. Small step sizes can have a detrimental effect on simulation speed but, in such a simple model, a value of 0.01 provides a good balance between simulation speed and accuracy.

Assemble Model

Update the block diagram. You can do this in the Simulink Editor menu bar, by selecting Simulation > Update diagram. Mechanics Explorer opens with a 3-D view of the model in its initial configuration.

In the Mechanics Explorer toolstrip, check that the View convention parameter is set to Y up (XY Front). This view convention ensures that gravity is vertically aligned on your screen. Select a standard view button to refresh the Mechanics Explorer display. The figure shows a front view of the model. Save the visualization settings by clicking the Save explorer configuration to model button .

Simulate Model

Run the simulation. You can do this through the Simulink Editor menu bar, by selecting Simulation > Run. Mechanics Explorer plays a physics-based animation of the pendulum model.

Save Model

Save the model in a convenient folder under the name simple_pendulum. You reuse this model in the tutorial Analyze Simple Pendulum.

Was this topic helpful?