Auto command crashes -- Problem with CommandGroup

when the robot first boots up the auto code works as expected, yet when running it again we get his error:

I know there is a method with a name like ResetComandGroup() and I’m wondering if I should schedule this in auto init. We have a Deadline inside of a sequential for our auto.

Are you building the command group in autonomous init?

Kind of, I call the Deadline and decorate it with an andThen

I suggest that you make sure that you are adding the deadline group into the sequential, and not anything else.
Either way, you can check the stack trace in the RioLog to find where the error started.

What do you mean not anything else?

Not a command in the deadline group, or anything that can be double.
Anyway, I suggest that you add a link to your code, it can help me and others find the problem

I haven’t forked our main project so I’ll just paste it in here, I dont have git on this laptop:

public Command getAutonomousCommand() {

    return autoDriveBackCommand.andThen(autoShootSequenceCommand);}

^Robot container

public AutoDriveBackCommand(DriveSubsystem driveSubsystem) {
    // Use addRequirements() here to declare subsystem dependencies.
    this.driveSubsystem = driveSubsystem;


  // Called every time the scheduler runs while the command is scheduled.
  public void execute() {
    driveSubsystem.arcadeDrive(-.5, 0);

  public void end(boolean interrupted) {
    driveSubsystem.arcadeDrive(0, 0);

  public boolean isFinished() {
    return Math.abs(driveSubsystem.getAverageEncoderDistanceMeters()) >= .763;

Auto drive command^

public class AutoShootSequenceCommand extends ParallelDeadlineGroup {

  public AutoShootSequenceCommand(IndexSubsystem indexSubsystem, ShooterSubsystem shooterSubsystem) {
    // Add your commands in the super() call. Add the deadline first.
    super(new AutoIndexSequenceCommand(indexSubsystem), new ShooterCommand(shooterSubsystem));

Auto shoot^ We did this to have the shooter spin up first and index a little later, we needed auto shoot to perpetually happen

public class AutoIndexSequenceCommand extends SequentialCommandGroup {

  public AutoIndexSequenceCommand(IndexSubsystem indexSubsystem) {
    super(new WaitCommand(0.8), new IndexWheelCommand(indexSubsystem).withTimeout(7));

^index with the wait

Can you try to run the auto and upload a picture of the error on the RIOLog?

I will at lunch. It works when the robo rio is fresh and has just turned on, yet when i run it again it gives me that error.

This part will cause the error you are seeing. Using the decorators such as andThen creates a command group (in this case a SequentialCommandGroup.) The problem is that you cannot put the commands into more than one command group, and this code creates a new group each time it is called.

I see two possible solutions to this problem:

  1. Create this command-group once, maybe in RobotContainer’s constructor, and then just return it in getAutonomousCommand
  2. Don’t reuse the commands, just create new ones.
public Command getAutonomousCommand() {
    return new AutoDriveBackCommand(driveSubsystem)
            .andThen(new AutoShootSequenceCommand(indexSubsystem, shooterSubsystem));

Could I use purely decorators like .alongWith etc… in the getAuto?

Why would you need to make the object every time? Also will the old command be trashed by java so i can use the autoshoot sequence again if i make the new objects as you do in the second example?

Most of the decorators create command-groups, and one instance of a command can only exist in a single command-group. See Command Groups in the docs:

Since command group components are run through their encapsulating command groups, errors could occur if those same command instances were independently scheduled at the same time as the group - the command would be being run from multiple places at once, and thus could end up with inconsistent internal state, causing unexpected and hard-to-diagnose behavior.

For this reason, command instances that have been added to a command group cannot be independently scheduled or added to a second command group. Attempting to do so will throw an exception and crash the user program.

This last paragraph describes exactly what you are seeing, an exception is thrown and your program crashes.

Option 1 above creates one instance of the commands and a single command-group. Option 2 above creates new instances of both the commands and the command-group, so you don’t have to reuse. Either option is acceptable, it’s up to you.

The old commands would be garbage-collected by Java as soon as they are no longer referenced, yes.

Yes, you can use all decorators in getAuto and get rid of your AutoIndexSequenceCommand. It would look something like this:

public Command getAutonomousCommand() {
    return new AutoDriveBackCommand(driveSubsystem)
            .andThen(new WaitCommand(0.8))
            .andThen(new IndexWheelCommand(indexSubsystem).withTimeout(7));

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