Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Single Joystick Tank Drive (http://www.chiefdelphi.com/forums/showthread.php?t=90356)

Shantali 28-01-2011 19:10

Single Joystick Tank Drive
 
Hi all,

I'm programming for rookie team. I barely have any experience with Java or robotics for that matter.

My goal is to make the robot drive with a single joystick in differential "tank" drive.
Here's the schematic that I found that would be ideal...
http://web.goodrobot.com/blog/wp-con.../tankdrive.png

I'm using Iterative robot template.

Any help would be greatttly appreciated!

J

tomy 28-01-2011 19:12

Re: Single Joystick Tank Drive
 
the only thing i can think of is you do something like this

Code:

...tankDrive(leftstick,leftstick)
that might work

Joe Ross 28-01-2011 19:48

Re: Single Joystick Tank Drive
 
What you are describing is similar to (or maybe identical) to arcade drive, which is already built in.

Quote:

Originally Posted by tomy (Post 1010656)
the only thing i can think of is you do something like this

Code:

...tankDrive(leftstick,leftstick)
that might work

This would result in the robot going forward and backwards with the left stick y axis, but never turning.

sjspry 28-01-2011 19:51

Re: Single Joystick Tank Drive
 
I can't find the related documentation/source (I'll keep looking and revise my answer as necessary), but it's probably not possible to do with the pre-made TankDrive class. And actually, I see more in common with the ArcadeDrive and your desired style than Tank.

I would say that you'll either need to find some code a previous team wrote or extend Tank/ArcadeDrive (or just starting from scratch, it'll end up being a combination of both, really). And take the ArcadeDrive code but set the two sets of motors depending on the combination of x,y values.

Ether 28-01-2011 20:52

Re: Single Joystick Tank Drive
 
Quote:

Originally Posted by Shantali (Post 1010655)
Hi all,

I'm programming for rookie team. I barely have any experience with Java or robotics for that matter.

My goal is to make the robot drive with a single joystick in differential "tank" drive.
Here's the schematic that I found that would be ideal...
http://web.goodrobot.com/blog/wp-con.../tankdrive.png

I'm using Iterative robot template.

Any help would be greatttly appreciated!

J


Try this:

// Xj,Yj are the joystick readings

L = -Yj+Xj;

R = -Yj-Xj;

max=abs(L); if(max<abs(R)) max=abs(R);

if(max>1){L/=max; R/=max;}

send "L" to the left wheels and "R" to the right wheels




Bot190 28-01-2011 21:31

Re: Single Joystick Tank Drive
 
As far as I can tell from your description, you are describing Arcade drive exactly. It takes an x and y axis, and outputs to 2 or 4 motors similar to tank drive.

In other word, full left on the joystick would make the right side go full forward, and left side go full backwards. Full right would make right go full backward, and left go full forwards. And so on.

Ether 28-01-2011 21:44

Re: Single Joystick Tank Drive
 
Quote:

Originally Posted by Bot190 (Post 1010750)
As far as I can tell from your description, you are describing Arcade drive exactly. It takes an x and y axis, and outputs to 2 or 4 motors similar to tank drive.

In other word, full left on the joystick would make the right side go full forward, and left side go full backwards. Full right would make right go full backward, and left go full forwards. And so on.


Some drivers find the following a bit more intuitive to drive:

if(Yj<=0){L=-Yj+Xj; R=-Yj-Xj;}

else {L= -Yj-Xj; R=-Yj+Xj;}

max=abs(L); if(max<abs(R))max=abs(R);

if(max>1){L/=max; R/=max;}

send "L" to the left wheels and "R" to the right wheels



Patrick Chiang 29-01-2011 20:58

Re: Single Joystick Tank Drive
 
Use the arcade drive method in Joystick. It will do EXACTLY what you want it to do.

Shantali 30-01-2011 20:00

Re: Single Joystick Tank Drive
 
Thanks for the responses!

I got it working with
Code:

m_robotDrive.arcadeDrive(m_driveStick.getY(), m_driveStick.getX());
It does everything as intended, but there's something i'd like to change.

Right now it goes forward, back, turns on the spot and strafes forward perfectly.

But if trying to pull the joystick back-left, the left motor is working 100% backwards, which essentially moves the robot's back to the right. If pulling back-right, the right motor is working 100% backwards, which moves the robot back to the left. Intuitively when trying to do that, you'd expect it to work like a car would, turning left would make the back go left..

I would like to change that so drivers could have it more intuitively.

I will post when/if I figure it out. Again, thanks everyone for taking the time.

J

Ether 30-01-2011 20:05

Re: Single Joystick Tank Drive
 
Quote:

Originally Posted by Shantali (Post 1011985)
But if trying to pull the joystick back-left, the left motor is working 100% backwards, which essentially moves the robot's back to the right. If pulling back-right, the right motor is working 100% backwards, which moves the robot back to the left. Intuitively when trying to do that, you'd expect it to work like a car would, turning left would make the back go left..

I would like to change that so drivers could have it more intuitively.

That's what this is supposed to do. Try it.



Shantali 02-02-2011 00:18

Re: Single Joystick Tank Drive
 
I was trying to work around that using
Code:

double m_y = m_driveStick.getY();
double m_x = m_driveStick.getX();
if (m_y >= 0) //the Y axis is inverted, so going forward is negative number
    m_x = 0-m_x; //inverting X value
m_robotDrive.arcadeDrive(m_y, m_x);

The problem I faced with that was that the joystick wasn't giving me a perfect 0.. I added a simple println statement to get the y values, and it ranged anywhere from -0.3 to 0.3...

