WPILibC++ 2026.2.2
Loading...
Searching...
No Matches
WaitUntilCommand.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8
9#include <units/time.h>
10
13
14namespace frc2 {
15/**
16 * A command that does nothing but ends after a specified match time or
17 * condition. Useful for CommandGroups.
18 *
19 * This class is provided by the NewCommands VendorDep
20 */
21class WaitUntilCommand : public CommandHelper<Command, WaitUntilCommand> {
22 public:
23 /**
24 * Creates a new WaitUntilCommand that ends after a given condition becomes
25 * true.
26 *
27 * @param condition the condition to determine when to end
28 */
29 explicit WaitUntilCommand(std::function<bool()> condition);
30
31 /**
32 * Creates a new WaitUntilCommand that ends after a given match time.
33 *
34 * <p>NOTE: The match timer used for this command is UNOFFICIAL. Using this
35 * command does NOT guarantee that the time at which the action is performed
36 * will be judged to be legal by the referees. When in doubt, add a safety
37 * factor or time the action manually.
38 *
39 * The match time counts down when connected to FMS or the DS is in practice
40 * mode for the current mode. When the DS is not connected to FMS or in
41 * practice mode, the command will not wait.
42 *
43 * @param time the match time after which to end, in seconds
44 * @see frc::DriverStation::GetMatchTime()
45 */
46 explicit WaitUntilCommand(units::second_t time);
47
49
50 WaitUntilCommand(const WaitUntilCommand& other) = default;
51
52 bool IsFinished() override;
53
54 bool RunsWhenDisabled() const override;
55
56 private:
57 std::function<bool()> m_condition;
58};
59} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition CommandHelper.h:25
A command that does nothing but ends after a specified match time or condition.
Definition WaitUntilCommand.h:21
bool RunsWhenDisabled() const override
WaitUntilCommand(units::second_t time)
Creates a new WaitUntilCommand that ends after a given match time.
WaitUntilCommand(WaitUntilCommand &&other)=default
WaitUntilCommand(std::function< bool()> condition)
Creates a new WaitUntilCommand that ends after a given condition becomes true.
WaitUntilCommand(const WaitUntilCommand &other)=default
bool IsFinished() override
Definition FunctionalCommand.h:13