Shine some light on Commands

Hi,
A couple of quick questions on command based robots.

  1. If a command requires a sub-system but doesn’t require it straight away, is it possible to put the requires line down in a conditional test in the commands execute method?

  2. If you build a sequential command group and each command requires different subsystems, are they are required/locked at the start of command group or at the point in the group where that command executes?
    EG Command A requires Subsystem A, Command B requires Subsystem B, and Command C requires Subsystem C. Command Group executes Command A, then when A finishes, B starts, then when B finishes, C starts, etc

Are all three subsystems required (ie captured/interrupted) at the start of execution of the command group or at the point in time when they start executing?

  1. What’s the go with WhileHeld(). The detail in the guide is a bit sketchy.
    3A. Does the initialization code for the command only run the once?
    3B. Is the isfinished actually called, because it is supposed to run continually while the button is held?
    3C. Is end called when the button is released?
    3D. If some other command requires the same subsystem, what command procedures are called as it is interrupted?
    3E. And if a command in Q 3D does require the subsystem that the command uses. Will the command automatically run again and re-require the subsystem back on the next pass of the scheduler?
    3F. Is there a better guide on the exact working of the command scheduler that answers the above question better then the topic at the end of the C programming guide. Or do I have to just go into the command scheduler source code and work it out?
    3G. Where would I find more information on the notifier procedure?

I have a heap more, but the answers to the above might answer my next questions?

Thanks in advance for the help
Warren

The documentation for commands is certainly lacking in a few areas, including the ones you’ve mentioned. At that point, source code is your friend. I’ve personally had to look up answers to a couple of your questions. Unfortunately, I don’t have the answers readily available, so I’ll refrain to prevent misinformation.

Anyway, read through the source code. The scheduler is a bit convoluted at first glance, but shouldn’t be too difficult to understand.

Nope. The requires() bit is declarative, i.e. should be called once in the constructor. If you need more complicated logic for a specific subsystem or set of subsystems, then you likely have the programming expertise to roll your own setup instead of different commands (put all your logic in a ControlX subsystem and make that your default command)

A command group with commands that require different subsystems is equivalent to a command that requires all those subsystems at once. So yes, the subsystems are locked at the beginning of the command group no matter where in the group they run, Likewise, if a command requiring a specific subsystem runs at the beginning of that command group, even if no other commands requiring that subsystem are in the group, that subsystem will be “locked” (i.e. its default command will not engage) for the duration of the group.

With regards to your questions about whileHeld, I believe the documentation of the function should answer your question (at least in Java, it continuously starts the command every scheduler tick).

#1: Never tried this. requires() is traditionally placed in the instantiation method (that is, the one with the same name as the class), not an execute() or even initialize() method. I strongly suspect that the command infrastructure expects requires() calls during instantiation.
#2: Pretty sure this locking occurs as each individual command is executed.
#3: My understanding of WhileHeld() is that the command is repeatedly added to the scheduler each cycle. If the command is already/still running, this has no effect, but will restart the command if it has finished.

Thanks guys for your answers. A couple of conflicting answers to Question 2. After being shown the source code by one of the kids in team today I think Robinsonz has the correct answer. ie all required at the start of the group.

In regards to Q3. The only info I can find on WhileHeld in both the Java and C manuals is the following one liner.
“Commands can run continuously while the button is depressed by calling whileHeld()”.
While that statement does tell you something, it doesn’t help me with the specific questions I asked in the original post. If anyone else has better documentation on whileHeld or knows whileHeld inside out, I’d still love to know the answers to the specific sub-questions.
Cheers and thanks again in advance for the people that answer these questions.

For Q2, Robinsonz’s answer is correct. As for Q3, see my explanation of whileHeld here. You may find all of that thread interesting too.

Steve

Also with respect to Q1 and Q2, it is possible to start a command from another command. A few times we have started a second command from the end() method of another command when we want to chain them together but want to avoid issues expressed in Q1 and Q2. BTW, if you do start another command from end() carefully consider overriding interrupted() in that same command. The Command class implementation of interrupted() just calls end() and that may not be what you want in this case.

Steve

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.