0% found this document useful (0 votes)
12 views25 pages

ELIAS TEGEGNEl Matlab Assignment (Seconed Revised) One

This document is a revised assignment submitted by Elias Tegegne to Professor Rao at Bahir Dar University, Ethiopia in July 2022. It contains MATLAB code functions for modeling and controlling electromechanical systems, including functions to: 1. Calculate the transformation matrix and new position vector after three successive rotations defined by input angles. 2. Determine the Euler parameters, unit vectors, and rotation angle from a given transformation matrix. 3. Calculate the angular velocity vector, skew matrix, transformation matrix, and derivative of the transformation matrix by inputting rotation angles and their derivatives. 4. Obtain the derivative of the Euler parameters by inputting the parameters and angular velocities, using the relationship between angular

Uploaded by

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

ELIAS TEGEGNEl Matlab Assignment (Seconed Revised) One

This document is a revised assignment submitted by Elias Tegegne to Professor Rao at Bahir Dar University, Ethiopia in July 2022. It contains MATLAB code functions for modeling and controlling electromechanical systems, including functions to: 1. Calculate the transformation matrix and new position vector after three successive rotations defined by input angles. 2. Determine the Euler parameters, unit vectors, and rotation angle from a given transformation matrix. 3. Calculate the angular velocity vector, skew matrix, transformation matrix, and derivative of the transformation matrix by inputting rotation angles and their derivatives. 4. Obtain the derivative of the Euler parameters by inputting the parameters and angular velocities, using the relationship between angular

Uploaded by

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

BAHIR DAR UNIVERSITY

BAHIR DAR INSTITUTE OF TECHNOLOGY


FACULTY OF MECHANICAL AND INDUSTRIAL ENGINEERING
DEPATRMENT OF ELECTROMECHANICAL

Computer Aided Modeling and Control of Electromechanical Systems

Revised Assignment II (Mat lab)

Prepared by

1. ELIAS TEGEGNE (IDNO. BDU1401918)


Submitted to: Prof. Rao

Bahir Dar, Ethiopia


July, 2022
function pa=eang(a,b,c,p)
%input rotation angles for program to calculate transformation matrix%
%and the new position vectors%
a=input('input the value of alpha= ')
b=input('input the value of beta= ')
c=input('inputthe value of gamma= ')
%give the initial position coordinate of point p to calculate the new
%position cordinate after three rotation%
x=input('input initial position values of x component for point p=')
y=input('input initial position values of y component for point p=')
z=input('input initial position values of z component for point p=')
alpha=a*pi/180;
beta=b*pi/180;
gamma=c*pi/180;
P=[x;y;z];
sll=cos(beta)*cos(gamma);
s12=cos(alpha)*sin(gamma)+ sin(alpha)*sin(beta)*cos(gamma);
s13=sin(gamma)*sin(alpha)- cos(alpha)*sin(beta)*cos(gamma);
s21=-cos(beta)*sin(gamma);
s22=cos(alpha)*cos(gamma)-sin(alpha)*sin(beta)*sin(gamma);
s23=sin(alpha)*cos(gamma)+cos(alpha)*sin(beta)*sin(gamma);
s31=sin(beta);
s32=-sin(alpha)*cos(beta);
s33=cos(alpha)*cos(beta);
disp('');
disp('Transformation matrix :');
S=[sll s12 s13;s21 s22 s23;s31 s32 s33]
disp('');
disp('The new position Vector:');
Pa=S*P
disp('');
After we run this program the program will request input values that is angles and initial
coordinates given in the question and then display the outputs.
Solution
input the value of alpha= 30
a =30
input the value of beta= 60
b = 60
input the value of gamma= 45
c = 45
input initial position values of x component for point p=3
x=3
input initial position values of y component for point p=4
y=4
input initial position values of z component for point p=5
z =5
Transformation matrix:
S=
0.3536 0.9186 -0.1768
-0.3536 0.3062 0.8839
0.8660 -0.2500 0.4330
The new position Vector:
Pa =
3.8510
4.5835

