a. Matlab Code

%Peak-a-Bevo Robotics_Project_V3
%Lila Bernhardt
clc; clear all; close all;
 
%Kinematic Analysis using a 4-Bar Crank Slider Approximation
%Origin:
Ox = 4;
Oy = 4;
 
%Variables:
a=1.6; 
b=6.7;
ci=4.5;
d=9.6;
Theta1=95.6;
k = 6.2;
f = 9.2;
Theta6 = 102.5;
 
%Initial Condition: Solve for Theta 3 and Theta 4 at Theta 2 = 0
Theta2i = 0;
[T1i,T2i,T3i,T4_i] = fourbarpos(a, b, ci, d, Theta1, Theta2i, -1);
Theta4i = T4_i + 180; %T_4 is supplementary angle of Theta0
bx=b*cosd(T3i);
L1 = bx + a;
L2 = L1 - d*cosd(Theta1);
 
%Position analysis of Theta 3, Theta 4, and c with input of Theta 2 = [0, 360]
for i=1:360
   T2(i) = i;
   T1(i) = Theta1;
   T3(i) = acosd((L1-a*cosd(T2(i)))/(b));
   T4(i) = atand( (d*sind(T1(i)) - b*sind(T3(i)) - a*sind(T2(i)))/ (-L2) )+180;
   c(i) = -L2/cosd(T4(i));  
end
 
%Plot Theta3 Theta4
figure(1)
grid on
subplot(2,1,1);
sgtitle('Theta 3 and Theta 4')
  plot(T3, 'g')
  grid on
  xlim([0 360])
  ylim([50 90])
  xlabel("Theta 2 (degrees)")
  ylabel("Theta 3 (degrees)")
subplot(2,1,2);
  plot(T4, 'r')
  grid on
  xlim([0 360])
  xlabel("Theta 2 (degrees)")
  ylabel("Theta 4 (degrees)")
  hold off
 
for i=1:360
   Hy(i) = a*sind(T2(i)) +b*sind(T3(i)) + k*sind(T4(i)) +3 + Oy;
   Py(i) = a*sind(T2(i)) +b*sind(T3(i)) + 1.5*sind(T4(i)) + Oy;
   T5(i) = atand((13-Py(i))/1.2);
   f(i) = 1.2/cosd(T5(i));
   Ay(i) = Py(i) + 6.5*sind(T5(i) + 25);
   Ax(i) = .6 + 6.5*cosd(T5(i) + 25);
end
figure(2)
  plot(Hy)
  hold on
  plot(Ay)
  legend('Head', 'Hands')
  grid on
  title('Vertical Movement of Head and Hands')
  xlabel("Theta 2 (degrees)")
  ylabel("y-position (cm)")
  xlim([0 360]) 
  ylim([10 19])
 
figure(3)
plot(Ax)
  title('Horizontal Movement of Hands')
  xlabel("Theta 2 (degrees)")
  ylabel("x-position (cm)")
  grid on
  xlim([0 360])