WPILibC++ 2024.3.2
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
12
13namespace frc2 {
14/**
15 * A command that runs a given runnable when it is initialized, and another
16 * runnable when it ends. Useful for running and then stopping a motor, or
17 * extending and then retracting a solenoid. Has no end condition as-is; either
18 * subclass it or use Command.WithTimeout() or Command.Until() to give
19 * it one.
20 *
21 * This class is provided by the NewCommands VendorDep
22 */
24 : public CommandHelper<FunctionalCommand, StartEndCommand> {
25 public:
26 /**
27 * Creates a new StartEndCommand. Will run the given runnables when the
28 * command starts and when it ends.
29 *
30 * @param onInit the Runnable to run on command init
31 * @param onEnd the Runnable to run on command end
32 * @param requirements the subsystems required by this command
33 */
34 StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
35 Requirements requirements = {});
36
37 StartEndCommand(StartEndCommand&& other) = default;
38
39 StartEndCommand(const StartEndCommand& other) = default;
40};
41} // namespace frc2
CRTP implementation to allow polymorphic decorator functions in Command.
Definition: CommandHelper.h:27
Represents requirements for a command, which is a set of (pointers to) subsystems.
Definition: Requirements.h:20
A command that runs a given runnable when it is initialized, and another runnable when it ends.
Definition: StartEndCommand.h:24
StartEndCommand(std::function< void()> onInit, std::function< void()> onEnd, Requirements requirements={})
Creates a new StartEndCommand.
StartEndCommand(StartEndCommand &&other)=default
StartEndCommand(const StartEndCommand &other)=default
Definition: TrapezoidProfileSubsystem.h:12