Package edu.wpi.first.wpilibj
Class XboxController
java.lang.Object
edu.wpi.first.wpilibj.GenericHID
edu.wpi.first.wpilibj.XboxController
public class XboxController extends GenericHID
Handle input from Xbox 360 or Xbox One controllers connected to the Driver Station.
This class handles Xbox input that comes from the Driver Station. Each time a value is requested the most recent value is returned. There is a single class instance for each controller and the mapping of ports to hardware buttons depends on the code in the Driver Station.
Only first party controllers from Microsoft are guaranteed to have the correct mapping, and only through the official NI DS. Sim is not guaranteed to have the same mapping, as well as any 3rd party controllers.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XboxController.Axis
Represents an axis on an XboxController.static class
XboxController.Button
Represents a digital button on an XboxController.Nested classes/interfaces inherited from class edu.wpi.first.wpilibj.GenericHID
GenericHID.HIDType, GenericHID.RumbleType
-
Constructor Summary
Constructors Constructor Description XboxController(int port)
Construct an instance of a controller. -
Method Summary
Modifier and Type Method Description BooleanEvent
a(EventLoop loop)
Constructs an event instance around the A button's digital signal.BooleanEvent
b(EventLoop loop)
Constructs an event instance around the B button's digital signal.BooleanEvent
back(EventLoop loop)
Constructs an event instance around the back button's digital signal.boolean
getAButton()
Read the value of the A button on the controller.boolean
getAButtonPressed()
Whether the A button was pressed since the last check.boolean
getAButtonReleased()
Whether the A button was released since the last check.boolean
getBackButton()
Read the value of the back button on the controller.boolean
getBackButtonPressed()
Whether the back button was pressed since the last check.boolean
getBackButtonReleased()
Whether the back button was released since the last check.boolean
getBButton()
Read the value of the B button on the controller.boolean
getBButtonPressed()
Whether the B button was pressed since the last check.boolean
getBButtonReleased()
Whether the B button was released since the last check.boolean
getLeftBumper()
Read the value of the left bumper (LB) button on the controller.boolean
getLeftBumperPressed()
Whether the left bumper (LB) was pressed since the last check.boolean
getLeftBumperReleased()
Whether the left bumper (LB) was released since the last check.boolean
getLeftStickButton()
Read the value of the left stick button (LSB) on the controller.boolean
getLeftStickButtonPressed()
Whether the left stick button (LSB) was pressed since the last check.boolean
getLeftStickButtonReleased()
Whether the left stick button (LSB) was released since the last check.double
getLeftTriggerAxis()
Get the left trigger (LT) axis value of the controller.double
getLeftX()
Get the X axis value of left side of the controller.double
getLeftY()
Get the Y axis value of left side of the controller.boolean
getRightBumper()
Read the value of the right bumper (RB) button on the controller.boolean
getRightBumperPressed()
Whether the right bumper (RB) was pressed since the last check.boolean
getRightBumperReleased()
Whether the right bumper (RB) was released since the last check.boolean
getRightStickButton()
Read the value of the right stick button (RSB) on the controller.boolean
getRightStickButtonPressed()
Whether the right stick button (RSB) was pressed since the last check.boolean
getRightStickButtonReleased()
Whether the right stick (RSB) button was released since the last check.double
getRightTriggerAxis()
Get the right trigger (RT) axis value of the controller.double
getRightX()
Get the X axis value of right side of the controller.double
getRightY()
Get the Y axis value of right side of the controller.boolean
getStartButton()
Read the value of the start button on the controller.boolean
getStartButtonPressed()
Whether the start button was pressed since the last check.boolean
getStartButtonReleased()
Whether the start button was released since the last check.boolean
getXButton()
Read the value of the X button on the controller.boolean
getXButtonPressed()
Whether the X button was pressed since the last check.boolean
getXButtonReleased()
Whether the X button was released since the last check.boolean
getYButton()
Read the value of the Y button on the controller.boolean
getYButtonPressed()
Whether the Y button was pressed since the last check.boolean
getYButtonReleased()
Whether the Y button was released since the last check.BooleanEvent
leftBumper(EventLoop loop)
Constructs an event instance around the right bumper's digital signal.BooleanEvent
leftStick(EventLoop loop)
Constructs an event instance around the left stick button's digital signal.BooleanEvent
leftTrigger(double threshold, EventLoop loop)
Constructs an event instance around the axis value of the left trigger.BooleanEvent
leftTrigger(EventLoop loop)
Constructs an event instance around the axis value of the left trigger.BooleanEvent
rightBumper(EventLoop loop)
Constructs an event instance around the left bumper's digital signal.BooleanEvent
rightStick(EventLoop loop)
Constructs an event instance around the right stick button's digital signal.BooleanEvent
rightTrigger(double threshold, EventLoop loop)
Constructs an event instance around the axis value of the right trigger.BooleanEvent
rightTrigger(EventLoop loop)
Constructs an event instance around the axis value of the right trigger.BooleanEvent
start(EventLoop loop)
Constructs an event instance around the start button's digital signal.BooleanEvent
x(EventLoop loop)
Constructs an event instance around the X button's digital signal.BooleanEvent
y(EventLoop loop)
Constructs an event instance around the Y button's digital signal.Methods inherited from class edu.wpi.first.wpilibj.GenericHID
axisGreaterThan, axisLessThan, button, getAxisCount, getAxisType, getButtonCount, getName, getPort, getPOV, getPOV, getPOVCount, getRawAxis, getRawButton, getRawButtonPressed, getRawButtonReleased, getType, isConnected, pov, pov, povCenter, povDown, povDownLeft, povDownRight, povLeft, povRight, povUp, povUpLeft, povUpRight, setOutput, setOutputs, setRumble
-
Constructor Details
-
XboxController
Construct an instance of a controller.- Parameters:
port
- The port index on the Driver Station that the controller is plugged into.
-
-
Method Details
-
getLeftX
Get the X axis value of left side of the controller.- Returns:
- The axis value.
-
getRightX
Get the X axis value of right side of the controller.- Returns:
- The axis value.
-
getLeftY
Get the Y axis value of left side of the controller.- Returns:
- The axis value.
-
getRightY
Get the Y axis value of right side of the controller.- Returns:
- The axis value.
-
getLeftTriggerAxis
Get the left trigger (LT) axis value of the controller. Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].- Returns:
- The axis value.
-
getRightTriggerAxis
Get the right trigger (RT) axis value of the controller. Note that this axis is bound to the range of [0, 1] as opposed to the usual [-1, 1].- Returns:
- The axis value.
-
getLeftBumper
Read the value of the left bumper (LB) button on the controller.- Returns:
- The state of the button.
-
getRightBumper
Read the value of the right bumper (RB) button on the controller.- Returns:
- The state of the button.
-
getLeftBumperPressed
Whether the left bumper (LB) was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getRightBumperPressed
Whether the right bumper (RB) was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getLeftBumperReleased
Whether the left bumper (LB) was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getRightBumperReleased
Whether the right bumper (RB) was released since the last check.- Returns:
- Whether the button was released since the last check.
-
leftBumper
Constructs an event instance around the right bumper's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the right bumper's digital signal attached to the given loop.
-
rightBumper
Constructs an event instance around the left bumper's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the left bumper's digital signal attached to the given loop.
-
getLeftStickButton
Read the value of the left stick button (LSB) on the controller.- Returns:
- The state of the button.
-
getRightStickButton
Read the value of the right stick button (RSB) on the controller.- Returns:
- The state of the button.
-
getLeftStickButtonPressed
Whether the left stick button (LSB) was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getRightStickButtonPressed
Whether the right stick button (RSB) was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getLeftStickButtonReleased
Whether the left stick button (LSB) was released since the last check.- Returns:
- Whether the button was released since the last check.
-
getRightStickButtonReleased
Whether the right stick (RSB) button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
leftStick
Constructs an event instance around the left stick button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the left stick button's digital signal attached to the given loop.
-
rightStick
Constructs an event instance around the right stick button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the right stick button's digital signal attached to the given loop.
-
getAButton
Read the value of the A button on the controller.- Returns:
- The state of the button.
-
getAButtonPressed
Whether the A button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getAButtonReleased
Whether the A button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
a
Constructs an event instance around the A button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the A button's digital signal attached to the given loop.
-
getBButton
Read the value of the B button on the controller.- Returns:
- The state of the button.
-
getBButtonPressed
Whether the B button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getBButtonReleased
Whether the B button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
b
Constructs an event instance around the B button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the B button's digital signal attached to the given loop.
-
getXButton
Read the value of the X button on the controller.- Returns:
- The state of the button.
-
getXButtonPressed
Whether the X button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getXButtonReleased
Whether the X button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
x
Constructs an event instance around the X button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the X button's digital signal attached to the given loop.
-
getYButton
Read the value of the Y button on the controller.- Returns:
- The state of the button.
-
getYButtonPressed
Whether the Y button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getYButtonReleased
Whether the Y button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
y
Constructs an event instance around the Y button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the Y button's digital signal attached to the given loop.
-
getBackButton
Read the value of the back button on the controller.- Returns:
- The state of the button.
-
getBackButtonPressed
Whether the back button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getBackButtonReleased
Whether the back button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
back
Constructs an event instance around the back button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the back button's digital signal attached to the given loop.
-
getStartButton
Read the value of the start button on the controller.- Returns:
- The state of the button.
-
getStartButtonPressed
Whether the start button was pressed since the last check.- Returns:
- Whether the button was pressed since the last check.
-
getStartButtonReleased
Whether the start button was released since the last check.- Returns:
- Whether the button was released since the last check.
-
start
Constructs an event instance around the start button's digital signal.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance representing the start button's digital signal attached to the given loop.
-
leftTrigger
Constructs an event instance around the axis value of the left trigger. The returned trigger will be true when the axis value is greater thanthreshold
.- Parameters:
threshold
- the minimum axis value for the returnedBooleanEvent
to be true. This value should be in the range [0, 1] where 0 is the unpressed state of the axis.loop
- the event loop instance to attach the event to.- Returns:
- an event instance that is true when the left trigger's axis exceeds the provided threshold, attached to the given event loop
-
leftTrigger
Constructs an event instance around the axis value of the left trigger. The returned trigger will be true when the axis value is greater than 0.5.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance that is true when the left trigger's axis exceeds the provided threshold, attached to the given event loop
-
rightTrigger
Constructs an event instance around the axis value of the right trigger. The returned trigger will be true when the axis value is greater thanthreshold
.- Parameters:
threshold
- the minimum axis value for the returnedBooleanEvent
to be true. This value should be in the range [0, 1] where 0 is the unpressed state of the axis.loop
- the event loop instance to attach the event to.- Returns:
- an event instance that is true when the right trigger's axis exceeds the provided threshold, attached to the given event loop
-
rightTrigger
Constructs an event instance around the axis value of the right trigger. The returned trigger will be true when the axis value is greater than 0.5.- Parameters:
loop
- the event loop instance to attach the event to.- Returns:
- an event instance that is true when the right trigger's axis exceeds the provided threshold, attached to the given event loop
-