Ether, it looks like your solution
Quote:

if(Yj<=0){L=-Yj+Xj; R=-Yj-Xj;}
would have the same problem.

I tried something like if m_y >= -0.3, but it results in motors rapidly switching directions if starting slowly..

Another possible solution would be treating anything within .2 or so from the axis as 0.. but it doesn't seem like the best way of doing it either.

Thanks in advance,
j.

Ether 03-02-2011 11:51

Re: Single Joystick Tank Drive
 
Quote:

Originally Posted by Shantali (Post 1013926)
The problem I faced with that was that the joystick wasn't giving me a perfect 0.. I added a simple println statement to get the y values, and it ranged anywhere from -0.3 to 0.3...

Are you saying you got readings in the range -0.3 to 0.3 for Y when the joystick was in the null position?



Shantali 03-02-2011 13:44

Re: Single Joystick Tank Drive
 
Yup

Ether 03-02-2011 13:48

Re: Single Joystick Tank Drive
 
Try a different joystick.



rsisk 03-02-2011 15:12

Re: Single Joystick Tank Drive
 
I believe you can also go into the windows control panel, find the Game Controllers adapter and use it to center the joystick (ie, the joystick reads 0,0 when centered).

Shantali 03-02-2011 15:55

Re: Single Joystick Tank Drive
 
It does say 0.0 at the beginning, but after driving it for a bit then letting go, it doesn't always center perfectly.

Both of our joysticks do that :\

Ether 03-02-2011 16:00

Re: Single Joystick Tank Drive
 
Quote:

Originally Posted by Shantali (Post 1015020)
It does say 0.0 at the beginning, but after driving it for a bit then letting go, it doesn't always center perfectly.

Both of our joysticks do that :\

Clean the Mountain Dew out of them.



Shantali 03-02-2011 17:19

Re: Single Joystick Tank Drive
 
They're clean outta the box ones... :'(

Ether 03-02-2011 17:30

Re: Single Joystick Tank Drive
 
Quote:

Originally Posted by Shantali (Post 1015072)
They're clean outta the box ones... :'(

Maybe there's an error in your software?

Try loading the default code that came with the LabVIEW installation and run it and see if it does the same thing.




Shantali 05-02-2011 02:28

Re: Single Joystick Tank Drive
 
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.

Ether 05-02-2011 12:55

Re: Single Joystick Tank Drive
 
Quote:

Originally Posted by Shantali (Post 1015989)
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



Shantali 05-02-2011 18:09

Re: Single Joystick Tank Drive
 
I've tried having a dead zone, treating everything within 0.1 from the axis, as 0.
Then problem is that when you move the joystick all the way right to turn on the spot, then move it slightly forward, then slightly backwards, you can hear the motors clicking as they're going from "left forward right backwards" to "left backwards right forward".

I tried to play around with giving it more of a dead zone when turning on the spot
Code:

//x, y = joystick position
if (abs(x) > 0.5){
  if (abs(y) < 0.3)
      y = 0;}

to fix that, but it didn't work that well either.

I think my driver will have to get used to driving the way it was originally, with swapped reverses.

Ether 06-02-2011 09:11

Re: Single Joystick Tank Drive
 
Quote:

Originally Posted by Shantali (Post 1016387)
I think my driver will have to get used to driving the way it was originally, with swapped reverses.

Have you considered doing something a little more advanced?

You could install the gyro and use it so that the driver interface would allow the driver to issue field-centric commands. The driver points the joystick, and the vehicle turns and goes in that direction at a speed determined by the magnitude of the joystick displacement.



Shantali 07-02-2011 19:58

Re: Single Joystick Tank Drive
 
I love the concept, but it's a little bit more advanced than I can manage at the moment :\ This is our rookie year, and there's a lot more to figure out. Maybe in the future!

Thanks so much for your help :)

maleche 23-03-2011 15:40

Re: Single Joystick Tank Drive
 
This is a great subject. I am working on the same concept using Visual Basic. I have a scaled Picture box with -128,128, 128,128 set as the scaled box points. Center is 0 (zero) with adjustable deadbands in both X & Y centered.

Moving a joystick OR mouse sends the Xj, Yj or Xm, Ym directly to the motor controller, after calculations.

I am using pythagorean for vector speed (Vel) based on joystick/mouse angle and distance from center. This works great in direct Y and -Y vectors ( both treads move at same speed and direction). -X, X will rotate Left and Right tank treads in opposite directions at equal speed. When steering slightly left and forward (Xj=-20, Yj=50) the total vector is the Sin(Angle)* Vel. This does well when transitioning from full forward to left/right steering. I'm still working out some bugs. I have not considered Tan2 yet or using a Gyro to steer by. The motor controller is a Sabertooth 2x50 and using 0-127 as speed with direction tokens.
One thing to consider however, is when going from full forward to all-stop. This can tip the robot or cause problems with stability. I programmed a ramp-down speed Vel=Vel-ramp^2. this allow VERY smooth and quick stopping transitions.
Keep in touch!
Doyle

siggy2xc 23-03-2011 18:31

Re: Single Joystick Tank Drive
 
As for the gyro-guided driving, I know that labview has a rotate axis vi built in. Not sure if java has it or not but the challenge is finding a way to get it to turn completely because as it comes closer to the direction your pointing the joystick the less exaggerated the turn becomes because you are moving closer to 0 on the x-axis and if your turning too fast then your gyro loses its accuracy. Good luck :)


All times are GMT -5. The time now is 11:21.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi