Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ROBOTICS

ASSIGNMENT / PROJECT

MATLAB REPORT
“Euler and Fixed Rotations”

Submitted by
Ayesha Masood 367924
Soban Ehsan 380195
Mohib Ullah Shehzad Jadoon 375181

ME 43 C
Euler and Fixed Rotations

Following is the code explained divided into pieces for better understanding

clear
clc
M1=0; M2=0; M3=0;
angleX=deg2rad(input("choose angle for X axis in degrees:"));
angleY=deg2rad(input("choose angle for Y axis in degrees:"));
angleZ=deg2rad(input("choose angle for Z axis in degrees:"));
while(angleX<0||angleY<0||angleZ<0)
disp("error, choose again");
disp("");
angleX=deg2rad(input("choose angle for X axis in degrees:"));
angleY=deg2rad(input("choose angle for Y axis in degrees:"));
angleZ=deg2rad(input("choose angle for Z axis in degrees:"));
end

It involves initializing variables, taking user input for angles in degrees, converting those angles
to radians, and validating the input to ensure non-negative values for the angles.
● clear: Clears all variables from the workspace.
● clc: Clears the command window.
● Three variables M1, M2, and M3 are initialized to 0.
○ The input function is used to prompt the user to enter an angle for the X, Y, and Z
axes in degrees.
○ deg2rad converts the entered angles from degrees to radians.

● A while loop checks if any of the angles (angleX, angleY, angleZ) are negative.
● If any angle is negative, an error message is displayed using disp.
● The user is prompted again to enter new values for the angles until all entered angles
are non-negative.

RX=[1,0,0;0,cos(angleX),-sin(angleX);0,sin(angleX),cos(angleX)];
RY=[cos(angleY),0,sin(angleY);0,1,0;-sin(angleY),0,cos(angleY)];
RZ=[cos(angleZ),-sin(angleZ),0;sin(angleZ),cos(angleZ),0;0,0,1];
disp('RX =');
disp(RX);
disp('RY =');
disp(RY);
disp('RZ ='); ; (continued pto)
disp(RZ);
disp("Choose what operation you want to perform");
disp("1). Euler");
disp("2). Fixed");
choice=input("1 or 2 ",'s');
if (choice < 1 ||choice> 2)
disp("please choose either 1 or 2");
end

● The code defines and displays rotation matrices for the X, Y, and Z axes using the
angles provided by the user.
● It then prompts the user to choose between performing an "Euler" rotation or a "Fixed"
rotation.
● It validates the user's choice to ensure it is either 1 or 2, displaying an error message if
the choice is invalid.

switch choice
case'1'
disp("For Euler choose from list:");
disp("1) RX");
disp("2) RY");
disp("3) RZ");
disp("choose from 1, 2, 3");
while (M1<1||M2<1||M3<1)
M1=input("choose 1st rotation matrix: ",'s');
M2=input("choose 2nd rotation matrix: ",'s');
M3=input("choose 3rd rotation matrix: ",'s');
end
switch M1
case '1'
M1=RX;
case '2'
M1=RY;
case '3'
M1=RZ;
end
switch M2
case '1'
M2=RX;
case '2'
M2=RY;
case '3'
M2=RZ;
end
switch M3
case '1'
M3=RX;
case '2'
M3=RY;
case '3'
M3=RZ;
end

endresult= M3*M2*M1;
disp("endresult=");
disp(endresult);

● This block of code is the first part of the case structure where if the user selects the euler
option
● this series of output will be shown to the user , asking the user to select the 3 rotations
in the desired order.
● RX,RY,RZ are shown as 1 , 2 and 3 for simplicity of the user.

case'2'
disp("For Fixed angle choose from list:");
disp("1) RX");
disp("2) RY");
disp("3) RZ");
disp("choose from 1, 2, 3");
while (M1<1||M2<1||M3<1)
M1=input("choose 1st rotation matrix: ",'s');
M2=input("choose 2nd rotation matrix: ",'s');
M3=input("choose 3rd rotation matrix: ",'s');
end
switch M1
case '1'
M1=RX;
case '2'
M1=RY;
case '3'
M1=RZ;
end
switch M2
case '1'
M2=RX;
case '2'
M2=RY;
case '3'
M2=RZ;
end
switch M3
case '1'
M3=RX;
case '2'
M3=RY;
case '3'
M3=RZ;
end

endresult= M1*M2*M3;
disp("endresult=");
disp(endresult);
end

● Similarly this block of code is the 2nd part of the case structure where if the user selects
the Fixed Rotation option
● this series of output will be shown to the user , asking the user to select the 3 rotations
in the desired order.
● RX,RY,RZ are shown as 1 , 2 and 3 for simplicity of the user.
Examples Solved

MATLAB SOLUTION:
Solution Matches !

You might also like