Trigger for button released

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));
1 Like

I am not sure I completely understand what you are trying to do, but how about something like this:

    new JoystickButton(m_operatorController, XboxController.Button.kBumperRight.value).or(new JoystickButton(m_driverController, XboxController.Button.kBumperRight.value))
      .whenActive(new InstantCommand(() -> m_intake.toggleIntakePosition(true)))
      .whenInactive(new WaitCommand(0.5).andThen(new InstantCommand(() -> m_intake.toggleIntakeWheels(true))));

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.

What do you mean by splitting them up into two controllers?

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

Now I see what you want to do and I think your original code should work. Sounds like it might just be academic now, but how about this:

    final Trigger intakeTrigger = new JoystickButton(m_operatorController, XboxController.Button.kBumperRight.value).or(new JoystickButton(m_driverController, XboxController.Button.kBumperRight.value));
    intakeTrigger
      .whenActive(new InstantCommand(() -> m_intake.toggleIntakePosition(true))
	    .andThen(new WaitUntilCommand(() -> !intakeTrigger.get())
		         .andThen(new InstantCommand(() -> m_intake.toggleIntakeWheels(true))))
		.withTimeout(0.5));

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.

1 Like

I really like this. I think this would have worked. Thanks

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.