Using the TimedCommand


#1

I’m a bit confused on how to use the TimedCommand. Does anyone have any working examples or advice to give?

http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/command/TimedCommand.html


#2

The timed command runs until the timeout passed to the constructor.

public class TimedDriveTest extends TimedCommand {

  private static final DriveSubsystem DRIVE = Robot.DriveSubsystem;

  public TimedDriveTest(double timeout) {
    super(timeout);
    requires(DRIVE);
  }

  @Override
  protected void initialize() {
    DRIVE.setDriveMode(SwerveDrive.DriveMode.CLOSED_LOOP);
    DRIVE.drive(0.2, 0.0, 0.0);
  }

  @Override
  protected void end() {
    DRIVE.stop();
  }
}

When constructing the command, pass the timeout: new TimedDriveTest(5.0). This command would run for 5.0 seconds.


#3

Thanks!