How to run auto command once

I had an auto command to just drive forward and it was working fine. I changed it to a SequentialCommandGroup to drive foward, drive reverse, then drive forward again. Now, in Autonomous mode, it runs the SCG twice. Any advice?


My solution was to add a very long wait command to the end of the sequential command.


Brute force always works

I can think of three things that might cause this problem:

  • The command group is scheduled twice

  • The command group is scheduled infinitely during auto, but auto ends by the time it’s run twice (what happens if you enable auto and then don’t switch mode? Does the robot just sit still after driving?)

  • The command group is actually scheduled once, but something in it’s logic causes it to run the sequence twice.

You’ll want to add some prints, to see when the sequential command group is scheduled and when it ends. Also, sharing your code would be helpful.

Can u post ur code/link to GitHub?

There’s too much code to paste. Maybe I’ll make a new project with just this. I ran it in the simulator and got this exception after the last command in the SequentialCommandGroup ran:

Error at java.base/jdk.internal.util.Preconditions.outOfBounds( Unhandled exception: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 2
        at java.base/jdk.internal.util.Preconditions.outOfBounds(
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(
        at java.base/jdk.internal.util.Preconditions.checkIndex(
        at java.base/java.util.Objects.checkIndex(
        at java.base/java.util.ArrayList.get(
        at edu.wpi.first.wpilibj2.command.SequentialCommandGroup.execute(
        at frc.robot.RobotContainer.autonomousPeriodic(
        at frc.robot.Robot.autonomousPeriodic(
        at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(
        at edu.wpi.first.wpilibj.TimedRobot.startCompetition(
        at edu.wpi.first.wpilibj.RobotBase.runRobot(
        at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(
        at java.base/

Warning at edu.wpi.first.wpilibj.RobotBase.runRobot( The robot program quit unexpectedly. This is usually due to a code error.
  The above stacktrace can help determine where the error occurred.
  See for more information.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot( The startCompetition() method (or methods called by it) should have handled the exception above.

Just make a public project on github (if its not already there) and post a link here to that project

1 Like

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