2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include <functional>
|
|
|
|
|
#include <initializer_list>
|
|
|
|
|
|
2021-06-06 19:51:14 -07:00
|
|
|
#include <wpi/span.h>
|
2020-01-01 20:09:17 -08:00
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include "frc2/command/CommandHelper.h"
|
2022-10-07 01:49:27 +03:00
|
|
|
#include "frc2/command/FunctionalCommand.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
namespace frc2 {
|
|
|
|
|
/**
|
2020-08-31 00:33:11 -07:00
|
|
|
* A command that runs a given runnable when it is initialized, and another
|
2019-08-25 23:55:59 -04:00
|
|
|
* runnable when it ends. Useful for running and then stopping a motor, or
|
|
|
|
|
* extending and then retracting a solenoid. Has no end condition as-is; either
|
2022-02-04 01:14:52 -05:00
|
|
|
* subclass it or use Command.WithTimeout() or Command.Until() to give
|
2019-10-19 11:13:33 -04:00
|
|
|
* it one.
|
2022-01-08 11:11:34 -08:00
|
|
|
*
|
|
|
|
|
* This class is provided by the NewCommands VendorDep
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
2022-10-07 01:49:27 +03:00
|
|
|
class StartEndCommand
|
|
|
|
|
: public CommandHelper<FunctionalCommand, StartEndCommand> {
|
2019-08-25 23:55:59 -04:00
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new StartEndCommand. Will run the given runnables when the
|
|
|
|
|
* command starts and when it ends.
|
|
|
|
|
*
|
|
|
|
|
* @param onInit the Runnable to run on command init
|
|
|
|
|
* @param onEnd the Runnable to run on command end
|
|
|
|
|
* @param requirements the subsystems required by this command
|
|
|
|
|
*/
|
|
|
|
|
StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
|
2020-01-01 20:09:17 -08:00
|
|
|
std::initializer_list<Subsystem*> requirements);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new StartEndCommand. Will run the given runnables when the
|
|
|
|
|
* command starts and when it ends.
|
|
|
|
|
*
|
|
|
|
|
* @param onInit the Runnable to run on command init
|
|
|
|
|
* @param onEnd the Runnable to run on command end
|
|
|
|
|
* @param requirements the subsystems required by this command
|
|
|
|
|
*/
|
|
|
|
|
StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
|
2021-06-06 19:51:14 -07:00
|
|
|
wpi::span<Subsystem* const> requirements = {});
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
StartEndCommand(StartEndCommand&& other) = default;
|
|
|
|
|
|
2022-10-07 01:49:27 +03:00
|
|
|
StartEndCommand(const StartEndCommand& other) = default;
|
2019-08-25 23:55:59 -04:00
|
|
|
};
|
|
|
|
|
} // namespace frc2
|