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.
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.
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.
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
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.
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).
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-content/uploads/2009/09/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.