%========================================================================
% Análise de cames com seguidor oscilante com rolo.
% Criado em: 02/04/2014
%========================================================================

clear all
close all
clc

P=50;
Rc=25;
C1=150;
C2=50;
C3=125;
Rf=15;
NP=361;

for i=1:NP
    A(i)=2*pi*(i-1)/(NP-1);
    ef=10^(-6);       % tolerancia para o metodo de Newton Raphson
    % => valores iniciais das variaveis secundarias
    B0 = 0*pi/180;
    D0 = 10*pi/180;
    s=[B0; D0];
    f=[1;1];          %funçao f cuja norma é maior que ef
    while norm(f) > ef
        b=s(1);
        d=s(2);
        f = [ Rc*sin(A(i))+(P+Rf)*sin(d)+C3*cos(b)-C1;
             -Rc*cos(A(i))+(P+Rf)*cos(d)-C3*sin(b)-C2];
        J = [-C3*sin(b)  (P+Rf)*cos(d);
             -C3*cos(b) -(P+Rf)*sin(d)];
        s=s-inv(J)*f;
    end
    B(i)=s(1);
    D(i)=s(2);
    fL(i)=(Rc*sin(A(i)+D(i)))/(C3*cos(B(i)-D(i)));
    dL(i)=(-Rc*cos(A(i)+D(i)))/(C3*cos(B(i)-D(i)));
    fLL(i)=Rc/C3*(cos(B(i)-D(i))*cos(A(i)+D(i))*(1+dL(i))+sin(B(i)-D(i))*sin(A(i)+D(i))*(fL(i)-dL(i)))/(cos(B(i)-D(i))^2);
end

figure('name','Oscilante de rolo')
subplot(3,1,1)
plot(A*180/pi,B*180/pi)
xlim([0 360])
xlabel('A (grau)')
ylabel('B (grau)')
grid on
subplot(3,1,2)
plot(A*180/pi,fL)
xlim([0 360])
xlabel('A (grau)')
ylabel('fL ')
grid on
subplot(3,1,3)
plot(A*180/pi,fLL)
xlim([0 360])
xlabel('A (grau)')
ylabel('fLL ')
grid on

