EasyTrigger
Esta página ainda não foi traduzida. Mostrando a versão em inglês.
A trigger turns a boolean condition into command scheduling. Gamepad buttons return triggers (see EasyGamepad), and you can build your own from any BooleanSupplier.
Triggers are polled when the scheduler runs, so they only work while an EasyCommandComponent, or your own call to scheduler.run(), is active.
#Creating Triggers
Java
EasyTrigger objectClose = new EasyTrigger(
() -> frontDistance.getDistance(DistanceUnit.CM) < 5);
objectClose.onTrue(claw.runOnce(() -> claw.setState("Closed")));
driver.aButton().onPress(shooter.runOnce(shooter::toggle));
driver.leftBumperButton().whileHeld(intake.run(intake::in));#Binding Commands
onTrue(cmd)/onPress(cmd): schedules the command when the condition turns true.onFalse(cmd)/onRelease(cmd): schedules the command when the condition turns false.whileTrue(cmd)/whileHeld(cmd): schedules on true and cancels when the condition turns false.whileFalse(cmd)/whileNotHeld(cmd): the inverse of whileTrue.toggleOnTrue(cmd)/toggleOnPress(cmd): schedules on one rising edge and cancels on the next.
#Plain Actions
onTrueRun(Runnable): runs a plain action on a rising edge, with no command.onFalseRun(Runnable): runs a plain action on a falling edge.onPress(Runnable, subsystems...): wraps the action in a command with requirements.onRelease(Runnable, subsystems...): the same for a falling edge.whileHeld(Runnable, subsystems...): runs the action every loop while the condition is true.
#Combining Conditions
and(cond),or(cond): combine the trigger with another condition.negate(): inverts the condition.get(): the current value of the condition.
#Debounce
debounce(millis) returns a new trigger that is true only after the condition has stayed true for the given time. The original trigger is unchanged, so call debounce first and attach commands to the returned trigger:
Java
new EasyTrigger(() -> limitSwitch.getState())
.debounce(50)
.onTrue(lift.runOnce(lift::zero));A negative time throws an IllegalArgumentException.
Última atualização 2026-11-16