When a Command
is composed into a CommandGroup
, it cannot be part of another CommandGroup
. If you have a non-trivial command that you would be useful in multiple other commands, what techniques have you found most useful?
For example, let’s say you were building autonomous commands for Crescendo, and defined one command that would pick up a few particular notes, and you wanted to use that in sequence with other commands to build a variety of autonomous commands, all of which included that same sequence.
One option might be to use a generator, which produces equivalent commands, but a unique one for each time it might be composed. This could be by creating a dedicated class and creating a new
instance each time, or by defining a lambda that generates a unique object, which you call each time you want to compose a sequence with that functionality.
Another option might be to use .asProxy()
to provide a level of indirection from the actual command. This should (? we haven’t tested it) allow for a common Command
to executed, but just the ProxyCommand
s to be composed. However, this isn’t a stated use case for ProxyCommand
, and the documentation suggests limited use of ProxyCommand
.
Have you found either of these options, or another option we haven’t covered here, to be useful in command-based programming? I’d like to ensure we are using best practices as we prepare for Reefscape.