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

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy