VIII Appendix

Arduino Code

#include <Stepper.h> //library

const int stepsPerRevolution = 2048; //number of steps per rotation


Stepper myStepper1 = Stepper(stepsPerRevolution, 8, 10, 9, 11);

Stepper myStepper2 = Stepper(stepsPerRevolution, 3, 5, 4, 6);


void setup() {

  // put your setup code here, to run once:

 myStepper1.setSpeed(5);

 myStepper2.setSpeed(5);

  Serial.begin(9600);

}

void loop() {

  // put your main code here, to run repeatedly:

  Serial.println("clockwise");

  myStepper1.step(stepsPerRevolution);

  Serial.println("counterclockwise");

  myStepper2.step(stepsPerRevolution);

}

MATLAB Code

%% Group 1 - Abayomi Adekanmbi & Zakari Ishak-Boushaki

clear all; clc; close all;

L1=5;
L2=1;
L3=7;
L33=7;
L4=4;
L44=4;
L5=4;
L6=4;
L66=8;
L7=4;

A1=0;
A2=pi/2:0.3:6*pi+(pi/2);

A22=pi+A2;
A2=-A2; A22=-A22;

% Point B
Bx=L2.*cos(A2);
By=L2.*sin(A2);

B2x=L2.*cos(A22);
B2y=L2.*sin(A22);

[A3,A4] = fourbarpos(L1,L2,L3,L4,A1,A2);
A5=(pi-A4)+(pi/2);
[A32,A42]= fourbarpos (L1,L2,L3,L4,A1,A22);
A52=(pi-A42)+(pi/2);

% Point C
Cx=Bx+(L3.*cos(A3));
Cy=L4.*sin(A4);

C2x=B2x+(L3.*cos(A32));
C2y=L4.*sin(A42);

% Point D
Dx=L1; Dy=0;

p=2.*L4.*((L1.*cos(A1))-(L2.*cos(A2)));
q=2.*L4.*((L1.*sin(A1))-(L2.*sin(A2)));
r=(L1.^2)+(L2.^2)-(L33.^2)+(L44.^2)-(2.*L1.*L2.*cos(A1-A2));

A44=2.*atan((-q+sqrt((p.^2)+(q.^2)-(r.^2)))./(r-p));

d=2.*L3.*((L2.*cos(A2))-(L1.*cos(A1)));
e=2.*L3.*((L2.*sin(A2))-(L1.*sin(A1)));
f=(L1.^2)+(L2.^2)+(L33.^2)-(L44.^2)-(2.*L1.*L2.*cos(A2-A1));

A33=2.*atan((-e-sqrt((d.^2)+(e.^2)-(f.^2)))./(f-d));

p2=2.*L4.*((L1.*cos(A1))-(L2.*cos(A22)));
q2=2.*L4.*((L1.*sin(A1))-(L2.*sin(A22)));
r2=(L1.^2)+(L2.^2)-(L33.^2)+(L44.^2)-(2.*L1.*L2.*cos(A1-A22));

A442=2.*atan((-q2+sqrt((p2.^2)+(q2.^2)-(r2.^2)))./(r2-p2));

d2=2.*L3.*((L2.*cos(A22))-(L1.*cos(A1)));
e2=2.*L3.*((L2.*sin(A22))-(L1.*sin(A1)));
f2=(L1.^2)+(L2.^2)+(L33.^2)-(L44.^2)-(2.*L1.*L2.*cos(A22-A1));

A332=2.*atan((-e2-sqrt((d2.^2)+(e2.^2)-(f2.^2)))./(f2-d2));

% Point E
Ex=Dx+L5.*cos(pi-A5);
Ey=Dy+L5.*sin(pi-A5);

E2x=Dx+L5.*cos(pi-A52);
E2y=Dy+L5.*sin(pi-A52);

A5=-A5; A4=-A4;
[A6,A7]=fourbarpos(L5,L4,L6,L7,A5,A4);

A52=-A52; A42=-A42;
[A62,A72]= fourbarpos(L5,L4,L6,L7,A52,A42);

Hx=Bx+(L33.*cos(A33));
Hy=By+L33.*sin(A33);

H2x=B2x+(L33.*cos(A332));
H2y=B2y+L33.*sin(A332);

Fx=Hx-L6.*cos(A6);
Fy=Hy-L6.*sin(A6);

F2x=H2x-L6.*cos(A62);
F2y=H2y-L6.*sin(A62);

Px=Hx+L66.*cos(A6+(pi/2));
Py=Hy+L66.*sin(A6+(pi/2));

P2x=H2x+L66.*cos(A62+(pi/2));
P2y=H2y+L66.*sin(A62+(pi/2));

A4=-A4; A5=-A5;

%%% Velocity Calculation

W2=2;

W3=-(L2.*W2.*sin(A2-A4))./(L3.*sin(A3-A4));
W4=(L2.*W2.*sin(A2-A3))./(L4.*sin(A4-A3));
W5=W4;

W33=-(L2.*W2.*sin(A2-A44))./(L33.*sin(A33-A44));
W44=(L2.*W2.*sin(A2-A33))./(L44.*sin(A44-A33));

A4=-A4; A5=-A5;
W6=(L5.*W5.*sin(A5-A7)-L44.*W44.*sin(A44-A7))./(L6.*sin(A6-A7));
W7=(L44.*W44.*sin(A44)-L5.*W5.*sin(A5)+L6.*W6.*sin(A6))./(L7.*sin(A7));

A4=-A4; A5=-A5;

% Acceleration

Alf2=0;

Alf3=((L2.*(W2.^2).*cos(A2-A4))+(L3.*(W3.^2).*cos(A3-A4))-(L4.*(W4.^2))-(L2.*sin(A4-A2)))./(L3.*sin(A4-A3));
Alf4=((L2.*Alf2.*sin(A3-A2))-(L2.*(W2.^2).*cos(A2-A3))-(L3.*(W3.^2))+(L4.*(W4.^2).*cos(A4-A3)))./(L4.*sin(A3-A4));
Alf5=Alf4;

Alf33=((L2.*(W2.^2).*cos(A2-A44))+(L33.*(W33.^2).*cos(A33-A44))-(L44.*(W44.^2))-(L2.*sin(A44-A2)))./(L33.*sin(A44-A33));
Alf44=((L2.*Alf2.*sin(A33-A2))-(L2.*(W2.^2).*cos(A2-A33))-(L33.*(W33.^2))+(L44.*(W44.^2).*cos(A44-A33)))./(L44.*sin(A33-A44));

A4=-A4; A5=-A5;
Alf7=((L44.*Alf44.*sin(A44-A6))+(L44.*(W44.^2).*cos(A44-A6))+(L6.*(W6.^2))-(L5.*Alf5.*sin(A5-A6))-(L5.*(W5.^2).*cos(A5-A6))-(L7.*(W7.^2).*cos(A7-A6)))./(L7.*sin(A7-A6));
Alf6=((L5.*Alf5.*sin(A5-A7))+(L5.*(W5.^2).*cos(A5-A7))+(L7.*(W7.*2))-(L44.*Alf44.*sin(A44-A7))-(L44.*(W44.^2).*cos(A44-A7))-(L6.*(W6.^2).*cos(A6-A7)))./(L6.*sin(A6-A7));

A4=-A4; A5=-A5;

figure(1)

x = A2;
link3 = A3;
link4 = A4;
link33 = A33;
link44 = A44;
link6 = A6;
link7 = A7;

plot(x,link3,'r', x,link4,'b',x,link33,'g',x,link44,'c',x,link6,'m',x,link7,'k')
legend('Link3','Link4','Link33','Link44','Link6','Link7')
grid on;
title('Jensen Links Position Analysis'); xlabel('Angle(\theta_2)')
ylabel('Position');

figure(2)

x = A2;
link3 = W3;
link4 = W4;
link33 = W33;
link44 = W44;
link6 = W6;
link7 = W7;

plot(x,link3,'r', x,link4,'b',x,link33,'g',x,link44,'c',x,link6,'m',x,link7,'k')
legend('Link3','Link4','Link33','Link44','Link6','Link7')
grid on;
title('Jensen Links velocity Analysis'); xlabel('Angle(\theta_2)')
ylabel('Velocity');

figure(3)

x = A2;
link3 = Alf3;
link4 = Alf4;
link33 = Alf33;
link44 = Alf44;
link6 = Alf6;
link7 = Alf7;

plot(x,link3,'r', x,link4,'b',x,link33,'g',x,link44,'c',x,link6,'m',x,link7,'k')
legend('Link3','Link4','Link33','Link44','Link6','Link7')
grid on;
title('Jensen Links Acceleration Analysis'); xlabel('Angle(\theta_2)')
ylabel('Acceleration');


function [T3,T4]= fourbarpos(L1,L2,L3,L4,T1,T2)
s1=-1;
s2=1;
P=2*L4*(L1*cos(T1)-L2*cos(T2));
Q=2*L4*(L1*sin(T1)-L2*sin(T2));
R=L1^2+L2^2-L3^2+L4^2-2*L1*L2*cos(T1-T2);
T4=2*atan2(-Q+(s1)*sqrt(P.^2+Q.^2-R.^2),R-P);

D=2*L3*(L2*cos(T2)-L1*cos(T1));
E=2*L3*(L2*sin(T2)-L1*sin(T1));
F=L1^2+L2^2+L3^2-L4^2-2*L1*L2*cos(T2-T1);
T3=2*atan2(-E+(s2)*sqrt(D.^2+E.^2-F.^2),F-D);
end



Bill of Materials

Items

QuantityCostSource
Arduino Uno1$24Amazon

5V Stepper Motor & Darlington Arrays

5$14Amazon
1 Set of Jumper Wires120$6.89Amazon
Power Module1$17Amazon
Computer Cable1$2.60Amazon

Lead Screw Set 

1$12Amazon
Caster Wheels1$10.79Amazon

Dowels, Wood, and 3D Printed Material

6FreeTIW
5 Sets of Ball Bearings 50$57.4Amazon
1 Set of Sliders2$17Amazon