WPILibC++ 2023.4.3-108-ge5452e3
RunCommand.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#include <initializer_list>
9#include <span>
10
13
14namespace frc2 {
15/**
16 * A command that runs a Runnable continuously. Has no end condition as-is;
17 * either subclass it or use Command.WithTimeout() or
18 * Command.Until() to give it one. If you only wish
19 * to execute a Runnable once, use InstantCommand.
20 *
21 * This class is provided by the NewCommands VendorDep
22 */
23class RunCommand : public CommandHelper<FunctionalCommand, RunCommand> {
24 public:
25 /**
26 * Creates a new RunCommand. The Runnable will be run continuously until the
27 * command ends. Does not run when disabled.
28 *
29 * @param toRun the Runnable to run
30 * @param requirements the subsystems to require
31 */
32 RunCommand(std::function<void()> toRun,
33 std::initializer_list<Subsystem*> requirements);
34
35 /**
36 * Creates a new RunCommand. The Runnable will be run continuously until the
37 * command ends. Does not run when disabled.
38 *
39 * @param toRun the Runnable to run
40 * @param requirements the subsystems to require
41 */
42 explicit RunCommand(std::function<void()> toRun,
43 std::span<Subsystem* const> requirements = {});
44
45 RunCommand(RunCommand&& other) = default;
46
47 RunCommand(const RunCommand& other) = default;
48};
49} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:25
A command that runs a Runnable continuously.
Definition: RunCommand.h:23
RunCommand(std::function< void()> toRun, std::span< Subsystem *const > requirements={})
Creates a new RunCommand.
RunCommand(std::function< void()> toRun, std::initializer_list< Subsystem * > requirements)
Creates a new RunCommand.
RunCommand(const RunCommand &other)=default
RunCommand(RunCommand &&other)=default
Definition: ProfiledPIDCommand.h:18