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>
|
|
|
|
|
|
2020-01-01 20:09:17 -08:00
|
|
|
#include <wpi/ArrayRef.h>
|
|
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include "frc2/command/CommandBase.h"
|
|
|
|
|
#include "frc2/command/CommandHelper.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
namespace frc2 {
|
|
|
|
|
/**
|
|
|
|
|
* A command that runs a Runnable continuously. Has no end condition as-is;
|
|
|
|
|
* either subclass it or use Command.WithTimeout() or
|
2019-10-19 11:13:33 -04:00
|
|
|
* Command.WithInterrupt() to give it one. If you only wish
|
2019-08-25 23:55:59 -04:00
|
|
|
* to execute a Runnable once, use InstantCommand.
|
|
|
|
|
*/
|
|
|
|
|
class RunCommand : public CommandHelper<CommandBase, RunCommand> {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new RunCommand. The Runnable will be run continuously until the
|
|
|
|
|
* command ends. Does not run when disabled.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the Runnable to run
|
|
|
|
|
* @param requirements the subsystems to require
|
|
|
|
|
*/
|
|
|
|
|
RunCommand(std::function<void()> toRun,
|
2020-01-01 20:09:17 -08:00
|
|
|
std::initializer_list<Subsystem*> requirements);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new RunCommand. The Runnable will be run continuously until the
|
|
|
|
|
* command ends. Does not run when disabled.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the Runnable to run
|
|
|
|
|
* @param requirements the subsystems to require
|
|
|
|
|
*/
|
|
|
|
|
RunCommand(std::function<void()> toRun,
|
|
|
|
|
wpi::ArrayRef<Subsystem*> requirements = {});
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
RunCommand(RunCommand&& other) = default;
|
|
|
|
|
|
|
|
|
|
RunCommand(const RunCommand& other) = default;
|
|
|
|
|
|
2020-12-28 00:10:13 -08:00
|
|
|
void Execute() override;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
std::function<void()> m_toRun;
|
|
|
|
|
};
|
|
|
|
|
} // namespace frc2
|