Skip to content

[cmd3] Ability to disable requirement inheritance in command builders#8880

Draft
EdanThomton wants to merge 3 commits into
wpilibsuite:mainfrom
EdanThomton:main
Draft

[cmd3] Ability to disable requirement inheritance in command builders#8880
EdanThomton wants to merge 3 commits into
wpilibsuite:mainfrom
EdanThomton:main

Conversation

@EdanThomton
Copy link
Copy Markdown
Contributor

Followup to #8777. This adds the ability to (optionally) explicitly enable/disable requirement inheritance in Sequential and Parallel command builders. To allow for scenarios where one mechanism needs to remain commanded throughout the entire sequence, I've also added an ability to add additional requirements in the builder if requirement inheritance is disabled, so long as the additional requirements were all originally inherited.

Syntax:

// some command group builder; syntax is same for both parallel groups and sequential groups
Command.sequence( 
    command1,
    command2,
    command3
)
// disable (or explicitly enable) requirement inheriting
.inheritRequirements(false)
// add any additional mechanisms
.withAdditionalRequirements(myMechanism, myMechanism2, myMechanism3, ...)
.withAdditionalRequirements(List.of(myMechanism3, myMechanism4, ...))
.named("my command group");

Known TODO: Tests need to be added. Unfortunately, I don't have the storage space to fully build wpilib right now, so someone else may need to do that.

- Added ability to disable subcommand requirement inheriting
in Parallel and Sequential command groups
- Added ability to add additional mechanism requirements
in Parallel and Sequential command groups
If a requirement isn't a subcommand requirement,
it leads to an unneeded mechanism being uncommanded.
To fix this, additional requirements are checked
and only added if they are a subcommand requirement
@EdanThomton
Copy link
Copy Markdown
Contributor Author

From some discussion on the discord, I'd also like to bring up potentially switching the default behavior of the command builders to not inheriting requirements. Generally, the behavior expected by the user is that these commands will run their subcommands as specified without affecting any mechanisms used. Inheriting requirements breaks this, can lead to uncommanded behavior in mechanisms, and actively encourages spam of ProxyCommand in v2. Generally, having inherited requirements is a more niche behavior and need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: commands v3 WPILib Commands library version 3 type: testing Related to testing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant