Add requirements param to more Command APIs (#2059)

Assorted improvements to the ergonomics of declaring requirements in the new
command framework. C++ requirements list parameters have been defaulted
to an empty list, some missing C++ requirements list parameters have been
added, and both C++ and Java have been given requirements list params in
various InstantCommand wrapper methods (#2049), whose value is
forwarded to the command.
This commit is contained in:
Oblarg
2019-11-08 21:30:30 -05:00
committed by Peter Johnson
parent ff39a96cee
commit 00228678d4
18 changed files with 97 additions and 59 deletions

View File

@@ -127,17 +127,21 @@ class Command : public frc::ErrorBase {
* 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
*/
SequentialCommandGroup BeforeStarting(std::function<void()> toRun) &&;
SequentialCommandGroup BeforeStarting(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements = {}) &&;
/**
* 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
*/
SequentialCommandGroup AndThen(std::function<void()> toRun) &&;
SequentialCommandGroup AndThen(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements = {}) &&;
/**
* Decorates this command to run perpetually, ignoring its ordinary end

View File

@@ -35,7 +35,8 @@ class FunctionalCommand : public CommandHelper<CommandBase, FunctionalCommand> {
FunctionalCommand(std::function<void()> onInit,
std::function<void()> onExecute,
std::function<void(bool)> onEnd,
std::function<bool()> isFinished);
std::function<bool()> isFinished,
std::initializer_list<Subsystem*> requirements = {});
FunctionalCommand(FunctionalCommand&& other) = default;

View File

@@ -29,7 +29,7 @@ class InstantCommand : public CommandHelper<CommandBase, InstantCommand> {
* @param requirements the subsystems required by this command
*/
InstantCommand(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
std::initializer_list<Subsystem*> requirements = {});
InstantCommand(InstantCommand&& other) = default;

View File

@@ -37,7 +37,7 @@ class NotifierCommand : public CommandHelper<CommandBase, NotifierCommand> {
* @param requirements the subsystems required by this command
*/
NotifierCommand(std::function<void()> toRun, units::second_t period,
std::initializer_list<Subsystem*> requirements);
std::initializer_list<Subsystem*> requirements = {});
NotifierCommand(NotifierCommand&& other);

View File

@@ -40,7 +40,7 @@ class PIDCommand : public CommandHelper<CommandBase, PIDCommand> {
std::function<double()> measurementSource,
std::function<double()> setpointSource,
std::function<void(double)> useOutput,
std::initializer_list<Subsystem*> requirements);
std::initializer_list<Subsystem*> requirements = {});
/**
* Creates a new PIDCommand, which controls the given output with a

View File

@@ -44,7 +44,7 @@ class ProfiledPIDCommand
std::function<units::meter_t()> measurementSource,
std::function<State()> goalSource,
std::function<void(double, State)> useOutput,
std::initializer_list<Subsystem*> requirements);
std::initializer_list<Subsystem*> requirements = {});
/**
* Creates a new PIDCommand, which controls the given output with a

View File

@@ -91,7 +91,7 @@ class RamseteCommand : public CommandHelper<CommandBase, RamseteCommand> {
frc2::PIDController leftController,
frc2::PIDController rightController,
std::function<void(units::volt_t, units::volt_t)> output,
std::initializer_list<Subsystem*> requirements);
std::initializer_list<Subsystem*> requirements = {});
/**
* Constructs a new RamseteCommand that, when executed, will follow the

View File

@@ -30,7 +30,7 @@ class RunCommand : public CommandHelper<CommandBase, RunCommand> {
* @param requirements the subsystems to require
*/
RunCommand(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
std::initializer_list<Subsystem*> requirements = {});
RunCommand(RunCommand&& other) = default;

View File

@@ -32,7 +32,7 @@ class StartEndCommand : public CommandHelper<CommandBase, StartEndCommand> {
* @param requirements the subsystems required by this command
*/
StartEndCommand(std::function<void()> onInit, std::function<void()> onEnd,
std::initializer_list<Subsystem*> requirements);
std::initializer_list<Subsystem*> requirements = {});
StartEndCommand(StartEndCommand&& other) = default;

View File

@@ -65,8 +65,10 @@ class Button : public Trigger {
* Binds a runnable to execute when the button is pressed.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
*/
Button WhenPressed(std::function<void()> toRun);
Button WhenPressed(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements = {});
/**
* Binds a command to be started repeatedly while the button is pressed, and
@@ -100,8 +102,10 @@ class Button : public Trigger {
* Binds a runnable to execute repeatedly while the button is pressed.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
*/
Button WhileHeld(std::function<void()> toRun);
Button WhileHeld(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements = {});
/**
* Binds a command to be started when the button is pressed, and cancelled
@@ -163,8 +167,10 @@ class Button : public Trigger {
* Binds a runnable to execute when the button is released.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
*/
Button WhenReleased(std::function<void()> toRun);
Button WhenReleased(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements = {});
/**
* Binds a command to start when the button is pressed, and be cancelled when

View File

@@ -96,8 +96,10 @@ class Trigger {
* Binds a runnable to execute when the trigger becomes active.
*
* @param toRun the runnable to execute.
* @paaram requirements the required subsystems.
*/
Trigger WhenActive(std::function<void()> toRun);
Trigger WhenActive(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements = {});
/**
* Binds a command to be started repeatedly while the trigger is active, and
@@ -145,8 +147,10 @@ class Trigger {
* Binds a runnable to execute repeatedly while the trigger is active.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
*/
Trigger WhileActiveContinous(std::function<void()> toRun);
Trigger WhileActiveContinous(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements = {});
/**
* Binds a command to be started when the trigger becomes active, and
@@ -234,8 +238,10 @@ class Trigger {
* Binds a runnable to execute when the trigger becomes inactive.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
*/
Trigger WhenInactive(std::function<void()> toRun);
Trigger WhenInactive(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements = {});
/**
* Binds a command to start when the trigger becomes active, and be cancelled