My team is incredibly confused on how to access Xbox joysticks in Java. We thought it was just “getRawAxis” like previous years but that doesn’t seem to be working. Can someone show example code, even just to access the axis of a joystick?
We used WPILib’s Joystick class’s getRawAxis() method. LEFT_STICK_Y is the axis on the XBox that we defined.
Our full code for using an XBox controller can be found here.
super your Xbox controller?
Super is the joystick class from wpilib which creates a joystick to use the xbox controller
Here’s our drive subsystem’s default command:
XboxController driverController = new XboxController(OIConstants.DRIVER_CONTROLLER_PORT); robotDrive .setDefaultCommand(new RunCommand(() -> robotDrive.arcadeDrive(-driverController.getY(GenericHID.Hand.kLeft), driverController.getX(GenericHID.Hand.kRight)), robotDrive));
Never heard of you having to super it. Also, think about how you wrote that line:
You are going to get the left stick axis of the super… Doesn’t really make sense. The dot syntax needs to be attached to your joystick.
The class he linked to extends Joystick, so the super is correct.
Ok, just never seen that so it looks weird to me. And not having the getaxis on a specific controller is weird to me.
I agree with @sargeanthost… Using a
Joystick (or subclass) object instead of just using the
XboxController class they provide is a bit weird to me. Likely just due to reusing legacy code and never updating it, if I were to guess
Thanks for sharing this. We’re in the middle of trying to use it. We were able to use it to get the dpad buttons and one stick working, but not the triggers. Are you using the triggers? Have they been tested? I’m wondering if the axis numbers that you input into super.getRawAxis() aren’t right.
In fact, after more testing, it looks like this indeed is the case. I think the rightStick’s X axis is actually being fed to the left Trigger, for example. Meaning when I moved the right stick left and right, we got input from your getLeftTrigger() method.
I think we may have to take what you’ve done and adapt it to extend from XboxController, to get these Axis right.
i believe that you just need to have an XboxController object and call getRawAxis(…)
Here is our RobotContainer class, which has all of our controller stuff and here is one of our commands utilizing these inputs from a DoubleSupplier
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.