2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-08-25 17:47:07 -04:00
|
|
|
|
|
|
|
|
package edu.wpi.first.wpilibj2.command;
|
|
|
|
|
|
2022-12-07 21:46:26 -08:00
|
|
|
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
|
2019-08-25 17:47:07 -04:00
|
|
|
|
|
|
|
|
import edu.wpi.first.wpilibj.Timer;
|
2020-12-29 22:45:16 -08:00
|
|
|
import java.util.function.BooleanSupplier;
|
2019-08-25 17:47:07 -04:00
|
|
|
|
|
|
|
|
/**
|
2020-12-29 22:45:16 -08:00
|
|
|
* A command that does nothing but ends after a specified match time or condition. Useful for
|
2019-08-25 17:47:07 -04:00
|
|
|
* CommandGroups.
|
2022-01-08 11:11:34 -08:00
|
|
|
*
|
|
|
|
|
* <p>This class is provided by the NewCommands VendorDep
|
2019-08-25 17:47:07 -04:00
|
|
|
*/
|
2023-07-14 01:12:01 -04:00
|
|
|
public class WaitUntilCommand extends Command {
|
2019-08-25 17:47:07 -04:00
|
|
|
private final BooleanSupplier m_condition;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new WaitUntilCommand that ends after a given condition becomes true.
|
|
|
|
|
*
|
|
|
|
|
* @param condition the condition to determine when to end
|
|
|
|
|
*/
|
|
|
|
|
public WaitUntilCommand(BooleanSupplier condition) {
|
|
|
|
|
m_condition = requireNonNullParam(condition, "condition", "WaitUntilCommand");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new WaitUntilCommand that ends after a given match time.
|
|
|
|
|
*
|
2020-12-29 22:45:16 -08:00
|
|
|
* <p>NOTE: The match timer used for this command is UNOFFICIAL. Using this command does NOT
|
2019-08-25 17:47:07 -04:00
|
|
|
* guarantee that the time at which the action is performed will be judged to be legal by the
|
2020-12-29 22:45:16 -08:00
|
|
|
* referees. When in doubt, add a safety factor or time the action manually.
|
2019-08-25 17:47:07 -04:00
|
|
|
*
|
|
|
|
|
* @param time the match time after which to end, in seconds
|
|
|
|
|
*/
|
|
|
|
|
public WaitUntilCommand(double time) {
|
|
|
|
|
this(() -> Timer.getMatchTime() - time > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isFinished() {
|
|
|
|
|
return m_condition.getAsBoolean();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean runsWhenDisabled() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|