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 static edu.wpi.first.util.ErrorMessages.requireNonNullParam; 008 009import edu.wpi.first.wpilibj.Timer; 010import java.util.function.BooleanSupplier; 011 012/** 013 * A command that does nothing but ends after a specified match time or condition. Useful for 014 * CommandGroups. 015 * 016 * <p>This class is provided by the NewCommands VendorDep 017 */ 018public class WaitUntilCommand extends Command { 019 private final BooleanSupplier m_condition; 020 021 /** 022 * Creates a new WaitUntilCommand that ends after a given condition becomes true. 023 * 024 * @param condition the condition to determine when to end 025 */ 026 public WaitUntilCommand(BooleanSupplier condition) { 027 m_condition = requireNonNullParam(condition, "condition", "WaitUntilCommand"); 028 } 029 030 /** 031 * Creates a new WaitUntilCommand that ends after a given match time. 032 * 033 * <p>NOTE: The match timer used for this command is UNOFFICIAL. Using this command does NOT 034 * guarantee that the time at which the action is performed will be judged to be legal by the 035 * referees. When in doubt, add a safety factor or time the action manually. 036 * 037 * <p>The match time counts down when connected to FMS or the DS is in practice mode for the 038 * current mode. When the DS is not connected to FMS or in practice mode, the command will not 039 * wait. 040 * 041 * @param time the match time after which to end, in seconds 042 * @see edu.wpi.first.wpilibj.DriverStation#getMatchTime() 043 */ 044 public WaitUntilCommand(double time) { 045 this(() -> Timer.getMatchTime() < time); 046 } 047 048 @Override 049 public boolean isFinished() { 050 return m_condition.getAsBoolean(); 051 } 052 053 @Override 054 public boolean runsWhenDisabled() { 055 return true; 056 } 057}