Can anybody tell me how to use whileTrue/False,onTrue/False,toggleonTrue/False?I’ve already read their desciption but I still don’t get it.
Doubt this. There are alternative explanations in your other thread.
I recommend reading this docs article: Binding Commands to Triggers — FIRST Robotics Competition documentation
In general, there are three types of binding:
-
onTrue
schedules the command when the button is pressed. -
whileTrue
schedules the command when the button is pressed, and cancels the command when the button is released. -
toggleTrue
toggles the command on every press: schedules if not currently scheduled, and cancels if scheduled.
The False
variants are the same thing, with release and press flipped.
Which controller class are you using? For example, there’s an XboxController class, as well as a CommandXboxController, while they’re fairly similar, the way you bind commands to buttons is slightly different
This section of the above article explains this. The only difference between XboxController and CommandXboxController is how you get the Trigger
instance; once you have the Trigger
/JoystickButton
instance, binding commands to it is identical.
Your explanation is very clear and helps to uncover why OP and some on my team struggle with remembering it.
The whileTrue
name fails to adequately describe the actions compared to the other two ways. A better name (and this still needs to be word-smithed) would be whileTrueThenReleaseCancel
.
The onTrue
doesn’t have a cancel. The toggleTrue
almost (but not quite) implies a cancel on alternating presses. One has to think hard that must be what is meant. (And could be better described.)
The whileTrue
doesn’t have any hint of the falling edge active cancel command.
This is what basically happens, as long as the command is still running when the second button press happens.
while
in my understanding (as in the loop) means executing something as long as a condition is true, stopping when the condition is false. Stopping a command means canceling it.
For some further context on the semantics change here: with the addition of RepeatCommand/repeatedly()
, the “schedule repeatedly” functionality of the original whilePressed
was more of a liability than a feature (the non-repeating functionality coming from the confusingly-similarly-named whenHeld
).
The previous behavior of re-scheduling the command continuously during whileHeld
was arguably unsafe, as it would repeat the command even if the command was interrupted rather than ending naturally. As interruptions are often error states, this does not make sense (note the equivalent functionality through repeatedly
and whileTrue
will not repeat if the command is externally interrupted).
I like the actions of this set of three commands - they are well thought out.
I’m trying to figure out a good way of expressing complicated actions with short names. We’ve recently been charged with thinking about style. I see some vendors have very long method names to completely describe the actions of a method. I’m almost tempted to think that’s the way to do it.
I’m thinking of the struggles of my 7 rookie programmers. They are not using the confusing shortcuts and maybe that’s the right answer. Shortcuts are for advanced programmers - second year lessons.
Here’s my next iteration of suggestions (for training purposes I presume) and they only assume without stating that the schedule or cancel action is performed only once (rule - no repeats unless specifically stated).
I see the definitions of press (first depression), hold (while pressed), (first) release have to be well known.
Sorry, I guess I’m just trying to figure out how to train my programmers to use these better without so much confusion.
-
onTrue
schedules the command once when the button is pressed.
ScheduleOnTrue -
whileTrue
schedules the command once when the button is pressed, and cancels the command when the button is released.
ScheduleOnTrueCancelOnFalse -
toggleTrue
toggles the command on every press: schedules if not currently scheduled, and cancels if scheduled.
ScheduleOrCancelToggleOnTrue
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.