[wpilib,cmd] Remove Axis from Gamepad Triggers (#8956)

It's a bit confusing, especially since some controllers will have this be
a 0:1 button rather than axis.
This commit is contained in:
Thad House
2026-06-12 06:42:06 -07:00
committed by GitHub
parent d6fb871a26
commit 5a7d7d50ee
11 changed files with 47 additions and 49 deletions

View File

@@ -873,22 +873,22 @@ public class CommandGamepad {
} }
/** /**
* Get the left trigger axis value of the controller. Note that this axis is bound to the range of * Get the left trigger value of the controller. Note that this axis is bound to the range of [0,
* [0, 1] as opposed to the usual [-1, 1]. * 1] as opposed to the usual [-1, 1].
* *
* @return The axis value. * @return The axis value.
*/ */
public double getLeftTriggerAxis() { public double getLeftTrigger() {
return m_gamepad.getLeftTriggerAxis(); return m_gamepad.getLeftTrigger();
} }
/** /**
* Get the right trigger axis value of the controller. Note that this axis is bound to the range * Get the right trigger value of the controller. Note that this axis is bound to the range of [0,
* of [0, 1] as opposed to the usual [-1, 1]. * 1] as opposed to the usual [-1, 1].
* *
* @return The axis value. * @return The axis value.
*/ */
public double getRightTriggerAxis() { public double getRightTrigger() {
return m_gamepad.getRightTriggerAxis(); return m_gamepad.getRightTrigger();
} }
} }

View File

@@ -181,10 +181,10 @@ double CommandGamepad::GetRightY() const {
return m_gamepad->GetRightY(); return m_gamepad->GetRightY();
} }
double CommandGamepad::GetLeftTriggerAxis() const { double CommandGamepad::GetLeftTrigger() const {
return m_gamepad->GetLeftTriggerAxis(); return m_gamepad->GetLeftTrigger();
} }
double CommandGamepad::GetRightTriggerAxis() const { double CommandGamepad::GetRightTrigger() const {
return m_gamepad->GetRightTriggerAxis(); return m_gamepad->GetRightTrigger();
} }

View File

@@ -494,20 +494,20 @@ class CommandGamepad {
double GetRightY() const; double GetRightY() const;
/** /**
* Get the left trigger axis value of the controller. Note that this axis is * Get the left trigger value of the controller. Note that this axis is
* bound to the range of [0, 1] as opposed to the usual [-1, 1]. * bound to the range of [0, 1] as opposed to the usual [-1, 1].
* *
* @return The axis value. * @return The axis value.
*/ */
double GetLeftTriggerAxis() const; double GetLeftTrigger() const;
/** /**
* Get the right trigger axis value of the controller. Note that this axis is * Get the right trigger value of the controller. Note that this axis is
* bound to the range of [0, 1] as opposed to the usual [-1, 1]. * bound to the range of [0, 1] as opposed to the usual [-1, 1].
* *
* @return The axis value. * @return The axis value.
*/ */
double GetRightTriggerAxis() const; double GetRightTrigger() const;
private: private:
CommandGenericHID* m_hid; CommandGenericHID* m_hid;

View File

@@ -824,22 +824,22 @@ public class CommandGamepad {
} }
/** /**
* Get the left trigger axis value of the controller. Note that this axis is bound to the range of * Get the left trigger value of the controller. Note that this axis is bound to the range of [0,
* [0, 1] as opposed to the usual [-1, 1]. * 1] as opposed to the usual [-1, 1].
* *
* @return The axis value. * @return The axis value.
*/ */
public double getLeftTriggerAxis() { public double getLeftTrigger() {
return m_gamepad.getLeftTriggerAxis(); return m_gamepad.getLeftTrigger();
} }
/** /**
* Get the right trigger axis value of the controller. Note that this axis is bound to the range * Get the right trigger value of the controller. Note that this axis is bound to the range of [0,
* of [0, 1] as opposed to the usual [-1, 1]. * 1] as opposed to the usual [-1, 1].
* *
* @return The axis value. * @return The axis value.
*/ */
public double getRightTriggerAxis() { public double getRightTrigger() {
return m_gamepad.getRightTriggerAxis(); return m_gamepad.getRightTrigger();
} }
} }

View File

