function F = MotorConnection(body1,bodies,n,name,p_a1,p_a2,Spring_Force_Coeffs,Damping_Force_Coeffs)

j = 0;
for i = 1:length(bodies)
name2 = get(bodies{i},'name');
  if(strcmp(name2,name))
    j = i;
  end
end
if(j == 0)
   error('ERROR: Can not find name match in MotorConnection');
end

body2 = bodies{j};

dt = get(body1,'dt');

%disp(['Computing Forces on ',get(body1,'name'),' due to ',get(body2,'name')]);

sv1 = get(body1,'sv');
sv2 = get(body2,'sv');

xo1 = get(body1,'x0');
xo2 = get(body2,'x0');
pos1 = sv1(1:6);
vel1 = sv1(7:12);
pos2 = sv2(1:6);
vel2 = sv2(7:12);

[Elongation,ElongationRate,s] = TetherElongations(xo1,pos1,vel1,p_a1,xo2,pos2,vel2,p_a2);
F = zeros(1,6);

if(Elongation > 0)
  SpringTension = ppval(Spring_Force_Coeffs,Elongation);
  F(1) = SpringTension*s(1);
  F(3) = SpringTension*s(3);

  DampingTension = ppval(Damping_Force_Coeffs,ElongationRate);

  F(1) = F(1) + DampingTension*s(1);
  F(3) = F(3) + DampingTension*s(3);
end


R = eye(3);
R(1,1) = cos(pos1(5)); R(1,3) = sin(pos1(5));  
R(3,1) = -R(1,3);  R(3,3) = R(1,1);
p_size = size(p_a1);
if(p_size(2) > p_size(1)) 
    p_a1 = p_a1'; 
end
M  = cross(R*p_a1,F(1:3));

%if(~isnan(s(3)))
%  M(2) = M(2)+100*s(3)*cos(2*pi*n*dt/10);  %Add artificial Motor Torque
%end


F(5) = M(2);


end





