Appendix - Mellinger
Works Cited
Ahmad Y Hassan. The Crank-Connecting Rod System in a Continuously Rotating Machine.
Code
%% Derive Position 1st Chain
syms a b c theta2 theta3 bdot w3
realx = a*cosd(theta2) + b*cosd(theta3) == 0;
imgx = a*sind(theta2) + b*sind(theta3) - c == 0;
[b,theta3] = solve(simplify(realx),simplify(imgx),b,theta3);
%% Derive Velocity 1st Chain
syms a b c theta2 theta3 bdot w3 w2
realdx = -a*w2*sind(theta2)+ bdot*cosd(theta3) - b*w3*sind(theta3) == 0;
imgdx = a*w2*cosd(theta2) + bdot*sind(theta3) + b*w3*cosd(theta3) == 0;
[w3,bdot] = solve(simplify(realdx),simplify(imgdx),bdot,w3);
%% Derive Acceleration 1st Chain
syms ddb a2 a theta2 b c theta2 theta3 bdot w3 w2 a3
realddx = -2*bdot*w3*sind(theta3) + a*w2^2*cosd(theta3) + ddb*cosd(theta3) - b*w3^2*cosd(theta3) - b*a3*sind(theta3) == 0;
imgddx = bdot*w3*cosd(theta3) + bdot*w3*cosd(theta3) - a*w2^2*sind(theta2) + ddb*sind(theta3) - b*w3^2*sind(theta3) + b*a3*cosd(theta3) == 0;
[ddb,a3] = solve(simplify(realddx),simplify(imgddx),ddb,a3);
%% Derive Position 2nd Chain
f = d*cosd(theta3);
d = e/sind(theta3);
%% Derive Velocity 2nd Chain
syms d w3 theta3 ddot fdot
realdx2 = -d*w3*sind(theta3)+ddot*cosd(theta3)-fdot == 0;
imgdx2 = d*w3*cosd(theta3)+ddot*sind(theta3) == 0;
[ddot,fdot] = solve(simplify(realdx2),simplify(imgdx2),ddot,fdot);
%% Derive Acceleration 2nd Chain
syms theta3 bdot w3 ddf ddot a3 d e f ddd
realddx = -2*ddot*w3*sind(theta3)-d*a3*sind(theta3) - d*w3^2*cosd(theta3)+ddd*cosd(theta3) - ddf == 0;
imgddx = 2*ddot*w3*cosd(theta3)+d*a3*sind(theta3) -d*w3^2*sind(theta3)+ddd*sind(theta3) == 0;
[ddd,ddf] = solve(simplify(realddx),simplify(imgddx),ddd,ddf);
%% Mechanism Kinematic Simulation
% Link Lengths
a = 1;
c = 2.5;
e = 4.5;
L3 = 5;
w2 = 1; % Input angular velocity (constant)
i = 1;
for theta2 = 0:360
% Position Analysis
theta3 = atand((a*sind(theta2)+c)/(a*cosd(theta2)));
if theta3 > 0
theta3 = theta3 - 180;
end
b = -a*cosd(theta2)/cosd(theta3);
% Velocity
w3 = a*w2*sin((pi*(theta2 - theta3))/180);
bdot = -(a*w2*cos((pi*(theta2 - theta3))/180))/b;
d = e/sind(theta3);
f = d*cosd(theta3);
ddot = -(d*w3*cos((pi*theta3)/180))/sin((pi*theta3)/180);
fdot = (9*29^(1/2)*a*w2*sin((pi*(theta2 - theta3))/180))/(10*sin((pi*theta3)/180));
MA = abs(w2/w3)*abs(a/d);
% Acceleration
ddb = b*w3^2 - a*w2^2 + a*w2^2*sin((pi*theta3)/180)^2 + a*w2^2*sin((pi*theta2)/180)*sin((pi*theta3)/180);
a3 = ((a*w2^2*sin((pi*theta3)/90))/2 - 2*bdot*w3 + a*w2^2*cos((pi*theta3)/180)*sin((pi*theta2)/180))/b;
ddd = -(- d*sin((pi*theta3)/180)*w3^2 + 2*ddot*cos((pi*theta3)/180)*w3 + a3*d*sin((pi*theta3)/180))/sin((pi*theta3)/180);
ddf = -(a3*d + 2*ddot*w3 - a3*d*cos((pi*theta3)/180)^2 + a3*d*cos((pi*theta3)/180)*sin((pi*theta3)/180))/sin((pi*theta3)/180);
% Coriolis Input Slider
coriolis_x = -2*bdot*w3*sind(theta3);
coriolis_y = 2*bdot*w3*cosd(theta3);
% Coriolis Output Slider
coriolis_x2 = -2*ddot*w3*sind(theta3);
coriolis_y2 = 2*ddot*w3*cosd(theta3);
% Output Arrays
ddf_out(i) = ddf;
a3_out(i) = a3;
d_out(i) = d;
b_out(i) = b;
MA_out(i) = MA;
fdot_out(i) = fdot;
ddot_out(i) = ddot;
bdot_out(i) = bdot;
f_out(i) = f;
d1_out(i) = d;
theta2_out(i) = theta2;
theta3_out(i) = theta3;
w2_out(i) = w2;
w3_out(i) = w3;
coriolis_x2_out(i) = coriolis_x2;
coriolis_y2_out(i) = coriolis_y2;
coriolis_x_out(i) = coriolis_x;
coriolis_y_out(i) = coriolis_y;
i = i + 1;
end
% Plot Position
figure(1)
sgtitle('Position Analysis')
subplot(3,1,1)
plot(theta2_out,theta3_out, 'k','linewidth', 2)
title('Theta 3 Relative Motion')
ylabel('Theta 3 (deg)')
subplot(3,1,2)
plot(theta2_out,f_out, 'k','linewidth', 2)
title('Output Slider Relative Motion')
ylabel('F, X-axis (inches)')
subplot(3,1,3)
plot(theta2_out,b_out, 'b','linewidth', 2)
hold on
plot(theta2_out,-d_out, 'r','linewidth', 2)
title('Slider Positions Along Link 3')
ylabel('Slider Pos. (inches)')
xlabel('Input Angle, Theta 2 (deg)')
legend('Input Slider, b', 'Output Slider, d')
% Plot Velocity
figure(2)
sgtitle('Velocity Analysis')
subplot(3,1,1)
plot(theta2_out,w3_out, 'k','linewidth', 2)
title('Link 3 Rotational Velocity')
ylabel('Omega 3 (deg/s)')
subplot(3,1,2)
plot(theta2_out,fdot_out, 'k','linewidth', 2)
title('Output Slider Velocity')
ylabel('Output Velocity (in/s)')
subplot(3,1,3)
plot(theta2_out,bdot_out, 'b','linewidth', 2)
hold on
plot(theta2_out,ddot_out, 'r','linewidth', 2)
title('Slider Velocity Along Link 3')
ylabel('Slider Vel. (in/s)')
xlabel('Input Angle (deg)')
legend('Input Slider, b', 'Output Slider, d')
% Plot Acceleration
figure(3)
sgtitle('Acceleration Analysis')
subplot(3,1,1)
plot(theta2_out,a3_out, 'k','linewidth', 2)
title('Link 3 Rotational Acceleration')
ylabel('Omega 3 (deg/s^2)')
subplot(3,1,2)
plot(theta2_out,ddf_out, 'k','linewidth', 2)
title('Output Slider Acceleration')
ylabel('Output Velocity (in/s^2)')
subplot(3,1,3)
plot(theta2_out,sqrt(coriolis_x_out.^2 + coriolis_y_out.^2), 'b','linewidth', 2)
hold on
plot(theta2_out,sqrt(coriolis_x2_out.^2 + coriolis_y2_out.^2), 'r','linewidth', 2)
title('Slider Coriolis Acceleration')
ylabel('Slider Acc. Magnitude (in/s^2)')
legend('Input Slider, b', 'Output Slider, d')
xlabel('Input Angle (deg)')
% Animation
v = VideoWriter('animation.avi');
open(v);
for i = 1:length(theta2_out)
% Robot Coordinates
O2 = [0 0];
O3 = [0 -2.5];
L2x = O2(1) + a*cosd(theta2_out(i));
L2y = O2(2) + a*sind(theta2_out(i));
L2 = [L2x L2y];
L3x = O3(1) - L3*cosd(theta3_out(i));
L3y = O3(2) - L3*sind(theta3_out(i));
bx = L2x + b_out(i)*cosd(theta3_out(i));
by = L2y + b_out(i)*sind(theta3_out(i));
O4y = ones(1,length(theta2_out))*2;
figure(4)
plot([3, 3],[3, 3])
axis([-3, 3, -3, 3])
hold on
inp = line([O2(1),L2x],[O2(2),L2y], 'color', 'b', 'linewidth', 2);
line([L2x,f_out(i)],[L2y, 2], 'color', 'k', 'linewidth', 2)
line([O3(1),L3x],[O3(2),L3y], 'color', 'k', 'linewidth', 2)
cor = quiver(L2x,L2y,coriolis_x_out(i),coriolis_y_out(i), 'color', 'g', 'linewidth', 1); % Coriolis
quiver(f_out(i),2,coriolis_x2_out(i),coriolis_y2_out(i), 'color', 'g', 'linewidth', 1);
slider = plot(f_out(i),2,'s','color', 'r', 'linewidth', 4);
plot(L2x,L2y,'s','color', 'r', 'linewidth', 4)
pin = plot(O3(1),O3(2),'o', 'color', 'b', 'linewidth', 4);
plot(O2(1),O2(2),'o', 'color', 'b', 'linewidth', 4)
outp = plot(f_out(1:i),O4y(1:i), '--k');
title('Mechanism Animation')
legend([inp, outp, slider, pin, cor], 'Input','Output', 'Slider', 'Pin','Coriolis Acc.','location', 'southoutside', 'Orientation', 'horizontal')
pause(0.001)
hold off
frame = getframe(gcf);
writeVideo(v,frame);
end
close(v)
Arduino
#include <Stepper.h>
const int stepsPerRevolution = 1600; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// nothing to do inside the setup
}
void loop() {
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(9.55);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}