3
4
function s=eulerangle(a,b,c)
%to determine euler parameters, unit vectors and euler angle first we have
%to calculate the transformation matrix s after three rotations%
%input given rotation angles from the question for program to calculate
%transformation matrix%
a=input('input the value of alpha= ')
b=input('input the value of beta= ')
c=input('inputthe value of gamma= ')
alpha=a*pi/180;
beta=b*pi/180;
gamma=c*pi/180;
sll=cos(beta)*cos(gamma);
s12=cos(alpha)*sin(gamma)+ sin(alpha)*sin(beta)*cos(gamma);
s13=sin(gamma)*sin(alpha)- cos(alpha)*sin(beta)*cos(gamma);
s21=-cos(beta)*sin(gamma);
s22=cos(alpha)*cos(gamma)-sin(alpha)*sin(beta)*sin(gamma);

5
s23=sin(alpha)*cos(gamma)+cos(alpha)*sin(beta)*sin(gamma);
s31=sin(beta);
s32=-sin(alpha)*cos(beta);
s33=cos(alpha)*cos(beta);
disp('Transformation matrix is:');
S=[sll s12 s13;s21 s22 s23;s31 s32 s33]
disp('');
%to calculate euler parameters first calculate trase of s called trs%
trs=sll+s22+s33;
e4=((trs+1)/4)^0.5;
e1=(s32-s23)/(4*e4);
e2=(s13-s31)/(4*e4);
e3=(s21-s12)/(4*e4);
% we can calculate the axis rotation angle O and unit vector using euler parametrs%
O=2*acosd(e4);
lambda1=e1/sind(O/2);
lambda2=e2/sind(O/2);
lambda3=e3/sind(O/2);
%we can also calculate the rodriguez parameter using lambdas and o%
n1=lambda1*tand(O/2);
n2=lambda2*tand(O/2);
n3=lambda3*tand(O/2);
disp('the euler parameters are');
e=[e1 e2 e3 e4]
disp('the euler axis rotation angle is')
angletetha=O
disp('the euler unit vectors are');
lambda=[lambda1 lambda2 lambda3]
disp('the rodrigez parameters are');
n=[n1 n2 n3]
disp(' ')
Solution
input the value of alpha= 30
a = 30
input the value of beta= 60
b = 60
input the value of gamma= 45
c = 45

6
Transformation matrix is:
S = 0.3536 0.9186 -0.1768
-0.3536 0.3062 0.8839
0.8660 -0.2500 0.4330
the euler parameters are
e = -0.3919 -0.3604 -0.4397 0.7233
the euler axis rotation angle is
angle tetha = 87.3419
the euler unit vectors are
lambda =
-0.5676 -0.5220 -0.6367
the rodrigez parameters are
n=
-0.5418 -0.4983 -0.6079

7
function s=angles(alpha,beta,gamma)
%%%% to calculate angular velocity first RwO first we have to calculate
%%%% componenets of angular velocity
%%%% so todo this we must give input angles and ange dervatives
disp('please insert angle dervatives');
da=input('input values of a dervate=')
db=input('input values of b dervate=')
dy=input('input values of y dervate=')
disp('please insert rotation angles');
alpha=input('input the value of alpha= ')
beta=input('input the value of beta= ')
gamma=input('inputthe value of gamma= ')
w1=da*cosd(beta)*cosd(gamma)+db*sind(gamma);
w2=da*cosd(beta)*sind(gamma)+db*cosd(gamma);
w3=dy+da*sind(beta);
disp('angular velocit vector RwO is')
RwO=[w1;w2;w3]
%to detemine transformation matrix dervative sAO dot first calculate skew matrix Q
disp('skew matrix is:')
Q=[0 -w3 w2;w3 0 -w1;-w2 w1 0]
% the transformation matrix is;
sll=cosd(beta)*cosd(gamma);
s12=cosd(alpha)*sind(gamma)+ sind(alpha)*sind(beta)*cosd(gamma);
s13=sind(gamma)*sind(alpha)- cosd(alpha)*sind(beta)*cosd(gamma);
s21=-cosd(beta)*sind(gamma);
s22=cosd(alpha)*cosd(gamma)-sind(alpha)*sind(beta)*sind(gamma);
s23=sind(alpha)*cosd(gamma)+cosd(alpha)*sind(beta)*sind(gamma);
s31=sind(beta);
s32=-sind(alpha)*cosd(beta);
s33=cosd(alpha)*cosd(beta);

