Can I make a Command Group a default command?

Hello, I am attempting to streamline my Command based robot code. In order to do so, me and my peers figured we should set a command group as the default drive command, but it does not seem like that can work. Is there a better way to do this?

Yes, I believe you should be able to. A CommandGroup is still a Command: https://github.com/wpilibsuite/allwpilib/blob/master/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandGroupBase.java#L20

1 Like

If you look at the Java Documentation for Command you can see all the known classes that implement the interface of Command.

Any one of those can be a Default Command for a Subsystem. There’s probably plenty of cases where that is true, but I would wonder why the Subsystem is so complex that it would require it.

It might be worth examining the design from a higher level to see if your Subsystem should be subdivided into smaller, more straight forward and simple parts.

A combination intake/indexer could be implemented more cleanly as a command group. The intake() command could send isFinished when it detects at least five balls, and passes to a QC() command. QC checks to see if there are really six or more and kicks those out, then terminates to pass control on to the wait-for-shooter(). I can think of other cases where you might have commands running in parallel.

1 Like

Yes, I guess in our normal paradigm of Command-Based programming the intake/indexer wouldn’t have a Default Command, but certainly yes, when the actuation button is pressed, it would most definitely kick off a Command Group rather than a single command.

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