Autonomous Help Please


I am trying to get some help for my programmer. He is having issues making our robot (Mk4i, Neo, Navx) move during autonomous. We can move our elevator/which and trigger our pneumatics for a high cube every time, but we can’t get the robot to move after. He is using a time based because that is what he knows and is comfortable with. Here is our code and here is a video of what we are getting now. His last attempt is disabling the robot when it gets to the moving part.
Any help is greatly appreciated!


The video shows that you are losing robot code. This is usually due to an exception being thrown due to a programming error. The exception will be in the log. I think I saw it go by in the video but it is too blurry to be sure. It will point you to the line of code that is failing. Also, I do not think the auto in your github is the one being shown in the video as the one in github appears to start with driving and not scoring.

1 Like

The code is trying to use a mix of command-based and timed. This is challenging to pull off. The most immediate problem I see is that it’s trying to create two instances of CANSparkMax to control the same motors, IDs 13 and 14. You cannot do this, it will throw an error with message A CANSparkMax instance has already been created with this device ID: {id}. Another issue I see is that m_Swerve in Robot is always null, so it’ll throw a NullPointerException when it’s called.

Since the rest of the code is command-based, the autonomous should also be command based. At the very least, the autonomous code must use the subsystems, not attempt to drive the motors directly. But, if you attempt this, watch out because TeleopSwerve is the default command, and it is also controlling the drivetrain.

In particular, right around 0:11-


There’s a stacktrace that flies past.

Scanning through the code I see something else. I think the code is attempting to schedule a command. It creates a new RunCommand but never schedules it.

  if (time - startTime > 6.75) {
    new RunCommand(() ->, 0, 0, true, true), m_Swerve);}

Although at this point it throws an exception because m_Swerve is null.

Error at java.base/java.util.Objects.requireNonNull( Unhandled exception: java.lang.NullPointerException: Parameter requirement in method addRequirements was null when it should not have been!  Check the stacktrace to find the responsible line of code - usually, it is the first line of user-written code indicated in the stacktrace.  Make sure all objects passed to the method in question were properly initialized - note that this may not be obvious if it is being called under dynamically-changing conditions!  Please do not seek additional technical assistance without doing this first!
        at java.base/java.util.Objects.requireNonNull(
        at edu.wpi.first.util.ErrorMessages.requireNonNullParam(
        at edu.wpi.first.wpilibj2.command.CommandBase.addRequirements(
        at edu.wpi.first.wpilibj2.command.FunctionalCommand.<init>(
        at edu.wpi.first.wpilibj2.command.RunCommand.<init>(
        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.
1 Like

Thank you all very much for your help! My programmer is looking at your posts and working on it right now. I am sure he will chime in with questions.

Your help is appreciated!


I tried to run the RunCommand with .withTimeout but got the same result. I also tired a Pathplanner generated path, when that is in it doesn’t disable robot code but it doesn’t move either.

.withTimeout does not schedule a command either, it decorates the command and returns a new command. You would schedule a command with .schedule().

BUT, because you’re trying to do your whole autonomous in a single robot iteration, the command won’t actually run. The autonomousPeriodic method should be allowed to run once every 20ms, you can’t put your whole autonomous routine in there and expect commands to work.

Also, you are not even getting far enough to attempt to schedule that command. I see two causes of errors before that:

  1. You’re creating two instance of CANSparkMax for the same ID.
  2. m_Swerve is null.

I highly advise you reconsider making your autonomous command-based. It will be a struggle to get it to run this way.

1 Like

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