Comments (7)
Looks like that line was originally added in #2450 (to resolve #2441). However, the behavior that needed to be fixed (scheduling a command with shared requirements from end()
would cause the original command to be canceled, calling end()
again in an infinite loop) has been fixed in #5470, so we probably don't need that comment anymore.
Regarding https://www.chiefdelphi.com/t/canonical-command-chaining/464156 (which I'm guessing is where you asked on CD):
- Overriding
Command.end()
(or equivalently, wrapping inonEnd()
) to get a callback when the command finishes should work, though if you run into bugs a) please file a bug report to help us improve! and b) try pollingCommand.isScheduled()
periodically to detect when it is no longer scheduled. - Depending on your framework, you also might be able to use
cmd.andThen(Commands.defer(() -> getNextCommand(), Set.of(<requirements>)))
instead of wrapping incmd.onEnd(() -> scheduleNextCommand())
or overridingcmd.end()
to schedule the next command, but I suspect that would run into memory issues since it would create subcommands but not be able to garbage collect old commands (since those are wrappers around the subcommands). bovlb's CD suggestion ofandThen(Commands.runOnce(() -> scheduleNextCommand()))
wouldn't run into those memory issues, though sinceonEnd()
should work, there wouldn't be an advantage compared toonEnd(() -> scheduleNextCommand())
. - I would advise against using
onCommandFinish()
and/oronCommandInterrupt()
, since even if you get both the finish and interrupt combination, you still will not be notified of a command ending within a composition (since the callbacks are managed byCommandScheduler
, while command compositions manage the composed commands themselves).
from allwpilib.
What is scheduling from end
going to gain you compared to using factory methods? You might be looking for select
or either
from allwpilib.
maybe? how do I use select() or either() to assemble an indefinite series of arbitrary commands?
from allwpilib.
Something like .run(select(...))
could work?
from allwpilib.
i see, you mean to put the selection logic in the command selector. how do you trap the command completion to select the next one? I think my main question is actually the reasoning behind the comment. why say that chaining commands through end() is a bad idea if it seems to work fine?
from allwpilib.
I presume that it isn't recommended as it adds a side effect to the command that is essentially hidden. When you use a factory command you explicitly state that after this command ends this command should run. Compared to end where you are implicitly moving on to it which could cause unintuitive behaviour using something like factory methods as well.
from allwpilib.
ok thanks. maybe this is more of a question about canon rather than the specific Command.end idea. I'll ask over on CD.
from allwpilib.
Related Issues (20)
- Add usage example to SynchronousInterrupt and AsynchronousInterrupt API docs
- Add AprilTag Tag Info to Field JSON HOT 6
- New Name For Command Decorator .deadlineWith() HOT 2
- Different Description Of The Command Being Decorated In Documentation And The Hover-Over JavaDocs HOT 6
- Document that the transform classes are intrinsic transformations
- SysId's units are confusing
- Add a fault management API
- Switch from Google Test to Catch2
- XRP Encoders not reporting Rate to WPILib
- roboRIO Team Number Setter crashes while refreshing status
- Segfault when destroying AprilTag detector
- be able to use InterpolatingDoubleTreeMap.put().put()... inline HOT 9
- Upgrade to PMD 7.1.0 HOT 1
- Remove RuntimeLoader and RuntimeDetector
- C++ command based examples don't all use CommandPtr HOT 3
- Example of LTVUnicycleController with path following
- ElevatorExponentialProfile example HOT 1
- Add usage reporting ID for DataLogManager (and/or DataLog)
- CMake: macOS: glassnt Library Does Not Link HOT 10
- Add abseil-cpp as a 3rd party library HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from allwpilib.