I want to deploy our intake and run the wheels when a button is pressed but if it is held (and then released) for .5 seconds or more then don’t spin the wheels. I thought this code would do it but it looks like whenInactive starts immediately. I don’t think I can use whenReleased because I am using or and it is a Trigger if I understand things right.
// When right bumper is pressed raise/lower the intake and stop/start the intake on both controllers. If held for > .5 seconds don't start the intake
new JoystickButton(m_operatorController, XboxController.Button.kBumperRight.value).or(new JoystickButton(m_driverController, XboxController.Button.kBumperRight.value))
.whenActive(new InstantCommand(() -> m_intake.toggleIntakePosition(true))
.andThen(new InstantCommand(timer::reset))
.andThen(new InstantCommand(timer::start)))
.whenInactive(new ConditionalCommand(new InstantCommand(() -> m_intake.toggleIntakeWheels(true)), new WaitCommand(0), () -> timer.get() < .5));
The idea was to have it conditionally either turn on the intake wheels or not based on how long the button was pressed. Yours will just wait .5 seconds between deploying the intake and turning on the wheels.
I ended up splitting up the two controllers and using the whenPressed and whenReleased which worked great but it still seems like there should be another way! In the end the drivers just wanted another button and we figured out a way to make that work.
I wanted the right bumper of either controller to trigger this. If I use ‘or’ like in my code from OP which forces me to use the trigger calls (like whenActive).
When i say I split them I wrote two identical commands one for driver one for operator but since I want using ‘or’ I could use when released which worked it just seemed like a very verbose way of doing it
That is a sequential group of the intake position instant command followed by a parallel race group of a 0.5 second timeout with a sequence of waiting for the trigger to go inactive and then running the intake.