Command decorators: A "complete" guide #21
Pinned
Jacob1010-h
announced in
Announcements
Replies: 1 comment 2 replies
-
I would like to have a discussion as to if things like this should be done iteratively or not, because we are given a disabledperiodic after all |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is a Command or CommandBase?
A Command is a class in WPILib that takes in a Runnable and adds it to a running queue or stack of all of the commands in the program. A CommandBase is, in simple terms, an implementation of a Command with more methods and modifiers. You can execute a specific command or the stack as a whole with the .schedule() modifier.
But what is a Command decorator?
A Command decorator is a method from the Command or, more likely, a Command Base class that has just been returned.
A Command modifier will modify the Command class that it is attached to. It is possible to layer Commands by putting one Command inside of another; however, if a modifier is applied to the outside Command, it is not applied to the root or the inside Command. Let’s look at an example of this in #4
Below is the previous version of the code, with a layered Command…
The code above does not work. The reason for this error is because the Command modifiers being applied to the outside command, not the original or root command: “update()”.
This error forces the “onDisabled()” method to run the Commands.run() method. However, this logic does not apply to the inside command, “update(),” which is what we want to happen.
Beta Was this translation helpful? Give feedback.
All reactions