8
disp('Transformation matrix is:');
S=[sll s12 s13;s21 s22 s23;s31 s32 s33]
%dS dot is the product of matrix Q and S
disp ('dervative of transformation matrix dS')
dS=Q*S
disp('')
after we run the above program it will request rotation angle and angle derivative and then
it will display angular velocity vector RwO,skew matrix Q transformation matrix S and
finally derivative of transformation
matrix dS.
please insert angle dervatives
input values of a dervate=1
da =
1
input values of b dervate=2
db =
2
input values of y dervate=3
dy =
3
please insert rotation angles
input the value of alpha= 30
alpha =
30
input the value of beta= 60
beta =
60
input the value of gamma= 45
gamma =
45
angular velocit vector RwO is
RwO =
1.7678
1.0607
3.8660
skew matrix is:
Q=
0 -3.8660 1.0607

9
3.8660 0 -1.7678
-1.0607 1.7678 0
Transformation matrix is:
S=
0.3536 0.9186 -0.1768
-0.3536 0.3062 0.8839
0.8660 -0.2500 0.4330
derivative of transformation matrix dS
dS =
2.2854 -1.4489 -2.9578
-0.1641 3.9931 -1.4489
-1.0000 -0.4330 1.7500

10
function eulerparameter(e1,e2,e3,e4)
%the quesion is to obtain dervative of euler parameter so first we have to
%get values of euler parameters.but for this queston euler parameters are
%given in problem 2
e1=input('please insert values of euler parameter1,e1:')
e2=input('please insert values of euler parameter2,e2:')
e3=input('please insert values of euler parameter3,e3:')
e4=input('please insert values of euler parameter4,e4:')
%angular velocities w are also nessecary to calculate dervatives
%of euler pameter and for this qestion anglar velocities are given Q4.
w1=input('please insert values of angular velocity1,w1:')
w2=input('please insert values of angular velocity2,w2:')
w3=input('please insert values of angular velocity2,w3:')
w4=input('please insert values of angular velocity1,w4:')
%from the relation w=2*E*dE we can calculate dE=0.5*E'w
disp('euler parameter matrix Eij:')
E=[e4 -e3 e2 -e1;e3 e4 -e1 -e2;-e2 e1 e4 -e3;e1 e2 e3 e4]
disp(' transpose of euler parameter matrix ,Eij:')
E'
disp('angular velocity matrix w:')
W=[w1;w2;w3;w4]
disp('dervative euler parameter matrix,dEij:')
dEij=0.5*E'*W

11
after run the above program the program will request Euler parameter and angular
velocity.so for this question insert values calculated from problem 2 and 4 give w4=o since
E is orthogonal matrix.
please insert values of euler parameter1,e1:-0.3919
e1 = -0.3919
please insert values of euler parameter2,e2:-0.3604
e2 =-0.3604
please insert values of euler parameter3,e3:-0.4397
e3 =-0.4397
please insert values of euler parameter4,e4:0.7233
e4 =0.7233
please insert values of angular velocity1,w1:1.7678
w1 =1.7678
please insert values of angular velocity2,w2:1.7678
w2 =1.7678
please insert values of angular velocity2,w3:3.8660
w3 =3.8660
please insert values of angular velocity1,w4:0
w4 = 0
euler parameter matrix Eij:
E=
0.7233 0.4397 -0.3604 0.3919
-0.4397 0.7233 0.3919 0.3604
0.3604 -0.3919 0.7233 0.4397
-0.3919 -0.3604 -0.4397 0.7233
transpose of euler parameter matrix ,Eij:
ans =
0.7233 -0.4397 0.3604 -0.3919
0.4397 0.7233 -0.3919 -0.3604

