[commands] Remove deprecated classes and functions (#5409)

Removes:
- PerpetualCommand
- Command.perpetually()
- CommandGroupBase
- Command.IsGrouped() (C++ only)
- Command.SetGrouped() (C++ only)
- Command.withInterrupt()
- ProxyScheduleCommand
- Button
- InternalButton, JoystickButton, NetworkButton and POVButton now subclass Trigger
- Old style Trigger functions:
    - Trigger.whenActive
    - Trigger.whileActiveOnce
    - Trigger.whileActiveContinuous
    - Trigger.whenInactive
    - Trigger.toggleWhenActive
    - Trigger.cancelWhenActive
- CommandScheduler.clearButtons()
- CommandScheduler.addButtons() (Java only)
- Command supplier constructor of SelectCommand
This commit is contained in:
Ryan Blue
2023-07-10 12:56:18 -04:00
committed by GitHub
parent b250a03944
commit 7a099cb02a
49 changed files with 82 additions and 2031 deletions

View File

@@ -23,8 +23,6 @@ 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
@@ -147,18 +145,6 @@ class Command {
[[nodiscard]]
CommandPtr OnlyWhile(std::function<bool()> condition) &&;
/**
* 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.
*
* @param condition the interrupt condition
* @return the command with the interrupt condition added
* @deprecated Replace with Until()
*/
[[deprecated("Replace with Until()")]] [[nodiscard]]
CommandPtr WithInterrupt(std::function<bool()> condition) &&;
/**
* Decorates this command with a runnable to run before this command starts.
*
@@ -203,26 +189,6 @@ class Command {
CommandPtr AndThen(std::function<void()> toRun,
std::span<Subsystem* const> requirements = {}) &&;
/**
* Decorates this command to run perpetually, ignoring its ordinary end
* conditions. The decorated command can still be interrupted or canceled.
*
* @return the decorated command
* @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.
*/
[[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.")]]
PerpetualCommand Perpetually() &&;
/**
* Decorates this command to run repeatedly, restarting it when it ends, until
* this command is interrupted. The decorated command can still be canceled.
@@ -361,25 +327,6 @@ safe) semantics.
*/
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()
*/
[[deprecated("Moved to IsComposed()")]]
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!
*
* @deprecated Moved to SetComposed()
*/
[[deprecated("Moved to SetComposed()")]]
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.

View File

@@ -1,31 +0,0 @@
// 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.
#pragma once
#include <memory>
#include <vector>
#include "frc2/command/CommandBase.h"
namespace frc2 {
/**
* A base for CommandGroups.
*
* This class is provided by the NewCommands VendorDep
* @deprecated This class is an empty abstraction. Inherit directly from
* CommandBase.
*/
class CommandGroupBase : public CommandBase {
public:
/**
* Adds the given commands to the command group.
*
* @param commands The commands to add.
*/
virtual void AddCommands(
std::vector<std::unique_ptr<Command>>&& commands) = 0;
};
} // namespace frc2

View File

@@ -77,12 +77,6 @@ class CommandScheduler final : public nt::NTSendable,
*/
frc::EventLoop* GetDefaultButtonLoop() const;
/**
* Removes all button bindings from the scheduler.
*/
[[deprecated("Call Clear on the EventLoop instance directly!")]]
void ClearButtons();
/**
* Schedules a command for execution. Does nothing if the command is already
* scheduled. If a command's requirements are not available, it will only be

View File

@@ -17,7 +17,7 @@
#include <wpi/DecayedDerivedFrom.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -33,7 +33,7 @@ namespace frc2 {
* This class is provided by the NewCommands VendorDep
*/
class ParallelCommandGroup
: public CommandHelper<CommandGroupBase, ParallelCommandGroup> {
: public CommandHelper<CommandBase, ParallelCommandGroup> {
public:
/**
* Creates a new ParallelCommandGroup. The given commands will be executed
@@ -67,6 +67,11 @@ class ParallelCommandGroup
// Prevent template expansion from emulating copy ctor
ParallelCommandGroup(ParallelCommandGroup&) = delete;
/**
* Adds the given commands to the group.
*
* @param commands Commands to add to the group.
*/
template <wpi::DecayedDerivedFrom<Command>... Commands>
void AddCommands(Commands&&... commands) {
std::vector<std::unique_ptr<Command>> foo;
@@ -89,7 +94,7 @@ class ParallelCommandGroup
Command::InterruptionBehavior GetInterruptionBehavior() const override;
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands);
std::vector<std::pair<std::unique_ptr<Command>, bool>> m_commands;
bool m_runWhenDisabled{true};

View File

@@ -17,7 +17,7 @@
#include <wpi/DecayedDerivedFrom.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -34,7 +34,7 @@ namespace frc2 {
* This class is provided by the NewCommands VendorDep
*/
class ParallelDeadlineGroup
: public CommandHelper<CommandGroupBase, ParallelDeadlineGroup> {
: public CommandHelper<CommandBase, ParallelDeadlineGroup> {
public:
/**
* Creates a new ParallelDeadlineGroup. The given commands (including the
@@ -73,6 +73,11 @@ class ParallelDeadlineGroup
// Prevent template expansion from emulating copy ctor
ParallelDeadlineGroup(ParallelDeadlineGroup&) = delete;
/**
* Adds the given commands to the group.
*
* @param commands Commands to add to the group.
*/
template <wpi::DecayedDerivedFrom<Command>... Commands>
void AddCommands(Commands&&... commands) {
std::vector<std::unique_ptr<Command>> foo;
@@ -97,7 +102,7 @@ class ParallelDeadlineGroup
void InitSendable(wpi::SendableBuilder& builder) override;
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands);
void SetDeadline(std::unique_ptr<Command>&& deadline);

View File

@@ -17,7 +17,7 @@
#include <wpi/DecayedDerivedFrom.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -32,8 +32,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class ParallelRaceGroup
: public CommandHelper<CommandGroupBase, ParallelRaceGroup> {
class ParallelRaceGroup : public CommandHelper<CommandBase, ParallelRaceGroup> {
public:
/**
* Creates a new ParallelCommandRace. The given commands will be executed
@@ -57,6 +56,11 @@ class ParallelRaceGroup
// Prevent template expansion from emulating copy ctor
ParallelRaceGroup(ParallelRaceGroup&) = delete;
/**
* Adds the given commands to the group.
*
* @param commands Commands to add to the group.
*/
template <wpi::DecayedDerivedFrom<Command>... Commands>
void AddCommands(Commands&&... commands) {
std::vector<std::unique_ptr<Command>> foo;
@@ -79,7 +83,7 @@ class ParallelRaceGroup
Command::InterruptionBehavior GetInterruptionBehavior() const override;
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands);
std::vector<std::unique_ptr<Command>> m_commands;
bool m_runWhenDisabled{true};

View File

@@ -1,99 +0,0 @@
// 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.
#pragma once
#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 4521)
#endif
#include <concepts>
#include <memory>
#include <utility>
#include <wpi/deprecated.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
/**
* A command that runs another command in perpetuity, ignoring that command's
* end conditions. While this class does not extend frc2::CommandGroupBase,
* it is still considered a CommandGroup, as it allows one to compose another
* command within it; the command instances that are passed to it cannot be
* added to any other groups, or scheduled individually.
*
* <p>As a rule, CommandGroups require the union of the requirements of their
* component commands.
*
* This class is provided by the NewCommands VendorDep
*
* @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.
*/
class PerpetualCommand : public CommandHelper<CommandBase, PerpetualCommand> {
public:
/**
* Creates a new PerpetualCommand. Will run another command in perpetuity,
* ignoring that command's end conditions, unless this command itself is
* interrupted.
*
* @param command the command to run perpetually
*/
WPI_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.")
explicit PerpetualCommand(std::unique_ptr<Command>&& command);
WPI_IGNORE_DEPRECATED
/**
* Creates a new PerpetualCommand. Will run another command in perpetuity,
* ignoring that command's end conditions, unless this command itself is
* interrupted.
*
* @param command the command to run perpetually
*/
template <std::derived_from<Command> T>
WPI_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.")
// NOLINTNEXTLINE(bugprone-forwarding-reference-overload)
explicit PerpetualCommand(T&& command)
: PerpetualCommand(
std::make_unique<std::decay_t<T>>(std::forward<T>(command))) {}
WPI_UNIGNORE_DEPRECATED
PerpetualCommand(PerpetualCommand&& other) = default;
// No copy constructors for command groups
PerpetualCommand(const PerpetualCommand& other) = delete;
// Prevent template expansion from emulating copy ctor
PerpetualCommand(PerpetualCommand&) = delete;
void Initialize() override;
void Execute() override;
void End(bool interrupted) override;
private:
std::unique_ptr<Command> m_command;
};
} // namespace frc2
#ifdef _WIN32
#pragma warning(pop)
#endif

View File

@@ -1,57 +0,0 @@
// 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.
#pragma once
#include <memory>
#include <span>
#include <wpi/SmallVector.h>
#include <wpi/deprecated.h>
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
#include "frc2/command/SetUtilities.h"
namespace frc2 {
/**
* Schedules the given commands when this command is initialized, and ends when
* all the commands are no longer scheduled. Useful for forking off from
* CommandGroups. If this command is interrupted, it will cancel all of the
* commands.
*
* This class is provided by the NewCommands VendorDep
*/
class ProxyScheduleCommand
: public CommandHelper<CommandBase, ProxyScheduleCommand> {
public:
/**
* Creates a new ProxyScheduleCommand that schedules the given commands when
* initialized, and ends when they are all no longer scheduled.
*
* @param toSchedule the commands to schedule
* @deprecated Replace with {@link ProxyCommand},
* composing multiple of them in a {@link ParallelRaceGroup} if needed.
*/
WPI_DEPRECATED("Replace with ProxyCommand")
explicit ProxyScheduleCommand(std::span<Command* const> toSchedule);
explicit ProxyScheduleCommand(Command* toSchedule);
ProxyScheduleCommand(ProxyScheduleCommand&& other) = default;
void Initialize() override;
void End(bool interrupted) override;
void Execute() override;
bool IsFinished() override;
private:
wpi::SmallVector<Command*, 4> m_toSchedule;
std::unique_ptr<Command> m_owning;
bool m_finished{false};
};
} // namespace frc2

View File

@@ -16,7 +16,6 @@
#include <utility>
#include <vector>
#include <wpi/deprecated.h>
#include <wpi/sendable/SendableBuilder.h>
#include "frc2/command/CommandBase.h"
@@ -95,17 +94,6 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
// Prevent template expansion from emulating copy ctor
SelectCommand(SelectCommand&) = delete;
/**
* Creates a new selectcommand.
*
* @param toRun a supplier providing the command to run
* @deprecated Replace with {@link ProxyCommand},
* composing multiple of them in a {@link ParallelRaceGroup} if needed.
*/
WPI_DEPRECATED("Replace with ProxyCommand")
explicit SelectCommand(std::function<Command*()> toRun)
: m_toRun{std::move(toRun)} {}
SelectCommand(SelectCommand&& other) = default;
void Initialize() override;
@@ -147,7 +135,6 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
private:
std::unordered_map<Key, std::unique_ptr<Command>> m_commands;
std::function<Key()> m_selector;
std::function<Command*()> m_toRun;
Command* m_selectedCommand;
bool m_runsWhenDisabled = true;
Command::InterruptionBehavior m_interruptBehavior{
@@ -156,16 +143,12 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
template <typename T>
void SelectCommand<T>::Initialize() {
if (m_selector) {
auto find = m_commands.find(m_selector());
if (find == m_commands.end()) {
m_selectedCommand = new PrintCommand(
"SelectCommand selector value does not correspond to any command!");
return;
}
m_selectedCommand = find->second.get();
auto find = m_commands.find(m_selector());
if (find == m_commands.end()) {
m_selectedCommand = new PrintCommand(
"SelectCommand selector value does not correspond to any command!");
} else {
m_selectedCommand = m_toRun();
m_selectedCommand = find->second.get();
}
m_selectedCommand->Initialize();
}

View File

@@ -19,7 +19,7 @@
#include <wpi/DecayedDerivedFrom.h>
#include "frc2/command/CommandGroupBase.h"
#include "frc2/command/CommandBase.h"
#include "frc2/command/CommandHelper.h"
namespace frc2 {
@@ -37,7 +37,7 @@ const size_t invalid_index = std::numeric_limits<size_t>::max();
* This class is provided by the NewCommands VendorDep
*/
class SequentialCommandGroup
: public CommandHelper<CommandGroupBase, SequentialCommandGroup> {
: public CommandHelper<CommandBase, SequentialCommandGroup> {
public:
/**
* Creates a new SequentialCommandGroup. The given commands will be run
@@ -69,6 +69,11 @@ class SequentialCommandGroup
// Prevent template expansion from emulating copy ctor
SequentialCommandGroup(SequentialCommandGroup&) = delete;
/**
* Adds the given commands to the group.
*
* @param commands Commands to add, in order of execution.
*/
template <wpi::DecayedDerivedFrom<Command>... Commands>
void AddCommands(Commands&&... commands) {
std::vector<std::unique_ptr<Command>> foo;
@@ -93,7 +98,7 @@ class SequentialCommandGroup
void InitSendable(wpi::SendableBuilder& builder) override;
private:
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands);
wpi::SmallVector<std::unique_ptr<Command>, 4> m_commands;
size_t m_currentCommandIndex{invalid_index};

View File

@@ -1,269 +0,0 @@
// 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.
#pragma once
#include <concepts>
#include <functional>
#include <initializer_list>
#include <span>
#include <utility>
#include <wpi/deprecated.h>
#include "Trigger.h"
#include "frc2/command/CommandPtr.h"
namespace frc2 {
class Command;
/**
* A class used to bind command scheduling to button presses. Can be composed
* with other buttons with the operators in Trigger.
*
* This class is provided by the NewCommands VendorDep
*
* @see Trigger
*/
class Button : public Trigger {
public:
/**
* Create a new button that is pressed when the given condition is true.
*
* @param isPressed Whether the button is pressed.
* @deprecated Replace with Trigger
*/
WPI_DEPRECATED("Replace with Trigger")
explicit Button(std::function<bool()> isPressed);
/**
* Create a new button that is pressed active (default constructor) - activity
* can be further determined by subclass code.
* @deprecated Replace with Trigger
*/
[[deprecated("Replace with Trigger")]] Button() = default;
/**
* Binds a command to start when the button is pressed. Takes a
* raw pointer, and so is non-owning; users are responsible for the lifespan
* of the command.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Replace with Trigger::OnTrue()
*/
[[deprecated("Replace with Trigger#OnTrue()")]]
Button WhenPressed(Command* command);
/**
* Binds a command to start when the button is pressed. Transfers
* command ownership to the button scheduler, so the user does not have to
* worry about lifespan - rvalue refs will be *moved*, lvalue refs will be
* *copied.*
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Replace with Trigger::OnTrue()
*/
template <std::derived_from<Command> T>
[[deprecated("Replace with Trigger#OnTrue()")]]
Button WhenPressed(T&& command) {
WhenActive(std::forward<T>(command));
return *this;
}
/**
* Binds a runnable to execute when the button is pressed.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Replace with Trigger::OnTrue(cmd::RunOnce())
*/
[[deprecated("Replace with Trigger#OnTrue(cmd::RunOnce())")]]
Button WhenPressed(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
/**
* Binds a runnable to execute when the button is pressed.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Replace with Trigger::OnTrue(cmd::RunOnce())
*/
[[deprecated("Replace with Trigger#OnTrue(cmd::RunOnce())")]]
Button WhenPressed(std::function<void()> toRun,
std::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started repeatedly while the button is pressed, and
* canceled when it is released. Takes a raw pointer, and so is non-owning;
* users are responsible for the lifespan of the command.
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Replace with Trigger::WhileTrue(command.Repeatedly())
*/
[[deprecated("Replace with Trigger#WhileTrue(command.Repeatedly())")]]
Button WhileHeld(Command* command);
/**
* Binds a command to be started repeatedly while the button is pressed, and
* canceled when it is released. Transfers command ownership to the button
* scheduler, so the user does not have to worry about lifespan - rvalue refs
* will be *moved*, lvalue refs will be *copied.*
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Replace with Trigger::WhileTrue(command.Repeatedly())
*/
template <std::derived_from<Command> T>
[[deprecated("Replace with Trigger#WhileTrue(command.Repeatedly())")]]
Button WhileHeld(T&& command) {
WhileActiveContinous(std::forward<T>(command));
return *this;
}
/**
* Binds a runnable to execute repeatedly while the button is pressed.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Replace with Trigger::WhileTrue(cmd::Run())
*/
[[deprecated("Replace with Trigger#WhileTrue(cmd::Run())")]]
Button WhileHeld(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
/**
* Binds a runnable to execute repeatedly while the button is pressed.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Replace with Trigger::WhileTrue(cmd::Run())
*/
[[deprecated("Replace with Trigger#WhileTrue(cmd::Run())")]]
Button WhileHeld(std::function<void()> toRun,
std::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started when the button is pressed, and canceled
* when it is released. Takes a raw pointer, and so is non-owning; users are
* responsible for the lifespan of the command.
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Replace with Trigger::WhileTrue()
*/
[[deprecated("Replace with Trigger#WhileTrue()")]]
Button WhenHeld(Command* command);
/**
* Binds a command to be started when the button is pressed, and canceled
* when it is released. Transfers command ownership to the button scheduler,
* so the user does not have to worry about lifespan - rvalue refs will be
* *moved*, lvalue refs will be *copied.*
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Replace with Trigger::WhileTrue()
*/
template <std::derived_from<Command> T>
[[deprecated("Replace with Trigger#WhileTrue()")]]
Button WhenHeld(T&& command) {
WhileActiveOnce(std::forward<T>(command));
return *this;
}
/**
* Binds a command to start when the button is released. Takes a
* raw pointer, and so is non-owning; users are responsible for the lifespan
* of the command.
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Replace with Trigger::OnFalse()
*/
[[deprecated("Replace with Trigger#OnFalse()")]]
Button WhenReleased(Command* command);
/**
* Binds a command to start when the button is pressed. Transfers
* command ownership to the button scheduler, so the user does not have to
* worry about lifespan - rvalue refs will be *moved*, lvalue refs will be
* *copied.*
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Replace with Trigger::OnFalse()
*/
template <std::derived_from<Command> T>
[[deprecated("Replace with Trigger#OnFalse()")]]
Button WhenReleased(T&& command) {
WhenInactive(std::forward<T>(command));
return *this;
}
/**
* Binds a runnable to execute when the button is released.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Replace with Trigger::OnFalse(cmd::RunOnce())
*/
[[deprecated("Replace with Trigger#OnFalse(cmd::RunOnce())")]]
Button WhenReleased(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
/**
* Binds a runnable to execute when the button is released.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Replace with Trigger::OnFalse(cmd::RunOnce())
*/
[[deprecated("Replace with Trigger#OnFalse(cmd::RunOnce())")]]
Button WhenReleased(std::function<void()> toRun,
std::span<Subsystem* const> requirements = {});
/**
* Binds a command to start when the button is pressed, and be canceled when
* it is pressed again. Takes a raw pointer, and so is non-owning; users are
* responsible for the lifespan of the command.
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Replace with Trigger::ToggleOnTrue()
*/
[[deprecated("Replace with Trigger#ToggleOnTrue()")]]
Button ToggleWhenPressed(Command* command);
/**
* Binds a command to start when the button is pressed, and be canceled when
* it is pressed again. Transfers command ownership to the button scheduler,
* so the user does not have to worry about lifespan - rvalue refs will be
* *moved*, lvalue refs will be *copied.*
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Replace with Trigger::ToggleOnTrue()
*/
template <std::derived_from<Command> T>
[[deprecated("Replace with Trigger#ToggleOnTrue()")]]
Button ToggleWhenPressed(T&& command) {
ToggleWhenActive(std::forward<T>(command));
return *this;
}
/**
* Binds a command to be canceled when the button is pressed. Takes a
* raw pointer, and so is non-owning; users are responsible for the lifespan
* and scheduling of the command.
*
* @param command The command to bind.
* @return The button, for chained calls.
* @deprecated Pass this as a command end condition with Until() instead.
*/
[[deprecated("Pass this as a command end condition with Until() instead.")]]
Button CancelWhenPressed(Command* command);
};
} // namespace frc2

View File

@@ -4,9 +4,8 @@
#pragma once
#include <frc/GenericHID.h>
#include <wpi/deprecated.h>
#include "Button.h"
#include "Trigger.h"
namespace frc2 {
/**
@@ -17,7 +16,7 @@ namespace frc2 {
*
* @see Trigger
*/
class JoystickButton : public Button {
class JoystickButton : public Trigger {
public:
/**
* Creates a JoystickButton that commands can be bound to.
@@ -25,11 +24,9 @@ class JoystickButton : public Button {
* @param joystick The joystick on which the button is located.
* @param buttonNumber The number of the button on the joystick.
*/
WPI_IGNORE_DEPRECATED
explicit JoystickButton(frc::GenericHID* joystick, int buttonNumber)
: Button([joystick, buttonNumber] {
: Trigger([joystick, buttonNumber] {
return joystick->GetRawButton(buttonNumber);
}) {}
WPI_UNIGNORE_DEPRECATED
};
} // namespace frc2

View File

@@ -11,7 +11,7 @@
#include <networktables/NetworkTable.h>
#include <networktables/NetworkTableInstance.h>
#include "Button.h"
#include "Trigger.h"
namespace frc2 {
/**
@@ -19,7 +19,7 @@ namespace frc2 {
*
* This class is provided by the NewCommands VendorDep
*/
class NetworkButton : public Button {
class NetworkButton : public Trigger {
public:
/**
* Creates a NetworkButton that commands can be bound to.

View File

@@ -5,9 +5,8 @@
#pragma once
#include <frc/GenericHID.h>
#include <wpi/deprecated.h>
#include "Button.h"
#include "Trigger.h"
namespace frc2 {
/**
@@ -18,7 +17,7 @@ namespace frc2 {
*
* @see Trigger
*/
class POVButton : public Button {
class POVButton : public Trigger {
public:
/**
* Creates a POVButton that commands can be bound to.
@@ -27,11 +26,9 @@ class POVButton : public Button {
* @param angle The angle of the POV corresponding to a button press.
* @param povNumber The number of the POV on the joystick.
*/
WPI_IGNORE_DEPRECATED
POVButton(frc::GenericHID* joystick, int angle, int povNumber = 0)
: Button([joystick, angle, povNumber] {
: Trigger([joystick, angle, povNumber] {
return joystick->GetPOV(povNumber) == angle;
}) {}
WPI_UNIGNORE_DEPRECATED
};
} // namespace frc2

View File

@@ -204,305 +204,6 @@ class Trigger {
*/
Trigger ToggleOnFalse(CommandPtr&& command);
/**
* Binds a command to start when the trigger becomes active. Takes a
* raw pointer, and so is non-owning; users are responsible for the lifespan
* of the command.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use OnTrue(Command) instead
*/
[[deprecated("Use OnTrue(Command) instead")]]
Trigger WhenActive(Command* command);
/**
* Binds a command to start when the trigger becomes active. Transfers
* command ownership to the button scheduler, so the user does not have to
* worry about lifespan - rvalue refs will be *moved*, lvalue refs will be
* *copied.*
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use OnTrue(Command) instead
*/
template <std::derived_from<Command> T>
[[deprecated("Use OnTrue(Command) instead")]]
Trigger WhenActive(T&& command) {
m_loop->Bind([condition = m_condition, previous = m_condition(),
command = std::make_unique<std::decay_t<T>>(
std::forward<T>(command))]() mutable {
bool current = condition();
if (!previous && current) {
command->Schedule();
}
previous = current;
});
return *this;
}
/**
* Binds a runnable to execute when the trigger becomes active.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Use OnTrue(Command) instead and construct the InstantCommand
* manually
*/
[[deprecated(
"Use OnTrue(Command) instead and construct the InstantCommand manually")]]
Trigger WhenActive(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
/**
* Binds a runnable to execute when the trigger becomes active.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Use OnTrue(Command) instead and construct the InstantCommand
* manually
*/
[[deprecated(
"Use OnTrue(Command) instead and construct the InstantCommand manually")]]
Trigger WhenActive(std::function<void()> toRun,
std::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started repeatedly while the trigger is active, and
* canceled when it becomes inactive. Takes a raw pointer, and so is
* non-owning; users are responsible for the lifespan of the command.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use WhileTrue(Command) with RepeatCommand, or bind
command::Schedule with IfHigh(std::function<void()>).
*/
[[deprecated(
"Use WhileTrue(Command) with RepeatCommand, or bind command::Schedule "
"with IfHigh(std::function<void()>).")]]
Trigger WhileActiveContinous(Command* command);
/**
* Binds a command to be started repeatedly while the trigger is active, and
* canceled when it becomes inactive. Transfers command ownership to the
* button scheduler, so the user does not have to worry about lifespan -
* rvalue refs will be *moved*, lvalue refs will be *copied.*
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use WhileTrue(Command) with RepeatCommand, or bind
command::Schedule with IfHigh(std::function<void()>).
*/
template <std::derived_from<Command> T>
[[deprecated(
"Use WhileTrue(Command) with RepeatCommand, or bind command::Schedule "
"with IfHigh(std::function<void()>).")]]
Trigger WhileActiveContinous(T&& command) {
m_loop->Bind([condition = m_condition, previous = m_condition(),
command = std::make_unique<std::decay_t<T>>(
std::forward<T>(command))]() mutable {
bool current = condition();
if (current) {
command->Schedule();
} else if (previous && !current) {
command->Cancel();
}
previous = current;
});
return *this;
}
/**
* Binds a runnable to execute repeatedly while the trigger is active.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Use WhileTrue(Command) and construct a RunCommand manually
*/
[[deprecated("Use WhileTrue(Command) and construct a RunCommand manually")]]
Trigger WhileActiveContinous(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
/**
* Binds a runnable to execute repeatedly while the trigger is active.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Use WhileTrue(Command) and construct a RunCommand manually
*/
[[deprecated("Use WhileTrue(Command) and construct a RunCommand manually")]]
Trigger WhileActiveContinous(std::function<void()> toRun,
std::span<Subsystem* const> requirements = {});
/**
* Binds a command to be started when the trigger becomes active, and
* canceled when it becomes inactive. Takes a raw pointer, and so is
* non-owning; users are responsible for the lifespan of the command.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use WhileTrue(Command) instead.
*/
[[deprecated("Use WhileTrue(Command) instead.")]]
Trigger WhileActiveOnce(Command* command);
/**
* Binds a command to be started when the trigger becomes active, and
* canceled when it becomes inactive. Transfers command ownership to the
* button scheduler, so the user does not have to worry about lifespan -
* rvalue refs will be *moved*, lvalue refs will be *copied.*
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use WhileTrue(Command) instead.
*/
template <std::derived_from<Command> T>
[[deprecated("Use WhileTrue(Command) instead.")]]
Trigger WhileActiveOnce(T&& command) {
m_loop->Bind([condition = m_condition, previous = m_condition(),
command = std::make_unique<std::decay_t<T>>(
std::forward<T>(command))]() mutable {
bool current = condition();
if (!previous && current) {
command->Schedule();
} else if (previous && !current) {
command->Cancel();
}
previous = current;
});
return *this;
}
/**
* Binds a command to start when the trigger becomes inactive. Takes a
* raw pointer, and so is non-owning; users are responsible for the lifespan
* of the command.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use OnFalse(Command) instead.
*/
[[deprecated("Use OnFalse(Command) instead.")]]
Trigger WhenInactive(Command* command);
/**
* Binds a command to start when the trigger becomes inactive. Transfers
* command ownership to the button scheduler, so the user does not have to
* worry about lifespan - rvalue refs will be *moved*, lvalue refs will be
* *copied.*
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use OnFalse(Command) instead.
*/
template <std::derived_from<Command> T>
[[deprecated("Use OnFalse(Command) instead.")]]
Trigger WhenInactive(T&& command) {
m_loop->Bind([condition = m_condition, previous = m_condition(),
command = std::make_unique<std::decay_t<T>>(
std::forward<T>(command))]() mutable {
bool current = condition();
if (previous && !current) {
command->Schedule();
}
previous = current;
});
return *this;
}
/**
* Binds a runnable to execute when the trigger becomes inactive.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Use OnFalse(Command) instead and construct the InstantCommand
* manually
*/
[[deprecated(
"Use OnFalse(Command) instead and construct the InstantCommand "
"manually")]]
Trigger WhenInactive(std::function<void()> toRun,
std::initializer_list<Subsystem*> requirements);
/**
* Binds a runnable to execute when the trigger becomes inactive.
*
* @param toRun the runnable to execute.
* @param requirements the required subsystems.
* @deprecated Use OnFalse(Command) instead and construct the InstantCommand
* manually
*/
[[deprecated(
"Use OnFalse(Command) instead and construct the InstantCommand "
"manually")]]
Trigger WhenInactive(std::function<void()> toRun,
std::span<Subsystem* const> requirements = {});
/**
* Binds a command to start when the trigger becomes active, and be canceled
* when it again becomes active. Takes a raw pointer, and so is non-owning;
* users are responsible for the lifespan of the command.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use ToggleOnTrue(Command) instead.
*/
[[deprecated("Use ToggleOnTrue(Command) instead.")]]
Trigger ToggleWhenActive(Command* command);
/**
* Binds a command to start when the trigger becomes active, and be canceled
* when it again becomes active. Transfers command ownership to the button
* scheduler, so the user does not have to worry about lifespan - rvalue refs
* will be *moved*, lvalue refs will be *copied.*
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Use ToggleOnTrue(Command) instead.
*/
template <std::derived_from<Command> T>
[[deprecated("Use ToggleOnTrue(Command) instead.")]]
Trigger ToggleWhenActive(T&& command) {
m_loop->Bind([condition = m_condition, previous = m_condition(),
command = std::make_unique<std::decay_t<T>>(
std::forward<T>(command))]() mutable {
bool current = condition();
if (!previous && current) {
if (command->IsScheduled()) {
command->Cancel();
} else {
command->Schedule();
}
}
previous = current;
});
return *this;
}
/**
* Binds a command to be canceled when the trigger becomes active. Takes a
* raw pointer, and so is non-owning; users are responsible for the lifespan
* and scheduling of the command.
*
* @param command The command to bind.
* @return The trigger, for chained calls.
* @deprecated Pass this as a command end condition with Until() instead.
*/
[[deprecated("Pass this as a command end condition with Until() instead.")]]
Trigger CancelWhenActive(Command* command);
/**
* Composes two triggers with logical AND.
*