www.kxcad.net Home > CAE Software Index > MATLAB Index >
|On this page…|
In this tutorial, you build a model of a planar, four bar mechanism and practice using some of the important SimMechanics features.
You are urged to work through Building a Simple Pendulum and Visualizing a Simple Pendulum in this chapter before proceeding with this section. Learn more about how to position and orient bodies in the Representing Motion chapter.
The machine consists of three moving bars of homogeneous steel, two connected at one end each to ground points and a third crossbar connecting the first two. The base acts as an immobile fourth bar, with a Ground at each end. The machine forms a single closed loop, and its motion is confined to two dimensions.
A Four Bar Mechanism
The elementary parts of the machine are the bodies, while the revolute joints are the idealized rotational degrees of freedom (DoFs) at each body-to-body contact point. The bodies and the joints expressing the bodies' relative motions must be translated into corresponding SimMechanics blocks. If you want, you can add elaborations such as Constraints, Drivers, Sensors, and Actuators to this essential block diagram.
Click here to open a detailed mechanical drawing of the four bar system.
The three moving bars are constrained to move in a plane. So each bar has two translational and one rotational DoFs, and the total number of machine DoFs, before counting constraints, is 3*(2+1) = 9.
Because the motion of the bars is constrained, however, not all of these nine DoFs are independent:
In two dimensions, each connection of a body with another body or with a ground point imposes two restrictions (one for each coordinate direction).
Such a restriction effectively eliminates one of the two body ends as independently moving points, because its motion is determined by the next body's end.
There are four such body-body or body-ground connections and therefore eight restrictions implicit in the machine's geometry.
The eight restrictions on the nine apparent DoFs reduce the DoFs to one, 9 - 8 = 1. There are four rotational DoFs between bars or between bars and grounds. But three of these are dependent. Specifying the state of one rotational DoF fully specifies the other three.
Open a new blank model window from the SimMechanics library. From the Bodies library of SimMechanics, drag in and drop a Machine Environment block and a Ground block. Enable the Ground's Machine Environment port and connect the environment block to the Ground.
First you need to configure the machine's mechanical settings. Open the Machine Environment block. The block dialog box appears.
Click the four tabs in succession to display each pane.
|Parameters||Controls general settings for mechanical simulations|
|Constraints||Sets constraint tolerances and how constraints are interpreted|
|Linearization||Controls how SimMechanics models are linearized with Simulink|
|Visualization||Chooses whether or not to visualize the machine|
Note some important features of this dialog box:
The Gravity vector field specifies the magnitude and direction of gravitational acceleration and sets the vertical or up-down direction.
The Linear and Angular assembly tolerance fields are also set here. Change Angular assembly tolerance to 1e-3 deg (degrees). (See Controlling Machine Assembly in the Running Mechanical Models chapter.)
Leave the other defaults, except Visualization. In that pane, select the Visualize machine check box.
Close the dialog by clicking OK.
Tip If possible, open the visualization window before building a model. With it, you can keep track of your model components and how they are connected, as well as correct mistakes.
To visualize the bodies as you build the machine, go to the SimMechanics node of the Configuration Parameters dialog:
Select the Update machine visualization on update diagram check box. If you want to animate the simulation later when you run the model, select the Animate machine during simulation check box as well. Click OK or Apply.
Then select Update Diagram from the Edit menu. The window opens.
In the SimMechanics menu, select Machine Display, then Ellipsoids.
As you add and change bodies in your model, you can update the machine display in your window at any time by updating your diagram.
In this set of steps, you create Bodies, position them, connect them with Joints, then configure the Body and Joint properties. The Body dialog boxes give you many ways to represent the same machine in the same physical state. This section explains one way.
Alternative, equivalent ways of configuring Bodies are discussed in Body Coordinate Systems.
The geometric and mass properties you need to specify for the Grounds and Bodies in this model are listed in the tables of the following two sections, Configuring the Ground and Joint Blocks and Configuring the Body Blocks.
Instead of typing the numerical values of these properties into the dialog boxes, you can load the variable set you need into the workspace by entering
at the MATLAB command line. The variable name for each property is given in the tables. Just enter the appropriate variable names in the appropriate fields as you come to them in the dialog boxes.
If you are working with online Help, you can click here to load the fourbar_data.mat file into the workspace.
Your model already has one environment block and one ground block. Assemble the full model with these steps:
In the block library, open the Bodies library. Drag and drop another Ground block and three Body blocks into the new model window. Close the Bodies library.
From the Joints library, drag and drop four Revolute blocks into the model window.
Rotate and connect the blocks in the pattern shown in the following figure or with an equivalent block diagram topology.
Use the block names shown in this figure for later consistency.
Connected Environment, Ground, Body, and Joint Blocks for the Four Bar
Block Diagram Topology. The topology of the block diagram is the connectivity of its elements. The elements are the Bodies and Grounds, connected by the Joints. Unlike the model of Building a Simple Pendulum, the four bar mechanism is a closed-loop machine. The two Ground blocks represent points on the same absolute, immobile body, and they close the loop of blocks. The simple pendulum has only one ground and does not close its block connections.
To maintain consistent Body motion direction, make sure the Body coordinate system (CS) port pairs on each Body follow the sequence CS1-CS2, CS1-CS2, etc., for each bar, moving from Ground_1 to Ground_2, from right to left, as shown. To make the Joints consistent with the Body motion, the base-follower pairs B-F, B-F, etc., should follow the same right-to-left sequence.
Now configure the Ground blocks with the data from the following table. Grounded coordinate systems (CSs) are automatically created.
This table summarizes the geometry of ground points.
Geometric Properties of the Four Bar Grounds
|Ground_1 point (m)||[ 0.433 0.04 0 ]||gpoint_1|
|Ground_2 point (m)||[-0.434 0.04 0 ]||gpoint_2|
The base of the mechanism has these measurements:
The base is horizontal, with length 86.7 cm.
Ground_1 represents the ground point 43.3 cm to the right of the World CS origin.
Ground_2 represents the ground point 43.4 cm to the left of the World CS origin.
The bottom revolutes are 4 cm above the origin (x-z) plane.
To represent ground points on the immobile base, you need to configure the Ground blocks. Use the variable names if you've loaded fourbar_data.mat into your workspace:
Open Ground_1 and enter [ 0.433 0.04 0 ] or gpoint_1 in the Location field.
Open Ground_2 and enter [-0.434 0.04 0 ] or gpoint_2 in the Location field.
Leave both pull-down menus for units at default m (meters).
The three nongrounded bars move in the plane of your screen (x-y plane), so you need to make all the Revolute axes the z-axis (out of the screen):
Open each Revolute's dialog box in turn. In its Parameters area, note on the Axes pane that the z-axis is the default: Axis of Action is set to [0 0 1] in each, relative to Reference CS WORLD. Leave these defaults.
A Revolute block contains only one primitive joint, a single revolute DoF. So the Primitive is automatically revolute. Its name within the block is R1.
Leave these Revolute joint block defaults and ignore the Advanced tab.
The Body CS and base-follower joint directionality should be set up as shown in the block diagram of the figure Connected Environment, Ground, Body, and Joint Blocks for the Four Bar. In the Connection parameters area, the default Joint directionality for each Revolute automatically follows the right-to-left sequence of Grounded and Body CSs:
Revolute1: Base to follower: GND@Gound_1 to CS1@Bar1
Revolute2: Base to follower: CS2@Bar1 to CS1@Bar2
Revolute3: Base to follower: CS2@Bar2 to CS1@Bar3
Revolute4: Base to follower: CS2@Bar3 to GND@Ground_2
In this Joint directionality convention,
At each Joint, the leftward Body moves relative to the rightward Body.
The rotation axis points in the +z direction (out of the screen).
Looking at the mechanism from the front in the figure, A Four Bar Mechanism, the positive rotational sense is counterclockwise. All Joint Sensor and Actuator data are interpreted in this sense.
Setting the Body properties is similar for each bar, but with different parameter values entered into each dialog box:
Lengths and orientations
Center of gravity (CG) positions
Body coordinate systems (CSs)
In contrast to the first tutorial, where you specify Body CS properties with respect to the absolute World CS, in this tutorial, you specify Body CS origins on the bars in relative coordinates, displacing Bar1's CS1 relative to Ground_1, Bar2's CS1 relative to Bar1, and so on, around the machine loop. You can refer the definition of a Body CS to three types of coordinate systems:
To the other Body CSs on the same Body
To the Adjoining CS (the coordinate system on a neighboring body or ground directly connected by a Joint to the selected Body CS).
The components of the displacement vectors for each Body CS origin continue to be oriented with respect to the World axes. The rotation of each Body's CG CS axes is also with respect to the World axes, in the Euler X-Y-Z convention.
The following three tables summarize the body properties for the three bars.
Bar1 Mass and Body CS Data (MKS Units)
|Inertia tensor||[1.07e-3 0 0;|
0 0.143 0;
0 0 0.143]
|CG Origin||[0.03 0.282 0] from World in axes of CS1||cg_1|
|CS1 Origin||[0 0 0] from World in axes of Adjoining||cs1_1|
|CS2 Origin||[0.063 0.597 0] from World in axes of CS1||cs2_1|
|CG Orientation||[0 0 83.1] from WORLD in convention Euler X-Y-Z||orientcg_1|
Bar2 Mass and Body CS Data (MKS Units)
|Inertia tensor||[1.8e-3 0 0;|
0 0.678 0;
0 0 0.678]
|CG Origin||[-0.427 0.242 0] from World in axes of CS1||cg_2|
|CS1 Origin||[0 0 0] from World in axes of Adjoining||cs1_2|
|CS2 Origin||[-0.87 0.493 0] from World in axes of CS1||cs2_2|
|CG Orientation||[0 0 29.5] from WORLD in convention Euler X-Y-Z||orientcg_2|
Bar3 Mass and Body CS Data (MKS Units)
|Inertia tensor||[2.06e-4 0 0;|
0 1.1e-3 0;
0 0 1.1e-3]
|CG Origin||[-0.027 -0.048 0] from World in axes of CS1||cg_3|
|CS1 Origin||[0 0 0] from World in axes of Adjoining||cs1_3|
|CS2 Origin||[0 0 0] from World in axes of Adjoining||cs2_3|
|CG Orientation||[0 0 60] from World in convention Euler X-Y-Z||orientcg_3|
Here are the common steps for configuring the Body dialogs of all three bars. See the three preceding tables for Body dialog box mass property (mass and inertia tensor) entries. The units are MKS: lengths in meters (m), masses in kilograms (kg), and inertia tensors in kilogram-meters2 (kg-m2).
Open all three Body dialogs for each bar. Enter the mass properties for each from the tables in the Mass and Inertia fields.
Now work in the Body coordinate systems area, the Position pane:
Set the Translated from Origin of menu, for each Body CS on each bar, to WORLD.
Leave units as default m (meters).
Set the Body CS properties for each Body CS on each bar from the data of the preceding tables:
Enter the Body CS origin position data for CG, CS1, and CS2 on each bar from the tables or from the corresponding MAT-file variables.
Set the Components in Axes of menu entries for each Body CS on each bar according to the values in the tables.
Select the Orientation pane by clicking its tab:
Enter the Orientation Vector for the CG on each bar from the tables or from the corresponding MAT-file variables.
Choose WORLD for Relative CS in each case.
Leave the other fields in their default values.
The front view of the four bar mechanism, with the bodies rendered as equivalent ellipsoids, looks like this:
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 Kinematics and the Machine's State of Motion and Modeling Actuators.
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.
Caution Because they are immobile, ground points cannot be moved, nor do they have any motion to measure.
Therefore, you cannot connect Ground blocks to Actuator or Sensor blocks.
To sense the motion of the Revolute2 and Revolute3 blocks,
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.
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:
In the Connection parameters area in the middle, adjust the spinner menu Number of sensor/actuator ports to the value 1. Click OK.
A new connector port appears on Revolute2.
Connect this connector port to the open round connector port on Joint Sensor.
Now repeat the same steps with Revolute3:
Create one new connector port on Revolute 3.
Connect this port to Joint Sensor1.
Be sure to connect the outports > of the Sensor blocks to a Simulink Sink block. These outports are normal Simulink signals.
Here you can view the Joint Sensor measurements of Revolute2 and Revolute3's motions using a Scope block from the Simulink Sinks library:
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."
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.
Expand the scope window for ease of viewing.
Connect the Joint Sensor and Joint Sensor1 block outports > to the Angle block inports >.
Open Joint Sensor and Joint Sensor1:
In the Measurements area, 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.
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.
Caution Sensor and Actuator blocks are the only blocks that can connect SimMechanics blocks to normal Simulink blocks.
Now take the final steps to prepare and start the model:
In the model window Simulation menu, select Configuration Parameters:
In the Solver node, change Absolute tolerance to 1e-6.
Leave the other defaults and click OK.
Now run the model by clicking Start in the Simulink toolbar. The four bar machine will fall under the influence of gravity.
Note some features of the simulation:
In this example, the machine starts from rest, with the initial velocities at zero. Thus the initial state of the four bar machine is just the geometric state that you set up in the immediately preceding section, Setting Up the Block Diagram.
The assembly at first falls over to the right, and the Revolute2 angle decreases.
Bar3 turns all the way around, and Bar2 and Bar1 turn back to the left. The Revolute2 angle reverses direction. Revolute3 sweeps through a complete turn. Angles are mapped to the interval (-180o,+180o] and exhibit discontinuities.
The motion repeats periodically, as there is no friction.
If you leave your visualization window open at the time you start the simulation and select the Animate machine during simulation check box in the SimMechanics node of the Configuration Parameters dialog, 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.
If you are connected to the Internet and have an AVI-compatible media streaming application installed on your system, click here to play a recorded animation of the mech_four_bar demo. The animation takes a short time to download and start.
The four bar system is also discussed in the context of advanced SimMechanics features and methods: Modeling Joints, Checking Model Validity, Finding Forces from Motions, Trimming Mechanical Models, and Linearizing Mechanical Models.
|Visualizing a Simple Pendulum||Representing Motion|