0% found this document useful (0 votes)
30 views19 pages

1.4 - Exam-1 - Mehrab - Q 2, 5, 7

The document contains MATLAB code for solving inverse kinematics problems. It defines homogeneous transformation matrices to relate the orientation of each link to the previous link. The code then calculates the transformation matrix relating the end effector to the base link. It also shows code for calculating joint angles given end effector position for different cases.

Uploaded by

Talash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views19 pages

1.4 - Exam-1 - Mehrab - Q 2, 5, 7

The document contains MATLAB code for solving inverse kinematics problems. It defines homogeneous transformation matrices to relate the orientation of each link to the previous link. The code then calculates the transformation matrix relating the end effector to the base link. It also shows code for calculating joint angles given end effector position for different cases.

Uploaded by

Talash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

MATLAB SCREENSHOT FOR CODING OF PROBLEM 2

MATLAB CODE FOR PROBLEM 2

% Code for solution to Problem number 7: inverse kinematics


% Mehrab Masayeed Habib L20495918
clc
clear all
close all
syms x y R;%we use x to denote for angle theta and use y to denote for angle fi
A1=[1 0 0; 0 cos(x) -sin(x); 0 sin(x) cos(x)]
A2=[cos(y) 0 sin(y); 0 1 0; -sin(y) 0 cos(y)]
A3=[0 -1 0; 1 0 0; 0 0 1]
A4=[1 0 0; 0 cos(y) sin(y); 0 -sin(y) cos(y)]
A5=[1 0 0; 0 cos(x) sin(x); 0 -sin(x) cos(x)]
R=A1*A2*A3*A4*A5;
disp(R)

OUTPUT:
A1 =

[1, 0, 0]
[0, cos(x), -sin(x)]
[0, sin(x), cos(x)]

A2 =

[ cos(y), 0, sin(y)]
[ 0, 1, 0]
[-sin(y), 0, cos(y)]

A3 =

0 -1 0
1 0 0
0 0 1

A4 =

[1, 0, 0]
[0, cos(y), sin(y)]
[0, -sin(y), cos(y)]

A5 =

[1, 0, 0]
[0, cos(x), sin(x)]
[0, -sin(x), cos(x)]

[ 0, -cos(x)*(cos(y)^2 + sin(y)^2), -sin(x)*(cos(y)^2


+ sin(y)^2)]
[cos(x), sin(x)*(sin(x)*cos(y)^2 + sin(x)*sin(y)^2), -cos(x)*(sin(x)*cos(y)^2 +
sin(x)*sin(y)^2)]
[sin(x), -sin(x)*(cos(x)*cos(y)^2 + cos(x)*sin(y)^2), cos(x)*(cos(x)*cos(y)^2 +
cos(x)*sin(y)^2)]
SCREENSHOT FOR MATLAB CODING OF PROBLEM 5

MATLAB CODE FOR PROBLEM 5:

% Code for solution to Problem number 5


% Mehrab Masayeed Habib L20495918
clc
clear all
close all
syms T c1 s1 c3 s3 c4 s4 c5 s5 d2 d4 a5; % Here, cos(θ1) is denoted by c1,sin(θ1) is
denoted by s1 and the like.
A1=[c1 0 -s1 0; s1 0 c1 0; 0 -1 0 0; 0 0 0 1] %Homogeneous transformation matrics for
link 1
A2=[1 0 0 0; 0 0 -1 0; 0 1 0 d2; 0 0 0 1] %Homogeneous transformation matrics for
link 2
A3=[c3 0 -s3 0; s3 0 c3 0; 0 -1 0 0; 0 0 0 1] %Homogeneous transformation matrics for
link 3
A4=[c4 0 s4 0; s4 0 -c4 0; 0 1 0 d4; 0 0 0 1] %Homogeneous transformation matrics for
link 4
A5=[c5 -s5 0 a5*c5; s5 c5 0 a5*s5; 0 0 1 0; 0 0 0 1] %Homogeneous transformation
matrics for link 5
T=A1*A2*A3*A4*A5;
disp(T)
Output:
A1 =

[c1, 0, -s1, 0]
[s1, 0, c1, 0]
[ 0, -1, 0, 0]
[ 0, 0, 0, 1]

A2 =

[1, 0, 0, 0]
[0, 0, -1, 0]
[0, 1, 0, d2]
[0, 0, 0, 1]

A3 =

[c3, 0, -s3, 0]
[s3, 0, c3, 0]
[ 0, -1, 0, 0]
[ 0, 0, 0, 1]

A4 =

[c4, 0, s4, 0]
[s4, 0, -c4, 0]
[ 0, 1, 0, d4]
[ 0, 0, 0, 1]

A5 =

[c5, -s5, 0, a5*c5]


[s5, c5, 0, a5*s5]
[ 0, 0, 1, 0]
[ 0, 0, 0, 1]

[c4*c5*(c1*c3 - s1*s3) - s5*(c1*s3 + c3*s1), - c5*(c1*s3 + c3*s1) - c4*s5*(c1*c3 - s1*s3),


s4*(c1*c3 - s1*s3), a5*c4*c5*(c1*c3 - s1*s3) - d4*(c1*s3 + c3*s1) - a5*s5*(c1*s3 + c3*s1) -
d2*s1]
[s5*(c1*c3 - s1*s3) + c4*c5*(c1*s3 + c3*s1), c5*(c1*c3 - s1*s3) - c4*s5*(c1*s3 + c3*s1),
s4*(c1*s3 + c3*s1), c1*d2 + d4*(c1*c3 - s1*s3) + a5*s5*(c1*c3 - s1*s3) + a5*c4*c5*(c1*s3 +
c3*s1)]
[ -c5*s4, s4*s5, c4,
-a5*c5*s4]
[ 0, 0, 0,
1]

SOLUTION TO PROBLEM NUMBER 7

SCREENSHOT FOR MATLAB CODING OF PROBLEM NUMBER 7

PLEASE SEE NEXT PAGE FOR MATLAB CODING AND OUTPUT


MATLAB CODING FOR PROBLEM NUMBER 7

% Code for solution to Problem number 7: inverse kinematics


% Mehrab Masayeed Habib L20495918
close all
clear all
clc
x=sqrt(2)
y=sqrt(2)
z=2
d2=z-1 % In figure, we can see, d2= zc-1 and t= joint angle of theta for the first
link
t=atan2(y,x)*180/pi % we 180 degree= pi radians
d3 = -1+sqrt(x^2+y^2) % from the figure, (D3+1)^2= Xc^2+Yc^2

% we there is special case


%1) Singularity point
% when x = 0, y=0> θ1 becomes undefined. This is known as singularity point
% where any value of θ1 will work for some desired z. It is avoided by
% adding an offset to the first link

disp('For Singularity point:')


x=0
y=0
z=2
d2=z-1
t= atan2(y,x)*180/pi
d3 = -1 + sqrt(x^2+y^2)

% when x=0 and y>0, thetA(θ) 1 will be pi/2 or 90 degrees.


% we can understand it from the properties of atan2(y,x)

disp('For x=0 and y>2: ')


x-0
y=5
z=2
d2= z-1
t = atan2(y,x)*180/pi
d3 = -1+sqrt(x^2+y^2)

Output:
d2
1
t=
45
d3 =
1
For Singularity point:
x=
0
y=
0
z=
2
d2 =
1
t=
0
d3 =
-1
For x=0 and y>2:
ans =
0
y=
5
z=
2
d2 =
1
t=
90
d3 =
4

You might also like