Hello,
I want to use a Joystick as a button by setting a threshold, at which point it will run a command. What’s they best way to accomplish this? I was going to write a custom trigger, but I can’t find a tutorial and I’m getting an error (described below). I guess I could just put an if statement in the command.
Trigger Code: TriggerL2Button.java
package frc.robot;
import edu.wpi.first.wpilibj.buttons.Trigger;
/** Add your docs here. */
public class TriggerL2Button extends Trigger {
@Override
public boolean get() {
return RobotContainer.controller.getRawAxis(3) > 0.5;
}
}
Relevant Code: RobotContainer.java
public static final TriggerL2Button intakeButton = new TriggerL2Button();
public static final TriggerR2Button flywheelButton = new TriggerR2Button();
Error-ing Code: RobotContainer.java
private void configureButtonBindings() {
shootButton.whileHeld(spinFeedWheel);
intakeButton.whileActive(spinIntakeWheel);
flywheelButton.whileActive(spinFlywheel);
}
Error:
The method whileActive(Command) in the type Trigger is not applicable for the arguments (SpinIntakeWheel)Java(67108979)
I don’t understand why this results in an error because SpinIntakeWheel
is a command and TriggerL2Button
extends Trigger
. I generated the trigger using the old trigger template and added the old WPILib library, but it’s the same as what’s shown in the current docs.
Link to project: FRC-Code-2022/src/main/java/frc/robot at fixingQuickTestCode · frc6506/FRC-Code-2022 · GitHub
Update: I get a similar error if I create an instance of a Command
without setting it to anything and pass it to whileActive
.