Skip to content
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

Add an event in CommandScheduler before each command is executed #7125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rcahoon
Copy link

@rcahoon rcahoon commented Sep 24, 2024

The new onBeforeExecute event parallels the existing onCommandExecute, but onBeforeExecute is run immediately before the execute() of each Command, whereas onCommandExecute is run immediately after. This allows for such uses as profiling the runtime of each Command, or reporting which Command is currently running.

@rcahoon rcahoon requested a review from a team as a code owner September 24, 2024 15:44
Copy link
Contributor

This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR.

@Starlight220
Copy link
Member

Both of the use cases mentioned are already possible; I'm not sure what this improves

@rcahoon
Copy link
Author

rcahoon commented Sep 24, 2024

Both of the use cases mentioned are already possible; I'm not sure what this improves

Could you provide me some more detail about how to report the currently-executing Command without this change? I wasn't able to find a way to do that.

I would like to be able to add an assertion like this in my Subsystem:
assert CommandScheduler.getInstance().requiring(this) == MyCommandSchedulerUtils.getCurrentCommand();
to ensure that a Command must declare my Subsystem in its requirements in order to use it.

@Starlight220
Copy link
Member

By currently-executing command do you mean the command currently being iterated on by the scheduler, and not simply currently scheduled?
Why is requiring() and (I think there's a getRunningCommands or something) not sufficient?

Ensuring requirements is more simply done via using subsystem factory methods and access control etc.

Command timings are already recorded by the scheduler tracer/watchdog; maybe there's room for improvement with exposing that data.

@rzblue
Copy link
Member

rzblue commented Sep 26, 2024

For timing/profiling commands, see #7099

@rcahoon
Copy link
Author

rcahoon commented Sep 26, 2024

By currently-executing command do you mean the command currently being iterated on by the scheduler, and not simply currently scheduled?

Yes

Ensuring requirements is more simply done via using subsystem factory methods and access control etc.

With the Trigger/FunctionalCommand lambdas being in RobotContainer along with the Subsystems, it's very easy for someone to use a Subsystem but forget to add it to the Command's requirement list.

Defensive Programming best practice is to have the receiver, not the caller, validate preconditions.

@Starlight220
Copy link
Member

With the Trigger/FunctionalCommand lambdas being in RobotContainer along with the Subsystems, it's very easy for someone to use a Subsystem but forget to add it to the Command's requirement list.

That's the idea behind the paradigm of subsystems' public API only consisting of command factories and reading accessors/Triggers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants