function T = TensionCommand3(p,v,Elongation,ElongationRate,n,dt)


persistent cable_out;
if(isempty(cable_out))
    cable_out = 10;
end

frac = mod(n,1);
n = floor(n);

% This function implements a depth control loop for the ESP by returning a
% tension (torque) target for the motor controller based upon the current depth of
% the ESP and the target depth.
% Arguments:    p = 6 dof position of the ESP relative to the global coordinate system.
%               v = 6 dof velocity of the ESP relative to the global coordinate system.
%               TetherOut = current amount of tether payed out.
%               TetherRate = current payout speed.  Positive equal payout.
%               t = current time in seconds.

  [TargetDepth TargetDepthRate] = TargetDepth_Profiling(n*dt);  %Get Target depth for this time.

  k = 1;       %Proportional gain (m/s per m);
  b = .1;       %Derivative gain (m/s per m/s);
  
  
  Vmin = [0]*4.45;  %Min Tension Request (N) 
  Vmax = [500] *4.45;
  depth_error = TargetDepth-p(3);
  depth_error_rate = TargetDepthRate-v(3);

  V = k*depth_error+b*depth_error_rate;
  
  
  cable_out = cable_out+V*frac*dt;