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.
|
2016-11-18 17:42:40 -05:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-09-12 02:44:22 -04:00
|
|
|
#include <functional>
|
|
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include <wpi/Twine.h>
|
2016-11-18 17:42:40 -05:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/commands/Command.h"
|
2018-09-12 02:44:22 -04:00
|
|
|
#include "frc/commands/Subsystem.h"
|
2016-11-18 17:42:40 -05:00
|
|
|
|
|
|
|
|
namespace frc {
|
|
|
|
|
|
2016-11-19 00:26:22 -08:00
|
|
|
/**
|
|
|
|
|
* This command will execute once, then finish immediately afterward.
|
|
|
|
|
*
|
2017-11-16 00:33:51 -08:00
|
|
|
* Subclassing InstantCommand is shorthand for returning true from IsFinished().
|
2016-11-19 00:26:22 -08:00
|
|
|
*/
|
2016-11-18 17:42:40 -05:00
|
|
|
class InstantCommand : public Command {
|
|
|
|
|
public:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Creates a new InstantCommand with the given name.
|
|
|
|
|
*
|
|
|
|
|
* @param name The name for this command
|
|
|
|
|
*/
|
2018-04-29 23:33:19 -07:00
|
|
|
explicit InstantCommand(const wpi::Twine& name);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2018-09-02 14:18:12 -07:00
|
|
|
/**
|
|
|
|
|
* Creates a new InstantCommand with the given requirement.
|
|
|
|
|
*
|
|
|
|
|
* @param subsystem The subsystem that the command requires
|
|
|
|
|
*/
|
|
|
|
|
explicit InstantCommand(Subsystem& subsystem);
|
|
|
|
|
|
2018-08-19 22:43:21 -04:00
|
|
|
/**
|
|
|
|
|
* Creates a new InstantCommand with the given name.
|
|
|
|
|
*
|
2018-09-02 14:18:12 -07:00
|
|
|
* @param name The name for this command
|
|
|
|
|
* @param subsystem The subsystem that the command requires
|
2018-08-19 22:43:21 -04:00
|
|
|
*/
|
2018-09-02 14:18:12 -07:00
|
|
|
InstantCommand(const wpi::Twine& name, Subsystem& subsystem);
|
2018-08-19 22:43:21 -04:00
|
|
|
|
2018-09-12 02:44:22 -04:00
|
|
|
/**
|
|
|
|
|
* Create a command that calls the given function when run.
|
|
|
|
|
*
|
|
|
|
|
* @param func The function to run when Initialize() is run.
|
|
|
|
|
*/
|
|
|
|
|
explicit InstantCommand(std::function<void()> func);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a command that calls the given function when run.
|
|
|
|
|
*
|
|
|
|
|
* @param subsystem The subsystems that this command runs on.
|
|
|
|
|
* @param func The function to run when Initialize() is run.
|
|
|
|
|
*/
|
|
|
|
|
InstantCommand(Subsystem& subsystem, std::function<void()> func);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a command that calls the given function when run.
|
|
|
|
|
*
|
|
|
|
|
* @param name The name of the command.
|
|
|
|
|
* @param func The function to run when Initialize() is run.
|
|
|
|
|
*/
|
|
|
|
|
InstantCommand(const wpi::Twine& name, std::function<void()> func);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a command that calls the given function when run.
|
|
|
|
|
*
|
|
|
|
|
* @param name The name of the command.
|
|
|
|
|
* @param subsystem The subsystems that this command runs on.
|
|
|
|
|
* @param func The function to run when Initialize() is run.
|
|
|
|
|
*/
|
|
|
|
|
InstantCommand(const wpi::Twine& name, Subsystem& subsystem,
|
|
|
|
|
std::function<void()> func);
|
|
|
|
|
|
2016-11-18 17:42:40 -05:00
|
|
|
InstantCommand() = default;
|
|
|
|
|
virtual ~InstantCommand() = default;
|
|
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
InstantCommand(InstantCommand&&) = default;
|
|
|
|
|
InstantCommand& operator=(InstantCommand&&) = default;
|
|
|
|
|
|
2016-11-18 17:42:40 -05:00
|
|
|
protected:
|
2018-09-12 02:44:22 -04:00
|
|
|
std::function<void()> m_func = nullptr;
|
|
|
|
|
void _Initialize() override;
|
2016-11-19 00:26:22 -08:00
|
|
|
bool IsFinished() override;
|
2016-11-18 17:42:40 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace frc
|