AE5337 Homework 5 Liu
AE5337 Homework 5 Liu
L1 = 1;
L2 = 0.5;
w = 0.05;
m1 = L1*w^2*7806;
m2 = L2*w^2*7806;
Iz1 = w^2+L1^2;
Iz2 = w^2+L2^2;
theta1 = 10 *pi/180;
theta2 = 90 *pi/180;
Xd = [0; 0.5];
dt = 0.01;
tf = 1;
tvec = 0: dt: tf;
ThetaD_p = [0;0];
for i = 1:length(tvec)
theta1_all(i) = theta1;
theta2_all(i) = theta2;
figure(1)
X = [0 X2(1) X3(1)];
Y = [0 Y2(1) Y3(1)];
plot(X,Y,'bO-','linewidth',2)
axis equal
axis([0 1.25 0 1.25])
grid on
pause(1)
for i = 1:length(tvec)
X = [0 X2(i) X3(i)];
Y = [0 Y2(i) Y3(i)];
plot(X3(1:i),Y3(1:i),'r:','linewidth',2); hold on
plot(X,Y,'bO-','linewidth',2); hold off
axis equal
axis([0 1.25 0 1.25])
grid on
pause(0.1)
end
pause(2)
figure(3)
plot(tvec,theta1d_all, tvec,theta2d_all,'linewidth',2)
legend('Theta1d','Theta2d')
xlabel('Time (s)');
ylabel('Rate (rad/s)');
title('Joint Rates')
grid on
figure(4)
plot(tvec,theta1dd_all, tvec,theta2dd_all,'linewidth',2)
legend('Theta1dd','Theta2dd')
xlabel('Time (s)');
ylabel('Angular Acc. (rad/s^2)');
title('Joint Accelerations')
grid on
figure(5)
plot(tvec,X3, tvec,Y3, tvec,Theta_3,'linewidth',2)
legend('X','Y','Phi')
xlabel('Time (s)');
ylabel('Pose (m & rad)');
title('Cartesian Pose')
grid on
figure(6)
plot(tvec,tou1_all,tvec,tou2_all,'linewidth',2)
legend('Tou1','Tou2')
xlabel('Time (s)');
ylabel('Torque (Nm)');
title('Joint Torques (w/o g)')
grid on
figure(7)
plot(tvec,tou1g_all,tvec,tou2g_all,'linewidth',2)
legend('Tou1','Tou2')
xlabel('Time (s)');
ylabel('Torque (Nm)');
title('Joint Torques (w/ g)')
grid on
Rate (rad/s)
Angle (deg)
Result Plots:
Pose (m & rad) Angular Acc. (rad/s 2 )
Torque (Nm)
Torque (Nm)
t=0 (s) t=0.33 (s)
1.2
0.8
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2
%========================================================================
==
%Frame 0 to 1
a = 0;
alpha = 0;
d = 0;
theta = theta1;
T0f1 = HomoTrans(a,alpha,d,theta);
%Frame 1 to 2
a = L1;
alpha = 0;
d = 0;
theta = theta2;
T1f2 = HomoTrans(a,alpha,d,theta);
%Frame 2 to 3
a = L2;
alpha = 0;
d = 0;
theta = theta3;
T2f3 = HomoTrans(a,alpha,d,theta);
%Frame 3 to 4
a = L3;
alpha = 0;
d = 0;
theta = 0;
T3f4 = HomoTrans(a,alpha,d,theta);
%========================================================================
==
R(:,:,1) = (T0f1(1:3,1:3));
R(:,:,2) = (T1f2(1:3,1:3));
R(:,:,3) = (T2f3(1:3,1:3));
R(:,:,4) = (T3f4(1:3,1:3));
P(:,1) = T0f1(1:3,4);
P(:,2) = T1f2(1:3,4);
P(:,3) = T2f3(1:3,4);
P(:,4) = T3f4(1:3,4);
function T = HomoTrans(a,alpha,d,theta)
T = [ cos(theta) -sin(theta) 0 a
sin(theta)*cos(alpha) cos(theta)*cos(alpha) -sin(alpha)
-sin(alpha)*d
sin(theta)*sin(alpha) cos(theta)*sin(alpha) cos(alpha)
cos(alpha)*d
0 0 0 1 ];
end
Execution Result:
>>
tou1 =
853.6032
tou2 =
637.2026
tou3 =
296.8187