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>
|
2019-08-25 23:55:59 -04:00
|
|
|
#include <memory>
|
2023-12-09 19:45:02 +02:00
|
|
|
#include <optional>
|
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>
|
2023-12-09 19:45:02 +02:00
|
|
|
#include <wpi/StackTrace.h>
|
2023-07-14 01:12:01 -04:00
|
|
|
#include <wpi/sendable/Sendable.h>
|
2019-11-05 20:52:49 -08:00
|
|
|
|
2023-09-17 20:48:39 -07:00
|
|
|
#include "frc2/command/Requirements.h"
|
2019-11-05 20:52:49 -08:00
|
|
|
#include "frc2/command/Subsystem.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
namespace frc2 {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2023-07-14 01:12:01 -04:00
|
|
|
class Command : public wpi::Sendable, public wpi::SendableHelper<Command> {
|
2019-08-25 23:55:59 -04:00
|
|
|
public:
|
2023-07-14 01:12:01 -04:00
|
|
|
~Command() override;
|
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
|
|
|
*/
|
2023-07-14 01:12:01 -04:00
|
|
|
virtual wpi::SmallSet<Subsystem*, 4> GetRequirements() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds the specified Subsystem requirements to the command.
|
|
|
|
|
*
|
|
|
|
|
* The scheduler will prevent two commands that require the same subsystem
|
|
|
|
|
* from being scheduled simultaneously.
|
|
|
|
|
*
|
|
|
|
|
* Note that the scheduler determines the requirements of a command when it
|
|
|
|
|
* is scheduled, so this method should normally be called from the command's
|
|
|
|
|
* constructor.
|
|
|
|
|
*
|
2023-09-17 20:48:39 -07:00
|
|
|
* While this overload can be used with {@code AddRequirements({&subsystem1,
|
|
|
|
|
* &subsystem2})}, {@code AddRequirements({&subsystem})} selects the {@code
|
|
|
|
|
* AddRequirements(Subsystem*)} overload, which will function identically but
|
|
|
|
|
* may cause warnings about redundant braces.
|
2023-07-14 01:12:01 -04:00
|
|
|
*
|
2023-09-17 20:48:39 -07:00
|
|
|
* @param requirements the Subsystem requirements to add, which can be
|
|
|
|
|
* implicitly constructed from an initializer list or a span
|
2023-07-14 01:12:01 -04:00
|
|
|
*/
|
2023-09-17 20:48:39 -07:00
|
|
|
void AddRequirements(Requirements requirements);
|
2023-07-14 01:12:01 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds the specified Subsystem requirements to the command.
|
|
|
|
|
*
|
|
|
|
|
* The scheduler will prevent two commands that require the same subsystem
|
|
|
|
|
* from being scheduled simultaneously.
|
|
|
|
|
*
|
|
|
|
|
* Note that the scheduler determines the requirements of a command when it
|
|
|
|
|
* is scheduled, so this method should normally be called from the command's
|
|
|
|
|
* constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param requirements the Subsystem requirements to add
|
|
|
|
|
*/
|
|
|
|
|
void AddRequirements(wpi::SmallSet<Subsystem*, 4> requirements);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds the specified Subsystem requirement to the command.
|
|
|
|
|
*
|
|
|
|
|
* The scheduler will prevent two commands that require the same subsystem
|
|
|
|
|
* from being scheduled simultaneously.
|
|
|
|
|
*
|
|
|
|
|
* Note that the scheduler determines the requirements of a command when it
|
|
|
|
|
* is scheduled, so this method should normally be called from the command's
|
|
|
|
|
* constructor.
|
|
|
|
|
*
|
|
|
|
|
* @param requirement the Subsystem requirement to add
|
|
|
|
|
*/
|
|
|
|
|
void AddRequirements(Subsystem* requirement);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the name of this Command.
|
|
|
|
|
*
|
|
|
|
|
* @return Name
|
|
|
|
|
*/
|
|
|
|
|
std::string GetName() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the name of this Command.
|
|
|
|
|
*
|
|
|
|
|
* @param name name
|
|
|
|
|
*/
|
|
|
|
|
void SetName(std::string_view name);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the subsystem name of this Command.
|
|
|
|
|
*
|
|
|
|
|
* @return Subsystem name
|
|
|
|
|
*/
|
|
|
|
|
std::string GetSubsystem() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the subsystem name of this Command.
|
|
|
|
|
*
|
|
|
|
|
* @param subsystem subsystem name
|
|
|
|
|
*/
|
|
|
|
|
void SetSubsystem(std::string_view subsystem);
|
2019-08-25 23:55:59 -04:00
|
|
|
|
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
|
|
|
/**
|
2023-06-22 19:43:51 -07:00
|
|
|
* Decorates this command with a timeout. If the specified timeout is
|
2019-08-25 23:55:59 -04:00
|
|
|
* exceeded before the command finishes normally, the command will be
|
2023-06-22 19:43:51 -07:00
|
|
|
* interrupted and un-scheduled.
|
2019-08-25 23:55:59 -04:00
|
|
|
*
|
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
|
|
|
/**
|
2023-06-22 19:43:51 -07:00
|
|
|
* Decorates this command with an interrupt condition. If the specified
|
2022-02-04 01:14:52 -05:00
|
|
|
* condition becomes true before the command finishes normally, the command
|
2023-06-22 19:43:51 -07:00
|
|
|
* will be interrupted and un-scheduled.
|
2022-02-04 01:14:52 -05:00
|
|
|
*
|
|
|
|
|
* @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
|
|
|
/**
|
2023-06-22 19:43:51 -07:00
|
|
|
* Decorates this command with a run condition. If the specified condition
|
2023-04-30 14:09:02 -07:00
|
|
|
* becomes false before the command finishes normally, the command will be
|
2023-06-22 19:43:51 -07:00
|
|
|
* interrupted and un-scheduled.
|
2023-04-30 14:09:02 -07:00
|
|
|
*
|
2023-06-22 19:43:51 -07:00
|
|
|
* @param condition the run condition
|
|
|
|
|
* @return the command with the run condition added
|
2023-04-30 14:09:02 -07:00
|
|
|
*/
|
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 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,
|
2023-09-17 20:48:39 -07:00
|
|
|
Requirements 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,
|
2023-09-17 20:48:39 -07:00
|
|
|
Requirements requirements = {}) &&;
|
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
|
|
|
/**
|
2023-06-22 19:43:51 -07:00
|
|
|
* Decorates this command to have a different interrupt behavior.
|
2019-08-25 23:55:59 -04:00
|
|
|
*
|
2023-06-22 19:43:51 -07:00
|
|
|
* @param interruptBehavior the desired interrupt behavior
|
2022-08-30 07:53:47 +03:00
|
|
|
* @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
|
|
|
|
2023-11-03 15:21:21 -07:00
|
|
|
/**
|
|
|
|
|
* Decorates this command with a lambda to call on interrupt or end, following
|
|
|
|
|
* the command's inherent Command::End(bool) method. The provided lambda will
|
|
|
|
|
* run identically in both interrupt and end cases.
|
|
|
|
|
*
|
|
|
|
|
* @param end a lambda to run when the command ends, whether or not it was
|
|
|
|
|
* interrupted.
|
|
|
|
|
* @return the decorated command
|
|
|
|
|
*/
|
|
|
|
|
[[nodiscard]]
|
|
|
|
|
CommandPtr FinallyDo(std::function<void()> 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);
|
|
|
|
|
|
2023-12-09 19:45:02 +02:00
|
|
|
/**
|
|
|
|
|
* Get the stacktrace of where this command was composed, or an empty
|
|
|
|
|
* optional. Intended for internal use.
|
|
|
|
|
*
|
|
|
|
|
* @return optional string representation of the composition site stack trace.
|
|
|
|
|
*/
|
|
|
|
|
std::optional<std::string> GetPreviousCompositionSite() const;
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
/**
|
|
|
|
|
* 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-21 19:45:50 +02:00
|
|
|
/**
|
|
|
|
|
* Transfers ownership of this command to a unique pointer. Used for
|
|
|
|
|
* decorator methods.
|
|
|
|
|
*/
|
|
|
|
|
virtual CommandPtr ToPtr() && = 0;
|
|
|
|
|
|
2023-07-14 01:12:01 -04:00
|
|
|
void InitSendable(wpi::SendableBuilder& builder) override;
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
protected:
|
2023-07-14 01:12:01 -04:00
|
|
|
Command();
|
|
|
|
|
|
|
|
|
|
wpi::SmallSet<Subsystem*, 4> m_requirements;
|
|
|
|
|
|
2019-08-25 23:55:59 -04:00
|
|
|
/**
|
|
|
|
|
* Transfers ownership of this command to a unique pointer. Used for
|
|
|
|
|
* decorator methods.
|
|
|
|
|
*/
|
2023-12-26 13:14:34 -08:00
|
|
|
[[deprecated("Use ToPtr() instead")]]
|
2019-08-25 23:55:59 -04:00
|
|
|
virtual std::unique_ptr<Command> TransferOwnership() && = 0;
|
|
|
|
|
|
2023-12-09 19:45:02 +02:00
|
|
|
std::optional<std::string> m_previousComposition;
|
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
|