-
Notifications
You must be signed in to change notification settings - Fork 611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[cmd] whileTrueLowPriority
on trigger
#7097
base: main
Are you sure you want to change the base?
Conversation
This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR. |
These seem footgun-y to me. Composed commands are invisible to the scheduler, so their var nextCommand = subsystem.run(...);
controller.a().onTrue(subsystem.someCommand().andThen(nextCommand));
// The scheduler does not see this command due to its inclusion in a composition
// This trigger can never fire
nextCommand.done().onTrue(...); They are also specific to the command instances on which they're invoked, so something like this would never work: controller.a().onTrue(subsystem.someCommand())
// New instance from someCommand() that never gets scheduled
// This trigger can never fire
subsystem.someCommand().done().onTrue(subsystem.someOtherCommand()); |
wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/Trigger.java
Outdated
Show resolved
Hide resolved
20fe049
to
a29bdfe
Compare
whileTrueLowPriority
on trigger and command trigger factorieswhileTrueLowPriority
on trigger
I think that As for the triggers on Command, I'm not sure how useful they'd be? Triggering on end can be done via |
A different approach would be to implement command priority levels and suspend-on-interrupt behavior (both of which could be backported from coroutine commands) |
This is something that's being "upstreamed" from the new choreolib rewrite. |
If a |
|
So the /**
* Returns a {@link Trigger} that is true when this subsystem is
* currently being required by no commands or being required by the default command.
*
* This can be used to create a control flow similar to a temporary default command
* <pre><code>
* {
* DriveSubsystem drive = ...;
* Command myCommand = ...;
* Trigger otherCondition = ...;
*
* otherCondition.and(drive.idle(loop)).whileTrue(myCommand.repeatedly());
*}</code></pre><p>
*
* @param loop the event loop to poll this trigger on
* @return a Trigger that is true when this subsystem is not being required by any commands other than the default command
*/
default Trigger idle(EventLoop loop) {
return new Trigger(loop, () -> {
Command currentCommand = getCurrentCommand();
return currentCommand == null || currentCommand == getDefaultCommand();
});
} This was my implementation A solution to this is to do |
Maybe adding a //inside Subsystem.java
default void defaultCommandWhile(BooleanSupplier condition, Command cmd) {
Trigger condTrigger = new Trigger(condTrigger );
condTrigger.and(this.idle()).onTrue(cmd.repeatedly().onlyWhile(condTrigger).withName(cmd.getName()));
} would be a sufficient abstraction |
I want some input on this before I port it to C++.
Specifically how do people feel about the
Command
Trigger
factories and whats a better name forwhileTrueLowPriority
(maybewhileTrueDefault
?).