How to start one of the new Commands in auto?

We’ve used commands in the past. I’m trying to understand the new command framework. I’ve read a lot of the docs, but I don’t see how to start one of these new commands, particularly in auto mode. I saw the section on triggers and buttons, but what is the new analogy to the old autonomousCommand.start() ?

It could also be because I’m also trying to do a PIDCommand for the first time as well. We’re trying to use PID to center on the limelight target.

package frc.robot.commands;

import edu.wpi.first.wpilibj.controller.PIDController;
import edu.wpi.first.wpilibj2.command.PIDCommand;
import frc.robot.Robot;
import frc.robot.subsystems.*;  

public class PIDDriveTrainAim extends PIDCommand {

  public PIDDriveTrainAim( PIDDriveTrain drive) {

    super(
        // The controller that the command will use
        new PIDController(1.0, 0, 0),
        // This should return the measurement
        () -> Robot.getLimelightXOffset(),
        // This should return the setpoint (can also be a constant)
        () -> 0,
        // This uses the output
        output -> drive.useOutput(output, 0 ),
        // this requires the drive
        drive 
        );

    getController().setTolerance(0.1);
  }

  // Returns true when the command should end.
  @Override
  public boolean isFinished() {
    return getController().atSetpoint();
  }

}

Also, anyone know why cut & pasting from VS Code causes all the extra lines? Or is there a better way of formatting it here other than the preformatted text?

Take a look at this

In RobotContainer.java return your autonomous command in the getAutonomousCommand() method

1 Like

Thanks. I think this was from within a project generated by RobotBuilder, and it didn’t have a RobotContainer. Was RobotBuilder updated with all these 2020 updates like the new Command framework?
Maybe we should just start over with the template from the examples in the WPILIB examples repo.

We tried robot builder this year and didn’t see where it incorporated the new framework. Didn’t spend a lot of time on it though. Found most of what we needed in that new 1000page pdf they put out this year.

Per the note at https://docs.wpilib.org/en/latest/docs/software/wpilib-tools/robotbuilder/introduction/robotbuilder-overview.html robot builder still generates for the old Command framework.

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