% cam and follower
% velocity and acceleration analysis
% differential method

clear; clc; close all

% revolute joint at A = O1 
Rc = 0.1;     % (m) radius of the circle of the cam
e  = 0.04;    % (m) distance from follower to A
RO = 0.5*Rc;  % AO = RO
Rf = 0.0025;  % (m)

% radius OC
R  = Rc + Rf; 

syms phi(t)

% position of O = Oc (rO_ = AO_)
xO = RO*cos(phi); 
yO = RO*sin(phi); 
rO_ = [xO, yO , 0];

% angle between OC and x-axis
psi = acos((e-xO)/R);  

% position of C (rC_ = AC_)
xC = e; 
yC = yO+R*sin(psi) ; 
rC_ = [xC, yC, 0];

vC2_ = diff(rC_, t); 
aC2_ = diff(vC2_,t); 

n = 30; % (rpm)  driver link
omega1 = pi*n/30; 
alpha1 = 0; 
phi1   = pi/3; 

slist={diff(phi(t),t,2), diff(phi(t),t), phi(t)}; 
nlist={alpha1,  omega1, phi1}; %numerical values for slist

vC2n_ = eval(subs(vC2_,slist,nlist));
aC2n_ = eval(subs(aC2_,slist,nlist));

fprintf('vC2_ = [%g, %6.3f, %g] (m/s)\n',vC2n_  ) 
fprintf('aC2_ = [%g, %6.3f, %g] (m/s^2)\n',aC2n_) 

% eof

% vC2_ = [0.000,  0.058, 0.000] (m/s)
% aC2_ = [0.000, -0.650, 0.000] (m/s^2)


