Skip to content

Autonomous

Charles Kennedy edited this page Jan 18, 2025 · 7 revisions

Autonomous

Autos are Commands that run during the first 15 seconds of a match. They consist of multiple commands run in a specific order, to tell the robot what to do exactly.

Creating an Autonomous

  1. Navigate to RobotContainer.java

  2. Create a new, private final variable of type Command. This will store our autonomous.

    private final Command lowBalance
  3. Set the command to a new instance of a pre-existing command.

    private final Command lowBalance = 
        new SetElevatorTargetCommand(Constants.bottomElevatorTargetPosition, 
    			true, elevator);
  4. Now you have a complete autonomous

Putting autonomous choices into shuffleboard for match selection

See Shuffleboard Logging for more information regarding Shuffleboard and how we log data

  1. Create a new variable of type SendableChooser, and set it equal to a new sendable chooser. This allows us to select different options in shuffleboard

    SendableChooser<Command> autoChooser = new SendableChooser<>()
  2. Create a method inside RobotContainer.java called addAutoChoicesToGui, like so:

    private void addAutoChoicesToGui()
  3. For the default autonomous option, inside addAutoChoicesToGui, do:

    autoChooser.setDefaultOption("Default Name", defaultAutonomous);
  4. For each other autonomous option, do the following:

    autoChooser.addOption("Autonomous Name", autonomousCommand);
  5. Then, at the end of addAutoChoicesToGui, do:

    shuffleboard.add(autoChooser);

    This does assume that shuffleboard is a ShuffleboardTab. ShuffleboardTab is the class that represents a tab on Shuffleboard.

  6. Lastly, add the following method to RobotContainer.java:

    public Command getAutonomousCommand() {
    	return autoChooser.getSelected();
    }

Configuring an auto

You will need to register all the commands in Autonomous.java in public void registerNamedCommands(), then you can register them with

NamedCommands.registerCommand("Ex: Intake", new IntakeCommand(Intake, anything else you want to run with the intake));

Then you need to use registerAutosAsNamedCommands(), somewhat like this:

 private void registerAutosAsNamedCommands()
    {
        for (String auto : AutoBuilder.getAllAutoNames())
            NamedCommands.registerCommand("Auto " + auto, getPathPlannerAuto(auto));

    }

After that you need to get pathplanner with the auto you need to use a method with the command pathFindThenFollowPath() command like this:

  protected static Command followPath(final String PathName)
    {
        final PathPlannerPath path = PathPlannerPath.fromPathFile(PathName);
        return AutoBuilder.pathfindThenFollowPath(path, SwerveConstants.PathConstraints);
    }

You may also need to get the pathplanner auto and you can use something like this:

protected static Command getPathPlannerAuto(final String PathName)
    {
        return new PathPlannerAuto(PathName);
    }

And finally you need to build the auto command using something like this

    public abstract Optional<Command> buildAutoCommand();

Clone this wiki locally