12
-0.3604 0.3919 0.7233 -0.4397
0.3919 0.3604 0.4397 0.7233
angular velocity matrix w:
W=
1.7678
1.0607
3.8660
0
dervative euler parameter matrix,dEij:
dEij =
1.1028
0.0147
1.2874
1.3875

13
function rotatinangle(a2,b2y2,a3,b3,y3)
a2=input(' rotation angle of body2 alpha:')
b2=input(' rotation angle of body2 beta')
y2=input(' rotation angle of body2 gamma')
a3=input(' rotation angle body3 alpha')
b3=input(' rotation angle body3 beta')
y3=input(' rotation angle body3 gamma')
w11=input('angular velocity body 1, w1:')
w12=input('angular velocity body 1, w2:')
w13=input('angular velocity body 1, w3:')
w21=input('angular velocity body 2, w1:')
w22=input('angular velocity body 2, w2:')
w23=input('angular velocity body 2, w3:')
14
w31=input('angular velocity body 3, w1:')
w32=input('angular velocity body 3, w2:')
w33=input('angular velocity body 3, w3:')
%to calculate W20 and W30 first determine s21,s12,w21andw10.
W21=[0 -w23 w22;w23 0 -w21;-w22 w21 0];
W10=[0 -w13 w12;w13 0 -w11;-w12 w11 0];
W32=[0 -w33 w32;w33 0 -w31;-w32 w31 0];
% the transformation matrix is;
sll=cosd(b2)*cosd(y2);
s12=cosd(a2)*sind(y2)+ sind(a2)*sind(b2)*cosd(y2);
s13=sind(y2)*sind(a2)- cosd(a2)*sind(b2)*cosd(y2);
s21=-cosd(b2)*sind(y2);
s22=cosd(a2)*cosd(y2)-sind(a2)*sind(b2)*sind(y2);
s23=sind(a2)*cosd(y2)+cosd(a2)*sind(b2)*sind(y2);
s31=sind(b2);
s32=-sind(a2)*cosd(b2);
s33=cosd(a2)*cosd(b2);
s1ll=cosd(b3)*cosd(y3);
s112=cosd(a3)*sind(y3)+ sind(a3)*sind(b3)*cosd(y3);
s113=sind(y3)*sind(a3)- cosd(a3)*sind(b3)*cosd(y3);
s121=-cosd(b3)*sind(y3);
s122=cosd(a3)*cosd(y3)-sind(a3)*sind(b3)*sind(y3);
s123=sind(a3)*cosd(y3)+cosd(a3)*sind(b3)*sind(y3);
s131=sind(b3);
s132=-sind(a3)*cosd(b3);
s133=cosd(a3)*cosd(b3);
disp('Transformation matrixS with respect to referanse and there transposes.:')
S21=[sll s12 s13;s21 s22 s23;s31 s32 s33]
S32=[s1ll s112 s113;s121 s122 s123;s131 s132 s133]
S31=S32*S21
S12=S21'
S23=S32'
S13=S31'
disp('finally the values ofW20 and W30 are')
W20=W21+S21*W10*S12
W30=W32+S32*W21*S23+S31*W10*S13
When we run the above program it will request rotation angle of each body and angular
velocity’s of each bod y with respect to other body’s. And then when you give this values It
will display w20 and w30 and all transformation matrix needed to calculate them..
rotation angle of body2 alpha:20
a2 =20rotation angle of body2 beta30

