View Full Version : RobotDrive with left joystick only? (XboxController)
Lesafian
06-02-2016, 23:34
Hey everyone.
I'm rather confused on how RobotDrive works. I'm planning on using the right joystick to move our sliding mechanism on top of our chassis. The code..
RobotDrive drive;
Joystick xboxController;
drive.arcadeDrive(xboxController);
does not specify what joystick axis it's utilizing. I'd like to know how to setup Arcade Drive (which I assume is the optimal for using only one stick) and specify it to use only the left stick.
Thank you in advance :)
minutebot
07-02-2016, 19:22
I'm not familiar with RobotDrive. We always set up our drive from scratch by making a DriveTrain subsystem (command base) or class (iterative).
It uses however many motor controllers your team uses which in our case is 4.
Here's some sample code:
public void arcadeDrive(double forwardThrottle, double turnThrottle) {
double leftVictorSPThrottle = forwardThrottle + turnThrottle;
double rightVictorSPThrottle = -forwardThrottle + turnThrottle;
leftBackVictorSP.set(leftVictorSPThrottle);
leftFrontVictorSP.set(leftVictorSPThrottle);
rightBackVictorSP.set(rightVictorSPThrottle);
rightFrontVictorSP.set(rightVictorSPThrottle);
}
You set motor values from the drive train methods. To receive input you use an XBox controller or joystick like you did and you can use the Joystick.getY() method to use the y axis for forward throttle and Joystick.get() method to use the x axis for turning throttle.
Here's a link to the 2016 WPILIB API which has all the classes like joystick and the thing they can do (methods).
http://first.wpi.edu/FRC/roborio/release/docs/java/
Dan Waxman
07-02-2016, 21:31
This is my first year, but I found it much easier to write my own drive class with a few other programmers. A ton easier to adjust to driver feedback and hotfix as needed.
I am going to assume you are using a XboxController class. If so here is the code my team used last year.
Teleop {
double rotateValue = Xbox.getLeftX();
double moveValue = Xbox.getLeftY();
mainDrive.arcadeDrive(rotateValue, moveValue);
}
Make sure if you are using a XboxController class that the axis ports are labeled starting with 0 like so.
LEFT_X_AXIS = 0,
LEFT_Y_AXIS = 1,
L_TRIGGER = 2,
R_TRIGGER = 3,
RIGHT_X_AXIS = 4,
RIGHT_Y_AXIS = 5,
DPAD_LR = 6;
I hope this helped.
geniusadam69
09-02-2016, 09:36
The arcade drive method has a lot of different parameters sets, including (double move, double rotate) and (GenericHID stick).
The arcadeDrive(GenericHID stick) method requires a GenericHID item, which Joystick is. Since your xboxController is a Joystick and Joystick extends GenericHID, then this is the method you're calling. What we found is that using an Xbox Controller and declaring it as Joystick will result in only the left joystick being recognized directly. The right joystick is available, but it's buried deeper. So, your current method will work just fine for arcade drive.
The better way to use an Xbox Controller is to write your own class called XboxController and provide methods to access all of the features of the controller. Typically you will provide a double back for the joystick positions like MaraiGG used. Then you can expose both joysticks in a clean way. You'll then use the other parameter set: arcadeDrive(double move, double rotate)
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.