@@ -69,7 +69,7 @@ void Gamepad::SetRightYDeadband(double deadband) {
m_rightYDeadband = ClampDeadband(deadband); m_rightYDeadband = ClampDeadband(deadband);
} }
double Gamepad::GetLeftTriggerAxis() const { double Gamepad::GetLeftTrigger() const {
return wpi::math::ApplyDeadband(GetAxis(Axis::LEFT_TRIGGER), return wpi::math::ApplyDeadband(GetAxis(Axis::LEFT_TRIGGER),
m_leftTriggerDeadband); m_leftTriggerDeadband);
} }
@@ -88,7 +88,7 @@ BooleanEvent Gamepad::LeftTrigger(EventLoop* loop) const {
return this->LeftTrigger(0.5, loop); return this->LeftTrigger(0.5, loop);
} }
double Gamepad::GetRightTriggerAxis() const { double Gamepad::GetRightTrigger() const {
return wpi::math::ApplyDeadband(GetAxis(Axis::RIGHT_TRIGGER), return wpi::math::ApplyDeadband(GetAxis(Axis::RIGHT_TRIGGER),
m_rightTriggerDeadband); m_rightTriggerDeadband);
} }
@@ -613,10 +613,10 @@ void Gamepad::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetSmartDashboardType("HID"); builder.SetSmartDashboardType("HID");
builder.PublishConstString("ControllerType", "Gamepad"); builder.PublishConstString("ControllerType", "Gamepad");
builder.AddDoubleProperty( builder.AddDoubleProperty(
"LeftTrigger Axis", "LeftTrigger", [this] { return GetAxisForSendable(Axis::LEFT_TRIGGER); },
[this] { return GetAxisForSendable(Axis::LEFT_TRIGGER); }, nullptr); nullptr);
builder.AddDoubleProperty( builder.AddDoubleProperty(
"RightTrigger Axis", "RightTrigger",
[this] { return GetAxisForSendable(Axis::RIGHT_TRIGGER); }, nullptr); [this] { return GetAxisForSendable(Axis::RIGHT_TRIGGER); }, nullptr);
builder.AddDoubleProperty( builder.AddDoubleProperty(
"LeftX", [this] { return GetAxisForSendable(Axis::LEFT_X); }, nullptr); "LeftX", [this] { return GetAxisForSendable(Axis::LEFT_X); }, nullptr);

View File

