WPILibC++ 2024.3.2
InstantCommand.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
12
13namespace frc2 {
14/**
15 * A Command that runs instantly; it will initialize, execute once, and end on
16 * the same iteration of the scheduler. Users can either pass in a Runnable and
17 * a set of requirements, or else subclass this command if desired.
18 *
19 * This class is provided by the NewCommands VendorDep
20 */
21class InstantCommand : public CommandHelper<FunctionalCommand, InstantCommand> {
22 public:
23 /**
24 * Creates a new InstantCommand that runs the given Runnable with the given
25 * requirements.
26 *
27 * @param toRun the Runnable to run
28 * @param requirements the subsystems required by this command
29 */
30 explicit InstantCommand(std::function<void()> toRun,
31 Requirements requirements = {});
32
33 InstantCommand(InstantCommand&& other) = default;
34
35 InstantCommand(const InstantCommand& other) = default;
36
37 /**
38 * Creates a new InstantCommand with a Runnable that does nothing. Useful
39 * only as a no-arg constructor to call implicitly from subclass constructors.
40 */
42};
43} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:27
A Command that runs instantly; it will initialize, execute once, and end on the same iteration of the...
Definition: InstantCommand.h:21
InstantCommand(InstantCommand &&other)=default
InstantCommand()
Creates a new InstantCommand with a Runnable that does nothing.
InstantCommand(const InstantCommand &other)=default
InstantCommand(std::function< void()> toRun, Requirements requirements={})
Creates a new InstantCommand that runs the given Runnable with the given requirements.
Represents requirements for a command, which is a set of (pointers to) subsystems.
Definition: Requirements.h:20
Definition: TrapezoidProfileSubsystem.h:12