View Single Post
  #21   Spotlight this post!  
Unread 05-02-2011, 12:55
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Single Joystick Tank Drive

Quote:
Originally Posted by Shantali View Post
After updating and running stuff again, joysticks center within 0.05 from center. Still not a perfect 0.

However, after playing around with various types of if statements, I'm starting to get the impression that the default way is the only way of making it operate smoothly.

If you look at the http://web.goodrobot.com/blog/wp-con.../tankdrive.png diagram clockwise, by default we get the "motor forward x3, motor off, motor backward x3, motor off" pattern.. That way there is never a situation where the motor has to abruptly switch directions.

If swapping the reverse directions, we get "motor forward x3, motor backward x3, motor off, motor backward, motor off". That way at some point there's an abrupt change in motors from going backwards to forward. That is the issue I've been having and at this point I see no way of avoiding it.

If I'm wrong, please correct me.
I think you are correct.

I believe the pseudo-code below implements the behavior shown in the diagram you referenced:

Code:
float Xj, Yj, L, R;

float max, sum, dif;

max = abs(Xj); if (abs(Yj)>max) max = abs(Yj);

sum = Xj+Yj; dif = Xj-Yj;

if(Yj<=0)
 {
 if(Xj>=0)
  {
  // first quadrant
  L =  max;
  R = -sum;
  }
 else
  {
  // second quadrant
  L =  dif;
  R =  max;
  }
 }
else
 {
 if(Xj>=0)
  {
  // fourth quadrant
  L =  dif;
  R = -max;
  }
 else
  {
  // third quadrant
  L = -max;
  R = -sum;
  }
 }
If you want to reverse the direction of rotation when backing up, I believe the following modified code would do that (note the addition of some deadband to address your concern about abrupt motor direction changes*):

Code:
float Xj, Yj, L, R;

float max, sum, dif, deadband;

if (Yj>-deadband)&&(Yj<deadband) Yj=0;

max = abs(Xj); if (abs(Yj)>max) max = abs(Yj);

sum = Xj+Yj; dif = Xj-Yj;

if(Yj<=0)
 {
 if(Xj>=0)
  {
  // first quadrant
  L =  max;
  R = -sum;
  }
 else
  {
  // second quadrant
  L =  dif;
  R =  max;
  }
 }
else
 {
 if(Xj>=0)
  {
  // fourth quadrant
  L = -max;
  R =  dif;
  }
 else
  {
  // third quadrant
  L =  -sum;
  R =  -max;
  }
 }

*if using Jaguars, you may want to experiment with putting the jumper in the "coast" setting to avoid abrupt motor braking when transitioning into/out_of the deadband zone



Last edited by Ether : 05-02-2011 at 14:54. Reason: added footnote; corrected modified code
Reply With Quote