Matlab Code & Graphs


clear
clc
close all
%% Gears


wInput = 54; % rpm


% Number of teeth
N1 = 6;
N2 = 12;
N3 = N2;
TRintermediate = -(N2/N1);
TRfinal = TRintermediate*-(N3/N2);
wOutput = wInput/TRfinal;
txt = ['Output angular velocity: ', num2str(wOutput), ' rpm'];
disp(txt);


timeEnd = 60;
gear1pos = zeros(1,timeEnd+1);
gear2pos = zeros(1,timeEnd+1);
gear3pos = zeros(1,timeEnd+1);
theta = zeros(1,timeEnd+1);
time = zeros(1,timeEnd+1);


for ii = 1:timeEnd+1 % 60 seconds
time(ii) = ii-1;
thetaInput = (ii-1)*wInput/60*(1/60)*2*pi*(180/pi);
gear1pos(ii) = thetaInput;
gear2pos(ii) = gear1pos(ii)*TRintermediate;
gear3pos(ii) = gear1pos(ii)*TRfinal;
end



figure(1)
hold on;
plot(time, gear1pos);
plot(time, gear2pos);
plot(time, gear3pos);
hold off;
title('Gears: Position')
xlabel('Time (sec)')
ylabel('Gear Position (degrees)')
legend('Gear 1', 'Gear 2', 'Gear 3')


%% Legs


% mm
a = 7;
b = 30;
c = 30;
d = 51.21;
theta1 = 62.03;
delta = 1;
p = 30;
beta = 0;


n = 360;
for ii=1:n+1
theta2(ii) = (ii-1)*pi/180 + 45*pi/180;
angles = fourbarpos1(a,b,c,d,theta1,theta2(ii),delta);
theta3(ii) = angles(3);
theta4(ii) = angles(4);
Rx(ii) = a*cos(theta2(ii)) + p*cos(theta3(ii) + beta);
Ry(ii) = a*sin(theta2(ii)) + p*sin(theta3(ii) + beta);
end


figure(2)
plot(Rx,Ry)
title('Knee Position')
xlabel('X')
ylabel('Y')


maxKnee = max(Ry);
minKnee = min(Ry);


txt = ['The maximum knee height is ', num2str(maxKnee),];
disp(txt);
txt = ['The minimum knee height is ', num2str(minKnee),];
disp(txt);