001// Copyright (c) FIRST and other WPILib contributors. 002// Open Source Software; you can modify and/or share it under the terms of 003// the WPILib BSD license file in the root directory of this project. 004 005package edu.wpi.first.wpilibj2.command; 006 007import edu.wpi.first.util.sendable.SendableRegistry; 008import edu.wpi.first.wpilibj.Timer; 009 010/** 011 * A command that does nothing but takes a specified amount of time to finish. Useful for 012 * CommandGroups. Can also be subclassed to make a command with an internal timer. 013 */ 014public class WaitCommand extends CommandBase { 015 protected Timer m_timer = new Timer(); 016 private final double m_duration; 017 018 /** 019 * Creates a new WaitCommand. This command will do nothing, and end after the specified duration. 020 * 021 * @param seconds the time to wait, in seconds 022 */ 023 public WaitCommand(double seconds) { 024 m_duration = seconds; 025 SendableRegistry.setName(this, getName() + ": " + seconds + " seconds"); 026 } 027 028 @Override 029 public void initialize() { 030 m_timer.reset(); 031 m_timer.start(); 032 } 033 034 @Override 035 public void end(boolean interrupted) { 036 m_timer.stop(); 037 } 038 039 @Override 040 public boolean isFinished() { 041 return m_timer.hasElapsed(m_duration); 042 } 043 044 @Override 045 public boolean runsWhenDisabled() { 046 return true; 047 } 048}