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>
|
2020-01-01 20:09:17 -08:00
|
|
|
#include <initializer_list>
|
2019-08-25 23:55:59 -04:00
|
|
|
#include <memory>
|
2022-10-15 16:33:14 -07:00
|
|
|
#include <span>
|
2019-08-25 23:55:59 -04:00
|
|
|
#include <string>
|
|
|
|
|
|
2020-06-29 22:25:09 -07:00
|
|
|
#include <units/time.h>
|
2019-08-25 23:55:59 -04:00
|
|
|
#include <wpi/Demangle.h>
|
|
|
|
|
#include <wpi/SmallSet.h>
|
2019-11-05 20:52:49 -08:00
|
|
|
|
|
|
|
|
#include "frc2/command/Subsystem.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
namespace frc2 {
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
std::string GetTypeName(const T& type) {
|
|
|
|
|
return wpi::Demangle(typeid(type).name());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PerpetualCommand;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A state machine representing a complete action to be performed by the robot.
|
|
|
|
|
* Commands are run by the CommandScheduler, and can be composed into
|
|
|
|
|
* CommandGroups to allow users to build complicated multi-step actions without
|
|
|
|
|
* the need to roll the state machine logic themselves.
|
|
|
|
|
*
|
2022-05-24 10:22:19 -06:00
|
|
|
* <p>Commands are run synchronously from the main robot loop; no
|
|
|
|
|
* multithreading is used, unless specified explicitly from the command
|
|
|
|
|
* implementation.
|
2019-08-25 23:55:59 -04:00
|
|
|
*
|
|
|
|
|
* <p>Note: ALWAYS create a subclass by extending CommandHelper<Base, Subclass>,
|
|
|
|
|
* or decorators will not function!
|
|
|
|
|
*
|
2022-01-08 11:11:34 -08:00
|
|
|
* This class is provided by the NewCommands VendorDep
|
|
|
|
|
*
|
2019-08-25 23:55:59 -04:00
|
|
|
* @see CommandScheduler
|
|
|
|
|
* @see CommandHelper
|
|
|
|
|
*/
|
2021-04-18 20:35:29 -07:00
|
|
|
class Command {
|
2019-08-25 23:55:59 -04:00
|
|
|
public:
|
|
|
|
|
Command() = default;
|
2021-04-18 20:35:29 -07:00
|
|
|
virtual ~Command();
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2021-05-25 20:54:39 -07:00
|
|
|
Command(const Command&) = default;
|
|
|
|
|
Command& operator=(const Command& rhs);
|
2019-09-14 15:22:54 -05:00
|
|
|
Command(Command&&) = default;
|
|
|
|
|
Command& operator=(Command&&) = default;
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
/**
|
|
|
|
|
* The initial subroutine of a command. Called once when the command is
|
|
|
|
|
* initially scheduled.
|
|
|
|
|
*/
|
|
|
|
|
virtual void Initialize();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The main body of a command. Called repeatedly while the command is
|
|
|
|
|
* scheduled.
|
|
|
|
|
*/
|
|
|
|
|
virtual void Execute();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The action to take when the command ends. Called when either the command
|
|
|
|
|
* finishes normally, or when it interrupted/canceled.
|
|
|
|
|
*
|
|
|
|
|
* @param interrupted whether the command was interrupted/canceled
|
|
|
|
|
*/
|
|
|
|
|
virtual void End(bool interrupted);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the command has finished. Once a command finishes, the scheduler
|
|
|
|
|
* will call its end() method and un-schedule it.
|
|
|
|
|
*
|
|
|
|
|
* @return whether the command has finished.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool IsFinished() { return false; }
|
|
|
|
|
|
|
|
|
|
/**
|
2022-08-30 07:53:47 +03:00
|
|
|
* Specifies the set of subsystems used by this command. Two commands cannot
|
|
|
|
|
* use the same subsystem at the same time. If another command is scheduled
|
|
|
|
|
* that shares a requirement, GetInterruptionBehavior() will be checked and
|
|
|
|
|
* followed. If no subsystems are required, return an empty set.
|
2019-08-25 23:55:59 -04:00
|
|
|
*
|
|
|
|
|
* <p>Note: it is recommended that user implementations contain the
|
|
|
|
|
* requirements as a field, and return that field here, rather than allocating
|
|
|
|
|
* a new set every time this is called.
|
|
|
|
|
*
|
|
|
|
|
* @return the set of subsystems that are required
|
2022-08-30 07:53:47 +03:00
|
|
|
* @see InterruptionBehavior
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
|
|
|
|
virtual wpi::SmallSet<Subsystem*, 4> GetRequirements() const = 0;
|
|
|
|
|
|
2022-08-30 07:53:47 +03:00
|
|
|
/**
|
|
|
|
|
* An enum describing the command's behavior when another command with a
|
|
|
|
|
* shared requirement is scheduled.
|
|
|
|
|
*/
|
|
|
|
|
enum class InterruptionBehavior {
|
|
|
|
|
/**
|
|
|
|
|
* This command ends, End(true) is called, and the incoming command is
|
|
|
|
|
* scheduled normally.
|
|
|
|
|
*
|
|
|
|
|
* <p>This is the default behavior.
|
|
|
|
|
*/
|
|
|
|
|
kCancelSelf,
|
|
|
|
|
/** This command continues, and the incoming command is not scheduled. */
|
|
|
|
|
kCancelIncoming
|
|
|
|
|
};
|
|
|
|
|
|
2022-10-06 01:19:28 +03:00
|
|
|
friend class CommandPtr;
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
/**
|
|
|
|
|
* Decorates this command with a timeout. If the specified timeout is
|
|
|
|
|
* exceeded before the command finishes normally, the command will be
|
|
|
|
|
* interrupted and un-scheduled. Note that the timeout only applies to the
|
|
|
|
|
* command returned by this method; the calling command is not itself changed.
|
|
|
|
|
*
|
2019-09-02 23:39:51 -07:00
|
|
|
* @param duration the timeout duration
|
2019-08-25 23:55:59 -04:00
|
|
|
* @return the command with the timeout added
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr WithTimeout(units::second_t duration) &&;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2022-02-04 01:14:52 -05:00
|
|
|
/**
|
|
|
|
|
* Decorates this command with an interrupt condition. If the specified
|
|
|
|
|
* condition becomes true before the command finishes normally, the command
|
|
|
|
|
* will be interrupted and un-scheduled. Note that this only applies to the
|
|
|
|
|
* command returned by this method; the calling command is not itself changed.
|
|
|
|
|
*
|
|
|
|
|
* @param condition the interrupt condition
|
|
|
|
|
* @return the command with the interrupt condition added
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr Until(std::function<bool()> condition) &&;
|
2022-02-04 01:14:52 -05:00
|
|
|
|
2023-04-30 14:09:02 -07:00
|
|
|
/**
|
|
|
|
|
* Decorates this command with a run condition. If the specified condition
|
|
|
|
|
* becomes false before the command finishes normally, the command will be
|
|
|
|
|
* interrupted and un-scheduled. Note that this only applies to the command
|
|
|
|
|
* returned by this method; the calling command is not itself changed.
|
|
|
|
|
*
|
|
|
|
|
* @param condition the interrupt condition
|
|
|
|
|
* @return the command with the interrupt condition added
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr OnlyWhile(std::function<bool()> condition) &&;
|
2023-04-30 14:09:02 -07:00
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
/**
|
|
|
|
|
* Decorates this command with an interrupt condition. If the specified
|
|
|
|
|
* condition becomes true before the command finishes normally, the command
|
|
|
|
|
* will be interrupted and un-scheduled. Note that this only applies to the
|
|
|
|
|
* command returned by this method; the calling command is not itself changed.
|
|
|
|
|
*
|
|
|
|
|
* @param condition the interrupt condition
|
|
|
|
|
* @return the command with the interrupt condition added
|
2022-09-11 20:37:55 +03:00
|
|
|
* @deprecated Replace with Until()
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
2023-06-08 00:01:06 -07:00
|
|
|
[[deprecated("Replace with Until()")]] [[nodiscard]]
|
2023-05-31 22:10:53 -07:00
|
|
|
CommandPtr WithInterrupt(std::function<bool()> condition) &&;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decorates this command with a runnable to run before this command starts.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the Runnable to run
|
2019-11-08 21:30:30 -05:00
|
|
|
* @param requirements the required subsystems
|
2019-08-25 23:55:59 -04:00
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr BeforeStarting(std::function<void()> toRun,
|
|
|
|
|
std::initializer_list<Subsystem*> requirements) &&;
|
2020-01-01 20:09:17 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decorates this command with a runnable to run before this command starts.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the Runnable to run
|
|
|
|
|
* @param requirements the required subsystems
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr BeforeStarting(std::function<void()> toRun,
|
|
|
|
|
std::span<Subsystem* const> requirements = {}) &&;
|
2020-01-01 20:09:17 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decorates this command with a runnable to run after the command finishes.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the Runnable to run
|
|
|
|
|
* @param requirements the required subsystems
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr AndThen(std::function<void()> toRun,
|
|
|
|
|
std::initializer_list<Subsystem*> requirements) &&;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decorates this command with a runnable to run after the command finishes.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the Runnable to run
|
2019-11-08 21:30:30 -05:00
|
|
|
* @param requirements the required subsystems
|
2019-08-25 23:55:59 -04:00
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr AndThen(std::function<void()> toRun,
|
|
|
|
|
std::span<Subsystem* const> requirements = {}) &&;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decorates this command to run perpetually, ignoring its ordinary end
|
|
|
|
|
* conditions. The decorated command can still be interrupted or canceled.
|
|
|
|
|
*
|
|
|
|
|
* @return the decorated command
|
2022-10-21 03:24:54 +03:00
|
|
|
* @deprecated PerpetualCommand violates the assumption that execute() doesn't
|
|
|
|
|
get called after isFinished() returns true -- an assumption that should be
|
|
|
|
|
valid. This was unsafe/undefined behavior from the start, and RepeatCommand
|
|
|
|
|
provides an easy way to achieve similar end results with slightly different (and
|
|
|
|
|
safe) semantics.
|
|
|
|
|
*/
|
2023-06-08 00:01:06 -07:00
|
|
|
[[deprecated(
|
2022-10-21 03:24:54 +03:00
|
|
|
"PerpetualCommand violates the assumption that execute() doesn't get "
|
|
|
|
|
"called after isFinished() returns true -- an assumption that should be "
|
|
|
|
|
"valid."
|
|
|
|
|
"This was unsafe/undefined behavior from the start, and RepeatCommand "
|
|
|
|
|
"provides an easy way to achieve similar end results with slightly "
|
2023-06-08 00:01:06 -07:00
|
|
|
"different (and safe) semantics.")]]
|
2022-09-07 19:04:21 +03:00
|
|
|
PerpetualCommand Perpetually() &&;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2022-04-08 08:02:08 +03:00
|
|
|
/**
|
|
|
|
|
* Decorates this command to run repeatedly, restarting it when it ends, until
|
|
|
|
|
* this command is interrupted. The decorated command can still be canceled.
|
|
|
|
|
*
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr Repeatedly() &&;
|
2022-04-08 08:02:08 +03:00
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
/**
|
2021-06-10 20:46:47 -07:00
|
|
|
* Decorates this command to run "by proxy" by wrapping it in a
|
2022-11-29 00:43:10 +02:00
|
|
|
* ProxyCommand. This is useful for "forking off" from command groups
|
2019-08-25 23:55:59 -04:00
|
|
|
* when the user does not wish to extend the command's requirements to the
|
|
|
|
|
* entire command group.
|
|
|
|
|
*
|
2022-10-06 01:19:28 +03:00
|
|
|
* <p>This overload transfers command ownership to the returned CommandPtr.
|
|
|
|
|
*
|
2019-08-25 23:55:59 -04:00
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr AsProxy() &&;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2022-05-24 10:22:19 -06:00
|
|
|
/**
|
|
|
|
|
* Decorates this command to only run if this condition is not met. If the
|
|
|
|
|
* command is already running and the condition changes to true, the command
|
|
|
|
|
* will not stop running. The requirements of this command will be kept for
|
2022-12-26 14:32:13 -05:00
|
|
|
* the new conditional command.
|
2022-05-24 10:22:19 -06:00
|
|
|
*
|
|
|
|
|
* @param condition the condition that will prevent the command from running
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr Unless(std::function<bool()> condition) &&;
|
2022-05-24 10:22:19 -06:00
|
|
|
|
2023-04-30 14:09:02 -07:00
|
|
|
/**
|
|
|
|
|
* Decorates this command to only run if this condition is met. If the command
|
|
|
|
|
* is already running and the condition changes to false, the command will not
|
|
|
|
|
* stop running. The requirements of this command will be kept for the new
|
|
|
|
|
* conditional command.
|
|
|
|
|
*
|
|
|
|
|
* @param condition the condition that will allow the command to run
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr OnlyIf(std::function<bool()> condition) &&;
|
2023-04-30 14:09:02 -07:00
|
|
|
|
2022-06-24 20:52:53 +03:00
|
|
|
/**
|
|
|
|
|
* Decorates this command to run or stop when disabled.
|
|
|
|
|
*
|
|
|
|
|
* @param doesRunWhenDisabled true to run when disabled.
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr IgnoringDisable(bool doesRunWhenDisabled) &&;
|
2022-06-24 20:52:53 +03:00
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
/**
|
2022-08-30 07:53:47 +03:00
|
|
|
* Decorates this command to run or stop when disabled.
|
2019-08-25 23:55:59 -04:00
|
|
|
*
|
2022-08-30 07:53:47 +03:00
|
|
|
* @param interruptBehavior true to run when disabled.
|
|
|
|
|
* @return the decorated command
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr WithInterruptBehavior(
|
2022-10-06 01:19:28 +03:00
|
|
|
Command::InterruptionBehavior interruptBehavior) &&;
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2022-10-11 19:53:27 +03:00
|
|
|
/**
|
|
|
|
|
* Decorates this command with a lambda to call on interrupt or end, following
|
|
|
|
|
* the command's inherent Command::End(bool) method.
|
|
|
|
|
*
|
|
|
|
|
* @param end a lambda accepting a boolean parameter specifying whether the
|
|
|
|
|
* command was interrupted.
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr FinallyDo(std::function<void(bool)> end) &&;
|
2022-10-11 19:53:27 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decorates this command with a lambda to call on interrupt, following the
|
|
|
|
|
* command's inherent Command::End(bool) method.
|
|
|
|
|
*
|
|
|
|
|
* @param handler a lambda to run when the command is interrupted
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr HandleInterrupt(std::function<void()> handler) &&;
|
2022-10-11 19:53:27 +03:00
|
|
|
|
2022-11-28 10:41:25 -05:00
|
|
|
/**
|
2022-12-16 04:28:52 +02:00
|
|
|
* Decorates this Command with a name.
|
2022-11-28 10:41:25 -05:00
|
|
|
*
|
|
|
|
|
* @param name name
|
|
|
|
|
* @return the decorated Command
|
|
|
|
|
*/
|
2023-05-31 22:10:53 -07:00
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr WithName(std::string_view name) &&;
|
2022-11-28 10:41:25 -05:00
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
/**
|
2022-08-30 07:53:47 +03:00
|
|
|
* Schedules this command.
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
2022-08-30 07:53:47 +03:00
|
|
|
void Schedule();
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
/**
|
2022-08-30 07:53:47 +03:00
|
|
|
* Cancels this command. Will call End(true). Commands will be canceled
|
|
|
|
|
* regardless of interruption behavior.
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
|
|
|
|
void Cancel();
|
|
|
|
|
|
|
|
|
|
/**
|
2022-12-07 07:13:31 +02:00
|
|
|
* Whether or not the command is currently scheduled. Note that this does not
|
|
|
|
|
* detect whether the command is in a composition, only whether it is directly
|
|
|
|
|
* being run by the scheduler.
|
2019-08-25 23:55:59 -04:00
|
|
|
*
|
|
|
|
|
* @return Whether the command is scheduled.
|
|
|
|
|
*/
|
|
|
|
|
bool IsScheduled() const;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-10-14 18:09:38 -07:00
|
|
|
* Whether the command requires a given subsystem. Named "HasRequirement"
|
|
|
|
|
* rather than "requires" to avoid confusion with Command::Requires(Subsystem)
|
|
|
|
|
* -- this may be able to be changed in a few years.
|
2019-08-25 23:55:59 -04:00
|
|
|
*
|
|
|
|
|
* @param requirement the subsystem to inquire about
|
|
|
|
|
* @return whether the subsystem is required
|
|
|
|
|
*/
|
|
|
|
|
bool HasRequirement(Subsystem* requirement) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the command is currently grouped in a command group. Used as extra
|
|
|
|
|
* insurance to prevent accidental independent use of grouped commands.
|
|
|
|
|
*/
|
2022-12-07 07:13:31 +02:00
|
|
|
bool IsComposed() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets whether the command is currently composed in a command composition.
|
|
|
|
|
* Can be used to "reclaim" a command if a composition is no longer going to
|
|
|
|
|
* use it. NOT ADVISED!
|
|
|
|
|
*/
|
|
|
|
|
void SetComposed(bool isComposed);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the command is currently grouped in a command group. Used as extra
|
|
|
|
|
* insurance to prevent accidental independent use of grouped commands.
|
|
|
|
|
*
|
|
|
|
|
* @deprecated Moved to IsComposed()
|
|
|
|
|
*/
|
2023-06-08 00:01:06 -07:00
|
|
|
[[deprecated("Moved to IsComposed()")]]
|
2019-08-25 23:55:59 -04:00
|
|
|
bool IsGrouped() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets whether the command is currently grouped in a command group. Can be
|
|
|
|
|
* used to "reclaim" a command if a group is no longer going to use it. NOT
|
|
|
|
|
* ADVISED!
|
2022-12-07 07:13:31 +02:00
|
|
|
*
|
|
|
|
|
* @deprecated Moved to SetComposed()
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
2023-06-08 00:01:06 -07:00
|
|
|
[[deprecated("Moved to SetComposed()")]]
|
2019-08-25 23:55:59 -04:00
|
|
|
void SetGrouped(bool grouped);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the given command should run when the robot is disabled. Override
|
|
|
|
|
* to return true if the command should run when disabled.
|
|
|
|
|
*
|
|
|
|
|
* @return whether the command should run when the robot is disabled
|
|
|
|
|
*/
|
|
|
|
|
virtual bool RunsWhenDisabled() const { return false; }
|
|
|
|
|
|
2022-08-30 07:53:47 +03:00
|
|
|
/**
|
|
|
|
|
* How the command behaves when another command with a shared requirement is
|
|
|
|
|
* scheduled.
|
|
|
|
|
*
|
|
|
|
|
* @return a variant of InterruptionBehavior, defaulting to kCancelSelf.
|
|
|
|
|
*/
|
|
|
|
|
virtual InterruptionBehavior GetInterruptionBehavior() const {
|
|
|
|
|
return InterruptionBehavior::kCancelSelf;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 10:41:25 -05:00
|
|
|
/**
|
|
|
|
|
* Gets the name of this Command. Defaults to the simple class name if not
|
|
|
|
|
* overridden.
|
|
|
|
|
*
|
|
|
|
|
* @return The display name of the Command
|
|
|
|
|
*/
|
2019-08-25 23:55:59 -04:00
|
|
|
virtual std::string GetName() const;
|
|
|
|
|
|
2022-11-28 10:41:25 -05:00
|
|
|
/**
|
|
|
|
|
* Sets the name of this Command. Nullop if not overridden.
|
|
|
|
|
*
|
|
|
|
|
* @param name The display name of the Command.
|
|
|
|
|
*/
|
|
|
|
|
virtual void SetName(std::string_view name);
|
|
|
|
|
|
2022-11-21 19:45:50 +02:00
|
|
|
/**
|
|
|
|
|
* Transfers ownership of this command to a unique pointer. Used for
|
|
|
|
|
* decorator methods.
|
|
|
|
|
*/
|
|
|
|
|
virtual CommandPtr ToPtr() && = 0;
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* Transfers ownership of this command to a unique pointer. Used for
|
|
|
|
|
* decorator methods.
|
|
|
|
|
*/
|
|
|
|
|
virtual std::unique_ptr<Command> TransferOwnership() && = 0;
|
|
|
|
|
|
2022-12-07 07:13:31 +02:00
|
|
|
bool m_isComposed = false;
|
2019-08-25 23:55:59 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if two commands have disjoint requirement sets.
|
|
|
|
|
*
|
|
|
|
|
* @param first The first command to check.
|
|
|
|
|
* @param second The second command to check.
|
|
|
|
|
* @return False if first and second share a requirement.
|
|
|
|
|
*/
|
|
|
|
|
bool RequirementsDisjoint(Command* first, Command* second);
|
|
|
|
|
} // namespace frc2
|