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.SendableBuilder; 008import edu.wpi.first.util.sendable.SendableRegistry; 009import edu.wpi.first.wpilibj.Timer; 010 011/** 012 * A command that does nothing but takes a specified amount of time to finish. 013 * 014 * <p>This class is provided by the NewCommands VendorDep 015 */ 016public class WaitCommand extends Command { 017 protected Timer m_timer = new Timer(); 018 private final double m_duration; 019 020 /** 021 * Creates a new WaitCommand. This command will do nothing, and end after the specified duration. 022 * 023 * @param seconds the time to wait, in seconds 024 */ 025 @SuppressWarnings("this-escape") 026 public WaitCommand(double seconds) { 027 m_duration = seconds; 028 SendableRegistry.setName(this, getName() + ": " + seconds + " seconds"); 029 } 030 031 @Override 032 public void initialize() { 033 m_timer.restart(); 034 } 035 036 @Override 037 public void end(boolean interrupted) { 038 m_timer.stop(); 039 } 040 041 @Override 042 public boolean isFinished() { 043 return m_timer.hasElapsed(m_duration); 044 } 045 046 @Override 047 public boolean runsWhenDisabled() { 048 return true; 049 } 050 051 @Override 052 public void initSendable(SendableBuilder builder) { 053 super.initSendable(builder); 054 builder.addDoubleProperty("duration", () -> m_duration, null); 055 } 056}