15
b2 =30
rotation angle of body2 gamma40
y2 =40
rotation angle body3 alpha25
a3=25
rotation angle body3 beta35
b3 =35
rotation angle body3 gamma45
y3 =45
angular velocity body 1, w1:1
w11 =1
angular velocity body 1, w2:2
w12 =2
angular velocity body 1, w3:3
w13 =3
angular velocity body 2, w1:5
w21 =5
angular velocity body 2, w2:6
w22 =6
angular velocity body 2, w3:7
w23 =7
angular velocity body 3, w1:3
w31 =3
angular velocity body 3, w2:4
w32 =4
angular velocity body 3, w3:5
w33 =5
Transformation matrixS with respect to referanse and there transposes.:

16
S21 =
0.6634 0.7350 -0.1401
-0.5567 0.6099 0.5640
0.5000 -0.2962 0.8138

S32 =
0.5792 0.8123 -0.0687
-0.5792 0.4695 0.6664
0.5736 -0.3462 0.7424
S31 =
-0.1023 0.9415 0.3210
-0.3124 -0.3368 0.8882
0.9444 -0.0095 0.3286
S12 =
0.6634 -0.5567 0.5000
0.7350 0.6099 -0.2962
-0.1401 0.5640 0.8138
S23 =
0.5792 -0.5792 0.5736
0.8123 0.4695 -0.3462
-0.0687 0.6664 0.7424
S13 =
-0.1023 -0.3124 0.9444
0.9415 -0.3368 -0.0095
0.3210 0.8882 0.3286
finally the values ofW20 and W30 are
W20 =

17
-0.0000 -9.3490 8.3552
9.3490 0.0000 -6.7132
-8.3552 6.7132 0.0000
W30 =
0.0000 -12.8988 10.2642
12.8988 -0.0000 -13.0324
-10.2642 13.0324 -0.0000

18
function angularvelocity(a,b,y)
a1=input('angle dervative of body1 alpha1=')
b1=input('angle dervative of body1 beta1=')
y1=input('angle dervative of body1 gamma1=')
a2=input('angle dervative of body2 alpha2=')
b2=input('angle dervative of body2 beta=')
y2=input('angle dervative of body2 gamma2=')
a3=input('angle dervative of body3 alpha3=')
b3=input('angle dervative of body3 beta3=')
y3=input('angle dervative of body3 gamma3=')
%to determine angular velocity Rw1,Rw2,Rw3 and partial velocity w1,w2,w3
%transformation matrix s10 and s20 is needed so first get values of them
s10=[0.3536 0.9186 -0.1768; -0.3536 0.3062 0.8839
0.8660 -0.2500 0.4330]
s21=[0.6634 0.7350 -0.1401;-0.5567 0.6099 0.5640

0.5000
s20=s21*s1 -0.2962 0.8138]
0;
disp('angular velocities of bodies with respect to referance are')
Rw1=[a1 b1 y1]
Rw2=Rw1+[a2,b2,y2]*s10
Rw3=Rw2+[a3,b3,y3]*s20
disp('partial angular velocities are')
w1=[eye(3,3);zeros(3,3);zeros(3,3)]
w2=[eye(3,3);s10;zeros(3,3)]
w3=[eye(3,3);s10;s20]
When you run the above program it will request angle derivative of each body and then if
you insert it will display angular velocity vector and partial angular velocity
angle dervative of body1 alpha1=1
a1 = 1
angle dervative of body1 beta1=2
b1 =2
angle dervative of body1 gamma1=3
y1 = 3
angle dervative of body2 alpha2=3
a2 = 3
angle dervative of body2 beta=4

