WPILibC++ 2023.4.3-108-ge5452e3
StartEndCommand.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 given runnable when it is initialized, and another
17 * runnable when it ends. Useful for running and then stopping a motor, or
18 * extending and then retracting a solenoid. Has no end condition as-is; either
19 * subclass it or use Command.WithTimeout() or Command.Until() to give
20 * it one.
21 *
22 * This class is provided by the NewCommands VendorDep
23 */
25 : public CommandHelper<FunctionalCommand, StartEndCommand> {
26 public:
27 /**
28 * Creates a new StartEndCommand. Will run the given runnables when the
29 * command starts and when it ends.
30 *
31 * @param onInit the Runnable to run on command init
32 * @param onEnd the Runnable to run on command end
33 * @param requirements the subsystems required by this command
34 */
35 StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
36 std::initializer_list<Subsystem*> requirements);
37
38 /**
39 * Creates a new StartEndCommand. Will run the given runnables when the
40 * command starts and when it ends.
41 *
42 * @param onInit the Runnable to run on command init
43 * @param onEnd the Runnable to run on command end
44 * @param requirements the subsystems required by this command
45 */
46 StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
47 std::span<Subsystem* const> requirements = {});
48
49 StartEndCommand(StartEndCommand&& other) = default;
50
51 StartEndCommand(const StartEndCommand& other) = default;
52};
53} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:25
A command that runs a given runnable when it is initialized, and another runnable when it ends.
Definition: StartEndCommand.h:25
StartEndCommand(std::function< void()> onInit, std::function< void()> onEnd, std::span< Subsystem *const > requirements={})
Creates a new StartEndCommand.
StartEndCommand(StartEndCommand &&other)=default
StartEndCommand(const StartEndCommand &other)=default
StartEndCommand(std::function< void()> onInit, std::function< void()> onEnd, std::initializer_list< Subsystem * > requirements)
Creates a new StartEndCommand.
Definition: ProfiledPIDCommand.h:18