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

Triggers with constant conditions never trigger #5608

Open
KangarooKoala opened this issue Sep 3, 2023 · 1 comment · May be fixed by #7425
Open

Triggers with constant conditions never trigger #5608

KangarooKoala opened this issue Sep 3, 2023 · 1 comment · May be fixed by #7425
Labels
component: command-based WPILib Command Based Library type: fix Iterations on existing features or infrastructure.

Comments

@KangarooKoala
Copy link
Contributor

(Adapted from https://discord.com/channels/176186766946992128/368993897495527424/1147691290365005835)

If a Trigger's condition maintains the same value as when it was started, no bindings will ever be triggered. For example, new Trigger(() -> true).whileTrue(cmd.repeatedly()) will never schedule cmd, because the stored m_pressedLast/previous field of the EventLoop callback is initialized with the value of the trigger's condition at binding time (true) and no changes from that value occur, which is the condition to schedule cmd.

Desired behavior is for it to be possible to make something like new Trigger(() -> true).whileTrue(Commands.print("Hi").repeatedly()) spam print "Hi" on every poll of the command scheduler's default event loop. This issue is still open for discussion of how this should be done- For example, I was considering having an enum parameter to the constructor which would specify the initial value of the previous input variable (always true, always false, the value of the condition at binding time (current behavior), and the negated value of the condition at binding time), but there are probably other possibilities. (For example, maybe we only want to support the variable being initialized with a single boolean value regardless of the condition's state, so we can just have a boolean parameter instead of an enum)

@auscompgeek auscompgeek added the component: command-based WPILib Command Based Library label Jan 2, 2024
@calcmogul calcmogul added the type: fix Iterations on existing features or infrastructure. label Mar 8, 2024
@calcmogul calcmogul changed the title [cmd] Triggers with constant conditions never trigger Triggers with constant conditions never trigger Mar 8, 2024
@tom131313
Copy link

This issue is a special case of the more general description I provided in #7413.
I have verified that my solution does fix the problem described herein (and other related problems) - new Trigger(() -> true).whileTrue(Commands.print("Hi").repeatedly()) does immediately spam Hi.

HAL Extensions: Attempting to load: halsim_gui
Simulator GUI Initializing.
Simulator GUI Initialized!
HAL Extensions: Successfully loaded extension
********** Robot program starting **********
NT: Listening on NT3 port 1735, NT4 port 5810
********** Robot program startup complete **********
Hi
Default simulationPeriodic() method... Override me!
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi
Hi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: command-based WPILib Command Based Library type: fix Iterations on existing features or infrastructure.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants