|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Java programming of an XBox Controller
How could we use an xbox controller to control our robot?
Does anyone have a drawing of which buttons correspond to what numbers and what axis' correspond to what numbers? Any help would be appreciated! |
|
#2
|
||||
|
||||
|
Re: Java programming of an XBox Controller
Yes, you could, but I would recommend against it. The Xbox Controller has fairly large (and inconsistent) deadzones around the center of the sticks. The logitech joysticks provide better accuracy.
Quote:
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.usfirst.Rotoraptors.controls.hids;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.*;
/**
*
* @author Daniel
*/
public class XboxController {
private Joystick m_pad;
public XboxController(int port) {
m_pad = new Joystick(port);
}
public double getLeftX() {
return m_pad.getRawAxis(LEFT_X_AXIS);
}
public double getLeftY() {
return m_pad.getRawAxis(LEFT_Y_AXIS);
}
public double getRightX() {
return m_pad.getRawAxis(RIGHT_X_AXIS);
}
public double getRightY() {
return m_pad.getRawAxis(RIGHT_Y_AXIS);
}
public double getTriggers() {
return m_pad.getRawAxis(TRIGGERS);
}
public double getDpadX() {
return m_pad.getRawAxis(DPAD_LR);
}
public double applyDeadband(int axis) {
if(Math.abs(m_pad.getRawAxis(axis)) < .1) {
return 0;
} else {
return axis;
}
}
// Creates buttons
public Button X = new JoystickButton(m_pad, BUTTON_X);
public Button Y = new JoystickButton(m_pad, BUTTON_Y);
public Button A = new JoystickButton(m_pad, BUTTON_A);
public Button B = new JoystickButton(m_pad, BUTTON_B);
public Button lBumper = new JoystickButton(m_pad, BUMPER_L);
public Button rBumper = new JoystickButton(m_pad, BUMPER_R);
public Button start = new JoystickButton(m_pad, BUTTON_START);
public Button back = new JoystickButton(m_pad, BUTTON_BACK);
public Button lStick = new JoystickButton(m_pad, LEFT_STICK_PRESS);
public Button rStick = new JoystickButton(m_pad, RIGHT_STICK_PRESS);
public boolean getButton(int btn) {
return m_pad.getRawButton(btn);
}
// Axis indexes:
public static final int
LEFT_X_AXIS = 1,
LEFT_Y_AXIS = 2,
TRIGGERS = 3,
RIGHT_X_AXIS = 4,
RIGHT_Y_AXIS = 5,
DPAD_LR = 6;
// Button mappings:
public static final int
BUTTON_A = 1,
BUTTON_B = 2,
BUTTON_X = 3,
BUTTON_Y = 4,
BUMPER_L = 5,
BUMPER_R = 6,
BUTTON_BACK = 7,
BUTTON_START = 8,
LEFT_STICK_PRESS = 9,
RIGHT_STICK_PRESS = 10;
}
Code:
XboxController driverXbox = new XboxController(1);
XboxController operatorXbox = new XboxController(2);
Code:
driverXbox.A.whenPressed(doSomething()); Last edited by F22Rapture : 08-01-2013 at 21:48. |
|
#3
|
||||
|
||||
|
How much do said logitech controllers cost!
|
|
#4
|
||||
|
||||
|
Re: Java programming of an XBox Controller
The Attack 3s should have come with your Rookie KoP... if not, $20-$25
If you're dead-set on using a gamepad, the Logitech F310 is about the same price, and also has both thumbsticks at the bottom of the controller so tank drive is less awkward. And they seem to have less deadzone than the Xbox controllers. |
|
#5
|
||||
|
||||
|
How big is the deadzone on an xbox controller?
|
|
#6
|
||||
|
||||
|
Re: Java programming of an XBox Controller
Depending on the controller, 15-20%
|
|
#7
|
||||
|
||||
|
Have you personally tested these and which is this info based on.
|
|
#8
|
||||
|
||||
|
Re: Java programming of an XBox Controller
I pulled up Xpadder and looked at the raw ouput. Mine was about 18%. Some seem to have more, some less.
|
|
#9
|
||||
|
||||
|
Re: Java programming of an XBox Controller
|
|
#10
|
||||
|
||||
|
Quote:
|
|
#11
|
||||
|
||||
|
Re: Java programming of an XBox Controller
Very. We've had no issues with it.
|
|
#12
|
||||
|
||||
|
Do you feel the deadzones affected your playing
|
|
#13
|
||||
|
||||
|
Re: Java programming of an XBox Controller
We don't really use the joysticks (we do our driving with the Attack 3's), but when we do we just have extra wide deadbands. We've found our controller sometimes doesn't return exactly to zero.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|