close all
clear all

g = 9.81;


X0 = 10*.0254;
XF = 6*.0254;

F0 = -2.2*g;
d = 2.7*.0254;
M0 = -F0*d;

l = 4.5*.0254;

k_target = -0.05;  %N-m/deg
k_target = k_target*180/pi;  %N-m/rad

%kr = -k_target/(2*l*l);
%kl = -k_target/(2*l*l);

kr = 280;
kl = kr+F0*(-d)/(l*(X0-XF));
A = ones(2,2);  
A(1,2) = -1;
A(2,1) = X0-XF-(30*pi/180)*l;
A(2,2) = -(X0-XF+(30*pi/180)*l);

B(1,1) = -M0/(l*(X0-XF));
B(2,1) = (k_target*(30*pi/180)-M0)/l;


x = A\B;

kr = x(1);
kl = x(2);

alpha = -30:30;  %deg

F = kr*(X0-XF-l*alpha*pi/180)-kl*(X0-XF+l*alpha*pi/180);
M = F*l+M0;

figure
plot(alpha,M)
grid on
xlabel('alpha (deg)');
ylabel('M (N-m)');
legend(['kr = ' num2str(kr,'%3.0f') ' N/m    kl = ' num2str(kl,'%3.0f') ' N/m']);
title(['Kt = ' num2str(k_target*pi/180, '%3.2f') ' N-m/deg    XF = ' num2str(XF/.0254,'%2.0f') ' in    X0 = ' num2str(X0/.0254,'%2.0f') ' in    M0 = ' num2str(M0,'%3.1f') ' N-m']);  
