2017-03-07

Linkages in MATLAB

Several years ago I was teaching a subject called (translating roughly) the Mechanics of Linkages. In that course the students would learn how to model the kinematics and dynamics of simple mechanisms.

It was done the old-school style: with chalk, blackboard, a ruler and a compass made out of a piece of string attached to the chalk. It was dirty work.

The students would draw the mechanisms in various positions at different times in their trajectories. It was not pointless. The drawing helps to understand the spatial relationships between the pieces of the moving mechanism. There are also a lot of simple graphic techniques that allow for computation of link velocities and accelerations. It is not merely a look back into the past, when there were no computers and all calculations had to be done by hand. The basic principles stand the test of time.

One of such simple mechanisms is shown in Fig. 1.
Fig. 1. A simple mechanical linkage.
The mechanism consists of 4 links: AC, CD, BD and DE. The driving motion is that provided by the link AC, which rotates with a constant angular velocity w.
The motions of individual points A, B, C, D and E are restricted by simple geometrical relationships. For example, the point E is attached to a slider - it is always only going to move left or right. The point C is always going to travel along the circle of radius |AC| around the point A. Similarly, D is always at a fixed distance from B. In order to find the location of the point D, you have to solve for the intersection of two circles: one with the center at C and the radius of |CD| and one located at B with the radius of |BD|.

The point E is located at the intersection of the circle ED and the horizontal line on which the slider rests.

I made a simple MATLAB script that not only solves the positions statically, but also animates the solution (see Fig. 2).
Fig. 2. Animating the linkage presented in Fig. 1.
As usual, the MATLAB scripts are to be found in the GitHub repository: https://github.com/dagothar/muw

The script that produces the solution presented in figures above is located in matlab/mech1.m. You are encouraged to experiment with different lengths of links. They are defined in the preamble.

The other m-files located in the directory are various MATLAB functions; for instance ccintersection.m contains a function that find the intersection points between two circles. The code for animation sits in a loop contained in the mech1.m file.

Note that to terminate the animation you most likely have to use CTRL+C key combination.


Moving on, I'd like to show you a different mechanism (see Fig. 3).
Fig. 3. Another kind of a mechanical linkage.
This time, I wanted to visualize the trajectory of the point F, which could be defined as the end effector of the device. Of course, for given link lengths the mechanism can still be placed in several configurations:
Fig. 4. Animating several possible solutions for the motion of the linkage presented in Fig. 3.

For some combinations of link lengths, the things get tricky:
Fig. 5. Animating the same mechanism as above. The selected link lengths result in singularities.
There now are several points at which the trajectories intersect. I leave you with a question: is it physically possible for the mechanism to jump between states at such intersections?

The script for the trajectory plotting of the second mechanism is located in matlab/mech2.m file.

No comments:

Post a Comment