%Example calculation for rough estimates of ram size/geometry.

close all
clear all

E = 25000;  %psi


    d_theta = (-5:.01:5)*pi/180;

phi_0 = 45*pi/180;

r = [6 12 18]; %Inches.  Attachment radius


Dc = 1.5;  %Inches.  Ram Diameter
%L = 1.5*r; %17.0;  %Inches.  Ram Length
Ac = 0.25*pi*Dc^2;

d = 3/8;  %Inches.  Hose Diameter
l = 24;  %Inches.  Hose Length
Ah = 0.25*pi*d^2;

ClevisPlay = 0.02;  %Inches, Total Play

%Simplest calculation, ram at centerpoint, only non-rod side of piston
%considered (worst case scenario)

figure
hold all;

for i = 1:length(r)
    L = 1.5*r(i);
    Vi = Ac*L/2+l*Ah;
    dL = r(i)*sin(d_theta)*sin(phi_0);
    
    for j = 1:length(dL)
        if(d_theta(j) < 0)
            dL(j) = dL(j) + ClevisPlay/2;
            if(dL(j) > 0)
                dL(j) = 0;
            end
        end
        if(d_theta(j) > 0)
            dL(j) = dL(j) - ClevisPlay/2;
            if(dL(j) < 0)
                dL(j) = 0;
            end
        end
    end
    dV = Ac*dL;
    
    dP = E*dV/Vi;
    F = Ac*dP;
    T = F*r(i)*sin(phi_0);
    
    MaxTorque = Ac*3000*r(i)*sin(phi_0);
    
    plot(d_theta*180/pi,T);
    leg_str{i} = ['Cylinder: Max Torque = ' num2str(MaxTorque,5) ' in-lbs   r = ' num2str(r(i)) ' in'];
    
end



%HTR10
Backlash = .5*pi/180; 
L = 14;  %Inches, from spec sheet
Disp = 12.5;  %In^3 from spec sheet
l = L;
Vi = Disp/2+l*Ah;  %In^3
Ac = (Disp/2)/(L/2);
r = 1.5;  %Estimated from spec sheet
for j = 1:length(d_theta)
   dL(j) = 0;
   if(d_theta(j) < -Backlash/2)
       dL(j) = r*sin(d_theta(j)+Backlash/2);
   end
   if(d_theta(j) > Backlash/2)
       dL(j) = r*sin(d_theta(j)-Backlash/2);
   end   
end

dV = Ac*dL;
    
dP = E*dV/Vi;
F = Ac*dP;
T = F*r;

plot(d_theta*180/pi,T);
leg_str{i} = ['HTR10: Max Torque = 10000 in-lbs '];
    


xlabel('theta (deg)');
ylabel('Torque (in-lbs)');
grid on;
legend(leg_str);


