MATLAB Posiotion Analysis
MATLAB Posiotion Analysis
Contents
2 Position Analysis
2.1 Absolute Cartesian Method . . . . . . . . . .
2.2 Slider-Crank (R-RRT) Mechanism . . . . . . .
2.3 R-RRR-RRT Mechanism . . . . . . . . . . . .
2.4 R-RTR-RTR Mechanism . . . . . . . . . . . .
2.5 R-RTR-RTR Mechanism - Complete Rotation
2.6 Path of a Point on a Link with
General Plane Motion . . . . . . . . . . . . .
2.7 Creating a Movie . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
. 1
. 2
. 6
. 12
. 16
. . . . . . . . . 19
. . . . . . . . . 20
2
2.1
Position Analysis
Absolute Cartesian Method
(2.1)
yB yA
.
xB xA
(2.2)
Let n be the intercept of AB with the vertical axis Oy. Using the slope m
and the intercept n, the equation of the straight link, in the plane, is
y = m x + n,
(2.3)
(2.4)
where p is the distance from the origin O to the sliding line (). The position
function for the joint A(xA , yA ) is
xA cos yA sin p = d,
(2.5)
where d is the distance from A to the sliding line. The relation between the
joint A and a point B on the sliding direction, B () (the symbol means
belongs to), is
(xA xB ) sin (yA yB ) cos = d,
(2.6)
.
2
If A x+B y +C = 0 is the linear equation of the line () then the distance
d is, Fig. 2.1(b)
|A xA + B yA + C|
d=
.
(2.7)
A2 + B 2
where = +
2.2
The R-RRT (slider-crank) mechanism shown in Fig. 2.2(a) has the dimensions: AB = 0.1 m and BC = 1 m. The driver link 1 makes an angle
= 1 = 45 with the horizontal axis. Find the positions of the joints and
the angles of the links with the horizontal axis.
Solution
The Matlab program starts with the statements
clear % clears all variables from the workspace
clc % clears the command window and homes the cursor
close all % closes all the open figure windows
The Matlab commands for the input data are
AB=0.5;
BC=1.;
The angle of the driver link 1 with the horizontal axis = 45 . The
Matlab command for the input angle is
phi=pi/4;
where pi has a numerical value approximately equal to 3.14159.
Position of joint A
A Cartesian reference frame xOy is selected. The joint A is in the origin
of the reference frame, that is, A O,
xA = 0, yA = 0,
or in Matlab
xA=0; yB=0;
Position of joint B
The unknowns are the coordinates of the joint B, xB and yB . Because
the joint A is fixed and the angle is known, the coordinates of the joint B
are computed from the following expressions
xB = AB cos = (0.5) cos 45 = 0.353553 m,
yB = AB sin = (0.5) sin 45 = 0.353553 m.
(2.8)
(2.9)
solve(eqn1,eqn2,...,eqnN,var1,var2,...varN)
attempts to solve an equation or set of equations eqn1,eqn2,...,eqnN
for the variables eqnN,var1,var2,...varN. The set of equations
are symbolic expressions or strings specifying equations.
For the R-RRT mechanism
solC=solve(eqnC,xCsol);
Because it is a quadratic equation two solutions are found for the position
of C. The two solutions are given in a vector form: solC is a vector with
two components solC(1) and solC(2). To obtain the numerical solutions
the eval command has to be used
xC1=eval(solC(1));
xC2=eval(solC(2));
The command eval(s), where s is a string, executes the string as an
expression or statement.
These two solutions for xC are located at the intersection of the horizontal
axis 0x with the circle centered in B and radius CB, as shown in Fig. 2.2(b),
and they have the following numerical values:
xC1 = 1.2890 m and xC2 = 0.5819 m.
To determine the correct position of the joint C for the mechanism, an additional condition is needed. For the first quadrant, 0 90 , the condition
is xC > xB.
This condition with Matlab is
if xC1 > xB xC = xC1; else xC = xC2; end
The general form of the if statement is
if expression statements else statements end
The x-coordinate of the joint C ise xC = xC1 = 1.2890 m.
The angle of the link 2 (link BC) with the horizontal is
2 = arctan
yB yC
,
xB xC
or in Matlab
phi2 = atan((yB-yC)/(xB-xC));
The statement atan(s) is the arctangent of the elements of s.
The numerical solutions for B, C, and 2 are printed using the statements
fprintf(xB =
fprintf(yB =
fprintf(xC =
fprintf(yC =
fprintf(phi2
0.353553 (m)
0.353553 (m)
1.06821 (m)
1.28897 (m)
= -20.7048 (degrees)
The mechanism is plotted with the help of the command plotf. The
statement plotf(x,y,c) plots vector x versus vector x, and c is a character
string.
For the R-RRT mechanism two straight lines AB and BC are plotted
plot( [xA,xB],[yA,yB],r-o, [xB,xC],[yB,yC],b-o ),...
The line AB is a red (r red ), solid line (- solid), with a circle (o circle)
at each data point and the line BC is a blue (b blue ), solid line with a circle
at each data point and the. The graphic of the mechanism obtained with
Matlab is shown in Fig. 2.3.
The x-axis and y-axis are labeled using the commands
xlabel(x (m)),...
ylabel(y (m)),...
and a title is added
title(positions for \phi = 45 (deg)),...
On the figure the joints A, B, and C are identified with the statements
text(xA,yA, A),...
text(xB,yB, B),...
text(xC,yC, C),...
axis([-0.2 1.4 -0.2 1.4]),...
grid
The commas and ellipses (...) after the command are used to execute
the commands together. Otherwise, the data will be plotted, then the labels
will be added and the data replotted, and so on.
The statement axis([xMIN xMAX yMIN yMAX]) sets scaling for the x and
y axes on the current plot. To improve the graph a background grid was
added with the command grid.
The Matlab program for the positions is given in Program 2.1.
2.3
R-RRR-RRT Mechanism
(2.10)
(2.11)
or
(2.12)
yC = yC1 = 0.465 m.
(2.13)
(2.14)
or
(xE + 0.069)2 + (yE 0.465)2 = 0.2302 .
The joints D, C and E are located on the same straight element DE. For
these joints, the following equation can be written
yD yC
yE yC
=
,
xD xC
xE xC
or
(2.15)
0.450 0.465
yE 0.465
=
.
0.300 + 0.069
xE + 0.069
Equations (2.14) and (2.15) form a system from which the coordinates of
the joint E can be computed. Two solutions are obtained, Fig. 2.6, and the
numerical values are
xE1 = 0.299 m, yE1 = 0.474 m,
xE2 = 0.160 m, yE2 = 0.455 m.
(2.16)
10
(2.17)
or
(0.370 + 0.300)2 + (yF 0.475)2 = 0.2302 ,
The solutions of Eq. (2.17) are
yF1 = 0.256 m,
yF2 = 0.693 m.
(2.18)
The points F1 and F2 are the intersections between the circle of radius EF
(centered at E) and the vertical line with x = xF , Fig. 2.7. For the mechanism depicted in Fig. 2.4, with = /4 the y coordinate of the joint F should
be smaller that the y coordinate of the joint E, yF < yE . The y coordinate
of the joint F is
yF = yF1 = 0.256 m.
(2.19)
The Matlab program for the position of F is
xF = - Lc ;
eqnF = ( xF - xE )^2 + ( yFsol - yE )^2 = EF^2 ;
solF = solve(eqnF,yFsol);
yFpositions=eval(solF);
yF1 = yFpositions(1); yF2 = yFpositions(2);
if yF1 < yE
yF=yF1;
else
yF=yF2;
end
rF = [xF yF 0];
The angles of the links 2, 3, and 4 with the horizontal are
2 = arctan
yD yC
yF yE
yB yC
, 3 = arctan
, 4 = arctan
,
xB xC
xD xC
xF xE
11
and in Matlab
phi2 = atan((yB-yC)/(xB-xC));
phi3 = atan((yD-yC)/(xD-xC));
phi4 = atan((yF-yE)/(xF-xE));
The results are printed using the statements
fprintf(rA =
fprintf(rD =
fprintf(rB =
fprintf(rC =
fprintf(rE =
fprintf(rF =
fprintf(phi2
fprintf(phi3
fprintf(phi4
[
[
[
[
[
[
=
=
=
%g, %g, %g ]
%g, %g, %g ]
%g, %g, %g ]
%g, %g, %g ]
%g, %g, %g ]
%g, %g, %g ]
%g (degrees)
%g (degrees)
%g (degrees)
12
Program 2.2.
2.4
R-RTR-RTR Mechanism
%(m)
% (m)
(2.20)
and rB = xB + yB .
The Matlab statements for the positions of the joints A, C, E, and B are
xA = 0 ; yA = 0 ; rA = [xA yA 0] ;
% Position of A
13
xC = 0 ; yC = AC ; rC = [xC yC 0] ; % Position of C
xE = 0 ; yE = -AE ; rE = [xE yE 0] ;
% Position of E
xB=AB*cos(phi); yB=AB*sin(phi); rB=[xB yB 0]; % Position of B
Position of joint D
The unknowns are the coordinates of the joint D, xD and yD . The length of
the segment CD is constant:
(xD xC )2 + (yD yC )2 = CD2 ,
(2.21)
or
(xD 0)2 + (yD 0.060)2 = 0.1502 .
The points B, C, and D are on the same straight line with the slope
m=
(yB yC )
(yD yC )
=
,
(xB xC )
(xD xC )
(2.22)
or
(0.070 0)
(yD 0)
=
.
(0.121 0.060)
(xD 0.060)
Equations (2.21) and (2.22) form a system from which the coordinates of the
joint D can be computed. To solve the system of equations the Matlab
statement solve will be used
eqnD1 = ( xDsol - xC )^2 + ( yDsol - yC )^2 = CD^2 ;
eqnD2 = (yB - yC)/(xB - xC) = (yDsol - yC)/(xDsol - xC);
solD = solve(eqnD1, eqnD2, xDsol, yDsol);
xDpositions = eval(solD.xDsol);
yDpositions = eval(solD.yDsol);
xD1 = xDpositions(1); % first component of the vector xDpositions
xD2 = xDpositions(2); % second component of the vector xDpositions
yD1 = yDpositions(1); % first component of the vector yDpositions
yD2 = yDpositions(2); % second component of the vector yDpositions
These solutions D1 and D2 are located at the intersection of the line BC
with the circle centered in C and radius CD (Fig. 2.10), and they have the
following numerical values:
xD1 = 0.149 m, yD1 = 0.047 m,
xD2 = 0.149 m, yD2 = 0.072 m.
14
To determine the correct position of the joint D for the mechanism, an additional condition is needed. For the first quadrant, 0 90 , the condition
is xD xC .
This condition with Matlab is given by
if xD1 <= xC
xD = xD1; yD=yD1;
else
xD = xD2; yD=yD2;
end
rD = [xD yD 0]; % Position of D
Because xC = 0, the coordinates of the joint D are
xD = xD1 = 0.149 m and yD = yD1 = 0.047 m.
The angles of the links 2, 3, and 4 with the horizontal are
2 = arctan
yD yE
yB yC
, 3 = 2 , 4 = arctan
+ , 5 = 4 ,
xB xC
xD xE
and in Matlab
phi2
phi3
phi4
phi5
=
=
=
=
atan((yB-yC)/(xB-xC));
phi2;
atan((yD-yE)/(xD-xE))+pi;
phi4;
=
=
=
=
xD + DF*cos(phi3) ; yF = yD + DF*sin(phi3) ;
[xF yF 0]; % Position vector of F
xE + EG*cos(phi5) ; yG = yE + EG*sin(phi5) ;
[xG yG 0]; % Position vector of G
[
[
[
=
=
[
[
15
2.5
16
For a complete rotation of the driver link AB, 0 360 , a step angle
of 60 is selected. To calculate the position analysis for a complete cycle the
Matlab statement for var=startval:step:endval, statement end is used. It
repeatedly evaluates statement in a loop. The counter variable of the loop
is var. At the start the variable is initialized to value startval and is incremented (or decremented when step is negative) by the value step for each
iteration. The statement is repeated until var has incremented to the value
endval. For the considered mechanism the following applies
for phi=0:pi/3:2*pi, Program block, end;
Method I - constraint conditions
Method I uses constraint conditions for the mechanism for each quadrant.
For the mechanism, there are several conditions for the position of the joint
D.
For the angle located in the first quadrant 0 90 (Fig. 2.10), and
the fourth quadrant 270 360 (Fig. 2.14), the following relation exists
between xD and xC :
xD xC = 0.
For the angle located in the second quadrant 90 < 180 (Fig. 2.12),
and the third quadrant 180 < < 270 (Fig. 2.13), the following relation
exists between xD and xC :
xD xC = 0.
The following Matlab commands are used to determine the correct position of the joint D for all four quadrants
if (phi>=0 && phi<=pi/2)||(phi >= 3*pi/2 && phi<=2*pi)
if xD1 <= xC xD = xD1; yD=yD1; else xD = xD2; yD=yD2; end
else
if xD1 >= xC xD = xD1; yD=yD1; else xD = xD2; yD=yD2; end
end
where || is the logical OR function.
17
The Matlab program and the results for a complete rotation of the
driver link using method I is given in Program 2.3. The graphic of the mechanism for a complete rotation of the driver link is given in Fig. 2.15. To
simplify the graphic the points E and G are not shown on the figure.
Method II - Euclidian distance function
Another position analysis method for a complete rotation of the driver
link uses constraint conditions only for the initial value of the angle . Next
for the mechanism, the correct position of the joint D is calculated using a
simple function, the Euclidian distance between two points P and Q:
d=
(xP xQ )2 + (yP yQ )2 .
(2.23)
18
increment=0;
% at the initial moment phi=0 => increment = 0
step=pi/6;
% the step has to be small for this method
for phi=0:step:2*pi,
...
if increment == 0
if xD1 <= xC xD = xD1; yD=yD1; else xD = xD2; yD=yD2; end
else
dist1 = Dist(xD1,yD1,xDold,yDold);
dist2 = Dist(xD2,yD2,xDold,yDold);
if dist1 < dist2 xD = xD1; yD=yD1; else xD = xD2; yD=yD2; end
end
xDold=xD;
yDold=yD;
increment=increment+1;
...
end
At the beginning of the rotation the driver link makes an angle phi=0
with the horizontal and the value of counter increment is 0. The Matlab
statement
increment=increment+1;
specifies that 1 is to be added to the value in increment and the result
stored back in increment. The value increment should be incremented by
1.
With this algorithm the correct solution is selected using just one constraint relation for the initial step and then, automatically, the problem is
solved. In this way it is not necessary to have different constraints for different quadrants.
For the Euclidian distance method the selection the step of the angle is
very important. If the step of the angle has a large value the method might
give wrong answers and that is why it is important to check the graphic of
the mechanism.
The Matlab program and the results for a complete rotation of the
driver link using the second method is given in Program 2.5. The graph of
the mechanism for a complete rotation of the driver link (the step of the
angle is 30 ) is given in Fig. 2.17 (the points E and G are not shown).
2.6
19
R-RRT mechanism
The mechanism shown in Fig. 2.18(a) has AB = 0.5 m and BC = 1 m.
The link 2 (connecting rod BC) has a general plane motion: translation along
x-axis, translation along y-axis, and rotation about z-axis. The mass center
of link 2 is located at C2 . Determine the path of point C2 for a complete
rotation of the driver link 1.
Solution
The coordinates of the joint B are: xB = AB cos and yB = AB sin ,
where
0 360 . The coordinates of the joint C are: xC = xB +
q
BC 2 yB2 and yC = 0. The mass center of the link 2 is the midpoint
of the segment BC
xC 2 =
xB + xC
2
and yC2 =
yB + yC
.
2
20
2.7
Creating a Movie
The R-RRR-RRT mechanism shown in Fig. 2.4 has the dimensions given at
subsection 2.3. This example illustrates the use of movies to visualize the
positions of the mechanism for 0 360 .
The first step is to create axis the same size as the ones that will display
the movie The axis command is
axis([-0.3 0.3 -0.3 0.3])
The statement, moviein is used to create a matrix large enough to hold
the 6 frames that compose the movie of the mechanism for 6 values of the
driver angle .
M = moviein(6);
The axis statement must precede the M = moviein(6); statement to
ensure M is initialized to the correct dimensions. Next the command,
set(gca,NextPlot,replacechildren)
is employed to prevent the plot function from resetting the axis shaping
to axis normal each time it is called.
21