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>
|
2022-10-15 16:33:14 -07:00
|
|
|
#include <span>
|
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 {
|
|
|
|
|
/**
|
|
|
|
|
* A Command that runs instantly; it will initialize, execute once, and end on
|
|
|
|
|
* the same iteration of the scheduler. Users can either pass in a Runnable and
|
|
|
|
|
* a set of requirements, or else subclass this command if desired.
|
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 InstantCommand : public CommandHelper<FunctionalCommand, InstantCommand> {
|
2019-08-25 23:55:59 -04:00
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new InstantCommand that runs the given Runnable with the given
|
|
|
|
|
* requirements.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the Runnable to run
|
|
|
|
|
* @param requirements the subsystems required by this command
|
|
|
|
|
*/
|
|
|
|
|
InstantCommand(std::function<void()> toRun,
|
2020-01-01 20:09:17 -08:00
|
|
|
std::initializer_list<Subsystem*> requirements);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new InstantCommand that runs the given Runnable with the given
|
|
|
|
|
* requirements.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the Runnable to run
|
|
|
|
|
* @param requirements the subsystems required by this command
|
|
|
|
|
*/
|
2020-12-28 11:18:07 -08:00
|
|
|
explicit InstantCommand(std::function<void()> toRun,
|
2022-10-15 16:33:14 -07:00
|
|
|
std::span<Subsystem* const> requirements = {});
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
InstantCommand(InstantCommand&& other) = default;
|
|
|
|
|
|
|
|
|
|
InstantCommand(const InstantCommand& other) = default;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new InstantCommand with a Runnable that does nothing. Useful
|
|
|
|
|
* only as a no-arg constructor to call implicitly from subclass constructors.
|
|
|
|
|
*/
|
|
|
|
|
InstantCommand();
|
|
|
|
|
};
|
|
|
|
|
} // namespace frc2
|