|On this page…|
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.
At the MATLAB® command line, enter smnew. The SimMechanics™ block library and a new model open up.
In the model, delete all blocks except Solver Configuration, World Frame, and Mechanism Configuration.
Drag the custom Link block into the model.
This is the block you created in the tutorial Model Simple Link.
Drag the following SimMechanics blocks into the model.
|SimMechanics > Second Generation > Joints||Revolute Joint|
|SimMechanics > Second Generation > Body Elements||Solid|
Connect the blocks as shown in the figure.
In the Solid block dialog box, specify these parameters.
|Geometry > Dimensions||[4 4 4] (units of cm)|
|Graphic > Visual Properties > Color||[0.80 0.45 0]|
The Revolute Joint block sets the common Z axis of its base and follower frames as the rotation axis. To ensure that gravity acts in an orthogonal direction to the rotation axis, you must change the gravity vector—by default [0 0 -9.8] m/s^2. To specify gravity so it acts along the -Y axis:
Double-click the Mechanism Configuration block.
In Uniform Gravity > Gravity, enter [0 -9.81 0] and click OK..
You can sense motion between the joint frames using the joint block. To specify the angular position of the follower frame with respect to the base frame about the common Z axis:
Specify the initial angle between the joint base and follower port frames:
Double-click the Revolute Joint block.
Select State Targets > Specify Position Target.
In Value, enter -60 and click OK.
In the model window, press Ctrl+D. SimMechanics assembles the model in its initial configuration. Mechanics Explorer displays a 3-D view of this configuration with the Z axis pointing up. Since gravity acts along the -Y axis, it helps to change the view convention so the Y axis points up.
In Mechanics Explorer, set View convention to Y up (XY Front).
Click any of the view buttons to refresh the viewpoint. The figure shows the pendulum model from an isometric viewpoint.
Simulate the model. You can do this in the Simulink Editor menu bar by selecting Simulation > Run. Mechanics Explorer shows a 3-D animation of the simple pendulum.
Double-click the Scope block to analyze the time-varying revolute joint angle.
The figure shows the resulting plot in units of radians. Click the Autoscale button to fit the plot to the viewing area.