@@ -214,7 +214,7 @@ class Gamepad : public HIDDevice,
void SetRightYDeadband(double deadband); void SetRightYDeadband(double deadband);
/** /**
* Get the left trigger axis value of the controller. Note that this axis * Get the left trigger value of the controller. Note that this axis
* is bound to the range of [0, 1] as opposed to the usual [-1, 1]. * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
* *
* A deadband of 0.01 is applied by default. Use SetLeftTriggerDeadband() to * A deadband of 0.01 is applied by default. Use SetLeftTriggerDeadband() to
@@ -222,7 +222,7 @@ class Gamepad : public HIDDevice,
* *
* @return the axis value. * @return the axis value.
*/ */
double GetLeftTriggerAxis() const; double GetLeftTrigger() const;
/** /**
* Set the deadband for the left trigger axis. * Set the deadband for the left trigger axis.
@@ -256,7 +256,7 @@ class Gamepad : public HIDDevice,
BooleanEvent LeftTrigger(EventLoop* loop) const; BooleanEvent LeftTrigger(EventLoop* loop) const;
/** /**
* Get the right trigger axis value of the controller. Note that this axis * Get the right trigger value of the controller. Note that this axis
* is bound to the range of [0, 1] as opposed to the usual [-1, 1]. * is bound to the range of [0, 1] as opposed to the usual [-1, 1].
* *
* A deadband of 0.01 is applied by default. Use SetRightTriggerDeadband() to * A deadband of 0.01 is applied by default. Use SetRightTriggerDeadband() to
@@ -264,7 +264,7 @@ class Gamepad : public HIDDevice,
* *
* @return the axis value. * @return the axis value.
*/ */
double GetRightTriggerAxis() const; double GetRightTrigger() const;
/** /**
* Set the deadband for the right trigger axis. * Set the deadband for the right trigger axis.

View File

@@ -29,13 +29,13 @@ classes:
SetRightXDeadband: SetRightXDeadband:
GetRightY: GetRightY:
SetRightYDeadband: SetRightYDeadband:
GetLeftTriggerAxis: GetLeftTrigger:
SetLeftTriggerDeadband: SetLeftTriggerDeadband:
LeftTrigger: LeftTrigger:
overloads: overloads:
double, EventLoop* [const]: double, EventLoop* [const]:
EventLoop* [const]: EventLoop* [const]:
GetRightTriggerAxis: GetRightTrigger:
SetRightTriggerDeadband: SetRightTriggerDeadband:
RightTrigger: RightTrigger:
overloads: overloads:

View File

@@ -27,7 +27,7 @@ void SysIdRoutineBot::ConfigureBindings() {
.WhileTrue(drive.SysIdDynamic(wpi::cmd::sysid::Direction::kReverse)); .WhileTrue(drive.SysIdDynamic(wpi::cmd::sysid::Direction::kReverse));
shooter.SetDefaultCommand(shooter.RunShooterCommand( shooter.SetDefaultCommand(shooter.RunShooterCommand(
[this] { return driverController.GetLeftTriggerAxis(); })); [this] { return driverController.GetLeftTrigger(); }));
(driverController.FaceDown() && driverController.LeftBumper()) (driverController.FaceDown() && driverController.LeftBumper())
.WhileTrue( .WhileTrue(

View File

@@ -299,14 +299,14 @@ public class Gamepad implements HIDDevice, Sendable {
} }
/** /**
* Get the left trigger axis value of the controller. Note that this axis is bound to the range of * Get the left trigger value of the controller. Note that this axis is bound to the range of [0,
* [0, 1] as opposed to the usual [-1, 1]. * 1] as opposed to the usual [-1, 1].
* *
* <p>A deadband of 0.01 is applied by default. Use {@link #setLeftTriggerDeadband} to change it. * <p>A deadband of 0.01 is applied by default. Use {@link #setLeftTriggerDeadband} to change it.
* *
* @return The axis value. * @return The axis value.
*/ */
public double getLeftTriggerAxis() { public double getLeftTrigger() {
return MathUtil.applyDeadband(getAxis(Axis.LEFT_TRIGGER), m_leftTriggerDeadband); return MathUtil.applyDeadband(getAxis(Axis.LEFT_TRIGGER), m_leftTriggerDeadband);
} }
@@ -337,14 +337,14 @@ public class Gamepad implements HIDDevice, Sendable {
} }
/** /**
* Get the right trigger axis value of the controller. Note that this axis is bound to the range * Get the right trigger value of the controller. Note that this axis is bound to the range of [0,
* of [0, 1] as opposed to the usual [-1, 1]. * 1] as opposed to the usual [-1, 1].
* *
* <p>A deadband of 0.01 is applied by default. Use {@link #setRightTriggerDeadband} to change it. * <p>A deadband of 0.01 is applied by default. Use {@link #setRightTriggerDeadband} to change it.
* *
* @return The axis value. * @return The axis value.
*/ */
public double getRightTriggerAxis() { public double getRightTrigger() {
return MathUtil.applyDeadband(getAxis(Axis.RIGHT_TRIGGER), m_rightTriggerDeadband); return MathUtil.applyDeadband(getAxis(Axis.RIGHT_TRIGGER), m_rightTriggerDeadband);
} }
@@ -1563,10 +1563,8 @@ public class Gamepad implements HIDDevice, Sendable {
public void initSendable(SendableBuilder builder) { public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("HID"); builder.setSmartDashboardType("HID");
builder.publishConstString("ControllerType", "Gamepad"); builder.publishConstString("ControllerType", "Gamepad");
builder.addDoubleProperty( builder.addDoubleProperty("LeftTrigger", () -> getAxisForSendable(Axis.LEFT_TRIGGER), null);
"LeftTrigger Axis", () -> getAxisForSendable(Axis.LEFT_TRIGGER), null); builder.addDoubleProperty("RightTrigger", () -> getAxisForSendable(Axis.RIGHT_TRIGGER), null);
builder.addDoubleProperty(
"RightTrigger Axis", () -> getAxisForSendable(Axis.RIGHT_TRIGGER), null);
builder.addDoubleProperty("LeftX", () -> getAxisForSendable(Axis.LEFT_X), null); builder.addDoubleProperty("LeftX", () -> getAxisForSendable(Axis.LEFT_X), null);
builder.addDoubleProperty("LeftY", () -> getAxisForSendable(Axis.LEFT_Y), null); builder.addDoubleProperty("LeftY", () -> getAxisForSendable(Axis.LEFT_Y), null);
builder.addDoubleProperty("RightX", () -> getAxisForSendable(Axis.RIGHT_X), null); builder.addDoubleProperty("RightX", () -> getAxisForSendable(Axis.RIGHT_X), null);

View File

@@ -25,7 +25,7 @@ public class DefaultTeleMode extends PeriodicOpMode {
robot.motor1.setThrottle(-gamepad.getRightY()); robot.motor1.setThrottle(-gamepad.getRightY());
robot.motor2.setThrottle(-gamepad.getLeftX()); robot.motor2.setThrottle(-gamepad.getLeftX());
robot.motor3.setThrottle(-gamepad.getRightX()); robot.motor3.setThrottle(-gamepad.getRightX());
robot.servo0.setPosition(gamepad.getLeftTriggerAxis()); robot.servo0.setPosition(gamepad.getLeftTrigger());
robot.servo1.setPosition(gamepad.getRightTriggerAxis()); robot.servo1.setPosition(gamepad.getRightTrigger());
} }
} }

View File

@@ -62,7 +62,7 @@ public class SysIdRoutineBot {
.whileTrue(drive.sysIdDynamic(SysIdRoutine.Direction.kReverse)); .whileTrue(drive.sysIdDynamic(SysIdRoutine.Direction.kReverse));
// Control the shooter wheel with the left trigger // Control the shooter wheel with the left trigger
shooter.setDefaultCommand(shooter.runShooter(driverController::getLeftTriggerAxis)); shooter.setDefaultCommand(shooter.runShooter(driverController::getLeftTrigger));
driverController driverController
.faceDown() .faceDown()