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?

Kevin

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

3 Likes

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(Preconditions.java:64): Unhandled exception: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 2
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
        at java.base/java.util.Objects.checkIndex(Objects.java:359)
        at java.base/java.util.ArrayList.get(ArrayList.java:427)
        at edu.wpi.first.wpilibj2.command.SequentialCommandGroup.execute(SequentialCommandGroup.java:71)
        at frc.robot.RobotContainer.autonomousPeriodic(RobotContainer.java:53)
        at frc.robot.Robot.autonomousPeriodic(Robot.java:47)
        at edu.wpi.first.wpilibj.IterativeRobotBase.loopFunc(IterativeRobotBase.java:344)
        at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:130)
        at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:343)
        at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:413)
        at java.base/java.lang.Thread.run(Thread.java:833)


Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:358): The robot program quit unexpectedly. This is usually due to a code error.
  The above stacktrace can help determine where the error occurred.
  See https://wpilib.org/stacktrace for more information.
Error at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:365): 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.