19
b2 =4
angle dervative of body2 gamma2=5
y2 = 5
angle dervative of body3 alpha3=5
a3 = 5
angle dervative of body3 beta3=6
b3 =6
angle dervative of body3 gamma3=7
y3 = 7
s10 =
0.3536 0.9186 -0.1768
-0.3536 0.3062 0.8839
0.8660 -0.2500 0.4330
s21 =
0.6634 0.7350 -0.1401
-0.5567 0.6099 0.5640
0.5000 -0.2962 0.8138
angular velocities of bodies with respect to referance are
Rw1 =1 2 3
Rw2 =4.9764 4.7306 8.1702
Rw3 =11.6027 7.4403 15.8343
partial angular velocities are
w1 =
100
010
001
000
000
000
000
000
000
w2 =
1.0000 0 0
0 1.0000 0
0 0 1.0000
0.3536 0.9186 -0.1768
-0.3536 0.3062 0.8839
0.8660 -0.2500 0.4330
000
000
000
w3 =

20
1.0000 0 0
0 1.0000 0
0 0 1.0000
0.3536 0.9186 -0.1768
-0.3536 0.3062 0.8839
0.8660 -0.2500 0.4330
-0.1466 0.8695 0.4717
0.0759 -0.4656 0.8817
0.9863 0.1652 0.0022

function angularacce(si,teta,fi)
a=input('please insert value of si ')
b=input('please inseart value of teta')
c=input('please inseart value of fi')
da=input('please inseart value of si dervate')
db=input('please inseart value of teta derviate')
dc=input('please inseart value of fi derviate')
d2a=input('please inseart value of si second derviate')
d2b=input('please inseart value of teta second derviate')
d2c=input('please inseart value of fi second derviate')
%the angular vvelocity Of body 3 Rw3 and angula acceleration of body 3
% R@3 is calculated from the input values directly.
disp('value of angular velocity vector component');
Rw3=[(db+dc)*cosd(a); (db+dc)*sind(a); da]

21
disp('value of angular angular vector component');
Ra3=[(d2b+d2c)*cosd(a)-(db+dc)*da*sind(a) (d2b+d2c)*sind(a)+(db+dc)*da*cosd(a) d2a]
The above program will provide the angular velocity vector and angular acceleration
vector by using the given parameters given in the question.
please insert value of si 30
a = 30
please insert value of teta45
b = 45
please insert value of fi60
c =60
please insert value of si dervate1
da = 1
please insert value of teta derviate2
db = 2
please insert value of fi derviate3
dc = 3
please insert value of si second derviate4
d2a =4
please insert value of teta second derviate5
d2b =5
please insert value of fi second derviate6
d2c =6
value of angular velocity vector component
Rw3 =
4.3301 2.5000 1.0000
value of angular angular vector component
Ra3 =
7.0263 9.8301 4.0000

22
function genspeed(a,b,y)
a=input('value of rotation angle alpha a:')
b=input('value of rotation angle beta b:')
y=input('value of rotation angle gamma y:')
da=input('value of angle dervayive of da:')
db=input('value of angle dervayive of db:')
dy=input('value of angle dervayive of dy:')
%the generalized speed can be calculated as
y1=da*cosd(b)*cosd(y)+ db*sind(y);
y2=-da*cosd(b)*sind(y)+ db*cosd(y);
y3=dy+da*sind(b);
disp('generalized speed y(k)s are')
Yk=[y1;y2;y3]
% the gimble matrix W components are
w11=cosd(b)*cosd(y);
w12=-cosd(b)*sind(y);
w13=sind(b);
w21=sind(y);
w22=cosd(y);
w23=0;

23
w31=0;
w32=0;
w33=1;
disp('the transformation matrix [w] is')
W=[w11 w12 w13;w21 w22 w23;w31 w32 w33]
When you run the above equation it will display the generalized speed yk and
transformation matrix[w] by inserting rotation angle and their derivative.
value of rotation angle alpha a:30
a = 30
value of rotation angle beta b:60
b = 60
value of rotation angle gamma y:45
y = 45
value of angle dervayive of da:1
da = 1
value of angle dervayive of db:2
db = 2
value of angle dervayive of dy:3
dy = 3
generalized speed y(k)s areYk =
1.7678
1.0607
3.8660
the transformation matrix [w] is
W=
0.3536 -0.3536 0.8660
0.7071 0.7071 0
0 0 1.0000

24
25

You might also like