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 01-28-2011 07:10 PM

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 01-28-2011 07:12 PM

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 01-28-2011 07:48 PM

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 01-28-2011 07:51 PM

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 01-28-2011 08:52 PM

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 01-28-2011 09:31 PM

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 01-28-2011 09:44 PM

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 01-29-2011 08:58 PM

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

Shantali 01-30-2011 08:00 PM

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 01-30-2011 08:05 PM

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 12:18 AM

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 02-03-2011 11:51 AM

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 02-03-2011 01:44 PM

Re: Single Joystick Tank Drive
 
Yup

Ether 02-03-2011 01:48 PM

Re: Single Joystick Tank Drive
 
Try a different joystick.



rsisk 02-03-2011 03:12 PM

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).


All times are GMT -5. The time now is 08:50 AM.

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