0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 function motor_selection
0039
0040 close all
0041 global robot
0042
0043
0044
0045
0046
0047
0048
0049 q=[0 0 -pi/2 0 0 0];
0050
0051
0052
0053 maximum_speeds=[3 3 4 5 5 5];
0054
0055
0056 maximum_accels=[5 5 6 7 8 9];
0057
0058
0059 time_at_constant_speed=0.4;
0060
0061
0062
0063 robot=load_robot('unimate', 'puma560');
0064 drawrobot3d(robot, q)
0065
0066
0067
0068
0069
0070
0071 time_acc = 2*maximum_speeds./maximum_accels+time_at_constant_speed;
0072
0073
0074 total_time=max(time_acc);
0075
0076
0077 [input_speeds, input_accels, time]=build_trapezoidal_speed_profile(maximum_speeds, maximum_accels, total_time);
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 compute_inverse_dynamics(q, input_speeds, input_accels, time);
0090
0091
0092 fprintf('\n\nOBSERVE THE PLOTS AND NOTE DOWN THE PEAK TORQUE, NOMINAL TORQUE AND MOTOR SPEEDS')
0093 fprintf('\nNOW COMPUTE THE TORQUES FOR 5 DIFFERENT SELECTED MOTIONS STATES')
0094 fprintf('\nPRESS ANY KEY TO CONTINUE...')
0095
0096 pause
0097
0098
0099
0100 input_speeds = [zeros(6,1) maximum_speeds' maximum_speeds' maximum_speeds' zeros(6,1) ];
0101 input_accels = [maximum_accels' maximum_accels' zeros(6,1) -maximum_accels' -maximum_accels' ];
0102
0103 compute_inverse_dynamics(q, input_speeds, input_accels, [1:5]);
0104
0105
0106
0107
0108
0109
0110 function [input_speeds, input_accelerations, time]=build_trapezoidal_speed_profile(maximum_speeds, maximum_accels, total_time)
0111
0112 delta_time=0.01;
0113
0114
0115 time = 0:delta_time:total_time;
0116
0117 input_speeds=[];
0118 input_accelerations=[];
0119
0120 for j=1:length(maximum_speeds),
0121 vel_row=[];
0122 acc_row=[];
0123 for i=1:length(time),
0124 [vel acc] = compute_values(time(i), maximum_speeds(j), maximum_accels(j), total_time);
0125 vel_row = [vel_row vel];
0126 acc_row = [acc_row acc];
0127 end
0128 input_speeds = [input_speeds; vel_row];
0129 input_accelerations = [input_accelerations; acc_row];
0130 end
0131
0132
0133
0134
0135
0136 function [vel acc]=compute_values(time_i, vel_max, acc_max, total_time)
0137
0138 tacc = vel_max/acc_max;
0139 tdec = total_time-tacc;
0140
0141 if time_i < tacc
0142 vel = time_i.*acc_max;
0143 acc = acc_max;
0144 return;
0145 elseif (time_i >= tacc) & (time_i < tdec)
0146 vel = vel_max;
0147 acc = 0;
0148 return;
0149 else
0150 vel = vel_max-(time_i-tdec)*acc_max;
0151 acc = -acc_max;
0152 end
0153
0154
0155
0156
0157
0158
0159
0160
0161 function compute_inverse_dynamics(q, input_speeds, input_accels, time)
0162 global robot
0163
0164
0165 torques=[];
0166 for j=1:length(time),
0167 fprintf('\nComputing time %d out of %d', j, length(time));
0168
0169
0170 M=1;
0171
0172 tau=inversedynamic(robot, q, input_speeds(:,j), input_accels(:,j), [0 0 -9.81]', [M*9.81 0 0 0 0 0]');
0173 torques=[torques tau'];
0174 end
0175
0176
0177
0178 figure, hold, xlabel('time (s)'), ylabel('Input reference speeds (rad/s)')
0179 plot(time, input_speeds(1,:), time, input_speeds(2,:), time, input_speeds(3,:),...
0180 time, input_speeds(4,:), time, input_speeds(5,:), time, input_speeds(6,:));
0181 legend('Speed for joint 1 (qd1)','Speed for joint 2 (qd2)','Speed for joint 3 (qd3)',...
0182 'Speed for joint 4 (qd4)','Speed for joint 5 (qd5)','Speed for joint 6 (qd6)' )
0183
0184 figure, hold, xlabel('time (s)'), ylabel('Input reference acceleration (rad/s)')
0185 plot(time, input_accels(1,:), time, input_accels(2,:), time, input_accels(3,:),...
0186 time, input_accels(4,:), time, input_accels(5,:), time, input_accels(6,:));
0187 legend('Acceleration for joint 1 (qd1)','Acceleration for joint 2 (qd2)','Acceleration for joint 3 (qd3)',...
0188 'Acceleration for joint 4 (qd4)','Acceleration for joint 5 (qd5)','Acceleration for joint 6 (qd6)' )
0189
0190
0191
0192 figure, hold, xlabel('time (s)'), ylabel('Join Torques (N m)')
0193 plot(time, torques(1,:), time, torques(2,:), time, torques(3,:),...
0194 time, torques(4,:), time, torques(5,:), time, torques(6,:));
0195 legend('Torque for joint 1 ','Torque for joint 2 ','Torque for joint 3 ',...
0196 'Torque for joint 4','Torque for joint 5 ','Torque for joint 6 ' )
0197
0198
0199 figure, hold, xlabel('time (s)'), ylabel('Motor Torques (N m)')
0200 plot(time, torques(1,:)/robot.motors.G(1), time, torques(2,:)/robot.motors.G(2), time, torques(3,:)/robot.motors.G(3),...
0201 time, torques(4,:)/robot.motors.G(4), time, torques(5,:)/robot.motors.G(5), time, torques(6,:)/robot.motors.G(6));
0202 legend('Torque at motor 1 ','Torque at motor 2 ','Torque at motor 3 ',...
0203 'Torque at motor 4 ','Torque at motor 5 ','Torque at motor 6 ' )
0204
0205
0206
0207 figure, hold, xlabel('time (s)'), ylabel('Power needed by each motor (W)')
0208 plot(time, torques(1,:).*input_speeds(1,:), time, torques(2,:).*input_speeds(2,:), time, torques(3,:).*input_speeds(3,:),...
0209 time, torques(4,:).*input_speeds(4,:), time, torques(5,:).*input_speeds(5,:), time, torques(6,:).*input_speeds(6,:));
0210 legend('Power: motor 1','Power: motor 2','Power: motor 3',...
0211 'Power: motor 4','Power: motor 5','Power: motor 6' )
0212
0213
0214 figure, hold, xlabel('time (s)'), ylabel('Speed in r.p.m of every motor (rev/min)')
0215 plot(time, robot.motors.G(1)*input_speeds(1,:)*30/pi, time, robot.motors.G(2)*input_speeds(2,:)*30/pi, time, robot.motors.G(3)*input_speeds(3,:)*30/pi,...
0216 time, robot.motors.G(4)*input_speeds(4,:)*30/pi, time, robot.motors.G(5)*input_speeds(5,:)*30/pi, time, robot.motors.G(6)*input_speeds(6,:)*30/pi);
0217 legend('Speed at motor 1 (qd1*G)','Speed at motor 2 (qd2*G)','Speed at motor 3 (qd3*G)',...
0218 'Speed at motor 4 (qd4*G)','Speed at motor 5 (qd5*G)','Speed at motor 6 (qd6*G)' )
0219
0220
0221
0222
0223 fprintf('\nMAIN RESULTS (referred to each motor): ')
0224 fprintf('\n------------------------------------------------------------------------------------ ')
0225 fprintf('\n Joint 1 - Joint 2 - Joint 3 - Joint 4 - Joint 5 - Joint 6: ')
0226 fprintf('\nPeak Torque (N·m): %.3f %.3f %.3f %.3f %.3f %.3f ', max(abs(torques(1,:)/robot.motors.G(1))), max(abs(torques(2,:)/robot.motors.G(2))) , max(abs(torques(3,:)/robot.motors.G(3))) , max(abs(torques(4,:)/robot.motors.G(4))) , max(abs(torques(5,:)/robot.motors.G(5))) , max(abs(torques(6,:)/robot.motors.G(6))))
0227 fprintf('\nNominal Torque (N·m): %.3f %.3f %.3f %.3f %.3f %.3f ', abs(torques(1,round(length(torques)/2))/robot.motors.G(1)), abs(torques(2,round(length(torques)/2))/robot.motors.G(2)), abs(torques(3,round(length(torques)/2))/robot.motors.G(3))...
0228 , abs(torques(4,round(length(torques)/2))/robot.motors.G(4)), abs(torques(5,round(length(torques)/2))/robot.motors.G(5)), abs(torques(6,round(length(torques)/2))/robot.motors.G(6)))
0229 fprintf('\nMax motor speed (r.p.m.): %.1f %.1f %.1f %.1f %.1f %.1f ', max(abs(robot.motors.G(1)*input_speeds(1,:))*30/pi), max(abs(robot.motors.G(2)*input_speeds(2,:))*30/pi), max(abs(robot.motors.G(3)*input_speeds(3,:))*30/pi)...
0230 ,max(abs(robot.motors.G(4)*input_speeds(4,:))*30/pi), max(abs(robot.motors.G(5)*input_speeds(5,:))*30/pi), max(abs(robot.motors.G(6)*input_speeds(6,:))*30/pi))
0231 fprintf('\n------------------------------------------------------------------------------------ ')
0232
0233