Issue with onTrue/onFalse() with commands?

So, our team has had issues with the onTrue command scheduling option, and I wondered if other teams are having the issue too. If so, I can move this to a GitHub issue.

Sometimes, even though the trigger happens in the onTrue, our command never fires. It was run 5 times (just a stick press), and we only get the command to change once (change our LEDs). We changed the command to a whileTrue() trigger, and moved the command logic to initialize, and it seemed to resolve the issue, but I feel like this is the incorrect solution.

If you add logging to the command, I’d bet you’d see the execute method getting called multiple times. I’m assuming your command is toggling LEDs (i.e. if on, turn off. If off, turn on). Electrical switches (buttons) rarely generate a clean signal. You need to debounce the value.

Fortunately there’s a method to do this for you, aptly named debounce()

1 Like

I didn’t think of that… I would have thought joystick buttons are debounced, but I bet it’s raw value for the fastest FPS.

I don’t have access to a robot till Wednesday, but maybe simulation can show that.

Are you sure the command isn’t triggered? onTrue triggers when the button is newly pressed, whileTrue does the same thing with the addition of cancelling the command when the button isn’t pressed anymore. Also, a debounce on HID buttons shouldn’t be needed. Related, scheduling an already-scheduled command doesn’t do anything.

If I had to guess, your command wasn’t ending, so it was already scheduled when the button was pressed, so the another press did nothing.

Debugging might be helped by adding logging in the command event listeners: CommandScheduler.onCommandInitialize etc.

1 Like