mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Clean up new C++ commands (#2027)
- Remove use of std::set. The only place std::set was actually used was in ParallelRaceGroup, but this was of minimal utility as ParallelRaceGroup checked for duplicate subsystem requirements, so it would be very unusual to end up with duplicate commands in any case; replaced it with a vector. - Remove use of std::unordered_map except for SelectCommand. Replaced with vector. - Use pImpl idiom for CommandScheduler - Minimize include files (remove unnecessary ones) - Reformat include file order for consistency
This commit is contained in:
@@ -7,18 +7,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/ErrorBase.h>
|
||||
#include <frc/WPIErrors.h>
|
||||
#include <frc2/command/Subsystem.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <frc/ErrorBase.h>
|
||||
#include <units/units.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/Demangle.h>
|
||||
#include <wpi/SmallSet.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "frc2/command/Subsystem.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/smartdashboard/Sendable.h>
|
||||
#include <frc/smartdashboard/SendableHelper.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
#include <frc/smartdashboard/Sendable.h>
|
||||
#include <frc/smartdashboard/SendableHelper.h>
|
||||
#include <wpi/SmallSet.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "Command.h"
|
||||
#include "frc2/command/Command.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/ErrorBase.h>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include <wpi/ArrayRef.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "Command.h"
|
||||
#include "frc2/command/Command.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
|
||||
@@ -7,22 +7,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <frc/ErrorBase.h>
|
||||
#include <frc/RobotState.h>
|
||||
#include <frc/WPIErrors.h>
|
||||
#include <frc/smartdashboard/Sendable.h>
|
||||
#include <frc/smartdashboard/SendableHelper.h>
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <wpi/DenseMap.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/FunctionExtras.h>
|
||||
#include <wpi/SmallSet.h>
|
||||
|
||||
#include "CommandState.h"
|
||||
|
||||
namespace frc2 {
|
||||
class Command;
|
||||
@@ -46,6 +40,10 @@ class CommandScheduler final : public frc::Sendable,
|
||||
*/
|
||||
static CommandScheduler& GetInstance();
|
||||
|
||||
~CommandScheduler();
|
||||
CommandScheduler(const CommandScheduler&) = delete;
|
||||
CommandScheduler& operator=(const CommandScheduler&) = delete;
|
||||
|
||||
using Action = std::function<void(const Command&)>;
|
||||
|
||||
/**
|
||||
@@ -186,8 +184,9 @@ class CommandScheduler final : public frc::Sendable,
|
||||
"Default commands should not end!");
|
||||
return;
|
||||
}
|
||||
m_subsystems[subsystem] = std::make_unique<std::remove_reference_t<T>>(
|
||||
std::forward<T>(defaultCommand));
|
||||
SetDefaultCommandImpl(subsystem,
|
||||
std::make_unique<std::remove_reference_t<T>>(
|
||||
std::forward<T>(defaultCommand)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,42 +329,11 @@ class CommandScheduler final : public frc::Sendable,
|
||||
// Constructor; private as this is a singleton
|
||||
CommandScheduler();
|
||||
|
||||
// A map from commands to their scheduling state. Also used as a set of the
|
||||
// currently-running commands.
|
||||
wpi::DenseMap<Command*, CommandState> m_scheduledCommands;
|
||||
void SetDefaultCommandImpl(Subsystem* subsystem,
|
||||
std::unique_ptr<Command> command);
|
||||
|
||||
// A map from required subsystems to their requiring commands. Also used as a
|
||||
// set of the currently-required subsystems.
|
||||
wpi::DenseMap<Subsystem*, Command*> m_requirements;
|
||||
|
||||
// A map from subsystems registered with the scheduler to their default
|
||||
// commands. Also used as a list of currently-registered subsystems.
|
||||
wpi::DenseMap<Subsystem*, std::unique_ptr<Command>> m_subsystems;
|
||||
|
||||
// The set of currently-registered buttons that will be polled every
|
||||
// iteration.
|
||||
wpi::SmallVector<wpi::unique_function<void()>, 4> m_buttons;
|
||||
|
||||
bool m_disabled{false};
|
||||
|
||||
// NetworkTable entries for use in Sendable impl
|
||||
nt::NetworkTableEntry m_namesEntry;
|
||||
nt::NetworkTableEntry m_idsEntry;
|
||||
nt::NetworkTableEntry m_cancelEntry;
|
||||
|
||||
// Lists of user-supplied actions to be executed on scheduling events for
|
||||
// every command.
|
||||
wpi::SmallVector<Action, 4> m_initActions;
|
||||
wpi::SmallVector<Action, 4> m_executeActions;
|
||||
wpi::SmallVector<Action, 4> m_interruptActions;
|
||||
wpi::SmallVector<Action, 4> m_finishActions;
|
||||
|
||||
// Flag and queues for avoiding concurrent modification if commands are
|
||||
// scheduled/canceled during run
|
||||
|
||||
bool m_inRunLoop = false;
|
||||
wpi::DenseMap<Command*, bool> m_toSchedule;
|
||||
wpi::SmallVector<Command*, 4> m_toCancel;
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
|
||||
friend class CommandTestBase;
|
||||
};
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandGroupBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include <functional>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,12 +7,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/Notifier.h>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <frc/Notifier.h>
|
||||
#include <units/units.h>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "frc/controller/PIDController.h"
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <frc/controller/PIDController.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "frc/controller/PIDController.h"
|
||||
#include <frc/controller/PIDController.h>
|
||||
|
||||
#include "frc2/command/SubsystemBase.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
@@ -13,12 +13,11 @@
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "CommandGroupBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
@@ -89,7 +88,7 @@ class ParallelCommandGroup
|
||||
private:
|
||||
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
|
||||
|
||||
std::unordered_map<std::unique_ptr<Command>, bool> m_commands;
|
||||
std::vector<std::pair<std::unique_ptr<Command>, bool>> m_commands;
|
||||
bool m_runWhenDisabled{true};
|
||||
bool isRunning = false;
|
||||
};
|
||||
|
||||
@@ -13,12 +13,11 @@
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "CommandGroupBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
@@ -99,7 +98,7 @@ class ParallelDeadlineGroup
|
||||
|
||||
void SetDeadline(std::unique_ptr<Command>&& deadline);
|
||||
|
||||
std::unordered_map<std::unique_ptr<Command>, bool> m_commands;
|
||||
std::vector<std::pair<std::unique_ptr<Command>, bool>> m_commands;
|
||||
Command* m_deadline;
|
||||
bool m_runWhenDisabled{true};
|
||||
bool isRunning = false;
|
||||
|
||||
@@ -13,13 +13,11 @@
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "CommandGroupBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
@@ -78,7 +76,7 @@ class ParallelRaceGroup
|
||||
private:
|
||||
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) override;
|
||||
|
||||
std::set<std::unique_ptr<Command>> m_commands;
|
||||
std::vector<std::unique_ptr<Command>> m_commands;
|
||||
bool m_runWhenDisabled{true};
|
||||
bool m_finished{false};
|
||||
bool isRunning = false;
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandGroupBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -8,10 +8,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <wpi/Twine.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "CommandHelper.h"
|
||||
#include "InstantCommand.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
#include "frc2/command/InstantCommand.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,9 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <frc/controller/ProfiledPIDController.h>
|
||||
#include <units/units.h>
|
||||
|
||||
#include "frc/controller/ProfiledPIDController.h"
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/controller/ProfiledPIDController.h>
|
||||
#include <units/units.h>
|
||||
|
||||
#include "frc/controller/ProfiledPIDController.h"
|
||||
#include "frc2/command/SubsystemBase.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "SetUtilities.h"
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
#include "frc2/command/SetUtilities.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -5,21 +5,22 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
|
||||
#include <frc/controller/PIDController.h>
|
||||
#include <frc/controller/RamseteController.h>
|
||||
#include <frc/geometry/Pose2d.h>
|
||||
#include <frc/kinematics/DifferentialDriveKinematics.h>
|
||||
#include <frc/trajectory/Trajectory.h>
|
||||
#include <frc2/Timer.h>
|
||||
#include <units/units.h>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc/controller/PIDController.h"
|
||||
#include "frc/controller/RamseteController.h"
|
||||
#include "frc/geometry/Pose2d.h"
|
||||
#include "frc/kinematics/DifferentialDriveKinematics.h"
|
||||
#include "frc/trajectory/Trajectory.h"
|
||||
#include "frc2/Timer.h"
|
||||
|
||||
#pragma once
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/ArrayRef.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "SetUtilities.h"
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
#include "frc2/command/SetUtilities.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandGroupBase.h"
|
||||
#include "PrintCommand.h"
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/PrintCommand.h"
|
||||
|
||||
namespace frc2 {
|
||||
template <typename Key>
|
||||
/**
|
||||
* Runs one of a selection of commands, either using a selector and a key to
|
||||
* command mapping, or a supplier that returns the command directly at runtime.
|
||||
@@ -39,6 +39,7 @@ template <typename Key>
|
||||
* <p>As a rule, CommandGroups require the union of the requirements of their
|
||||
* component commands.
|
||||
*/
|
||||
template <typename Key>
|
||||
class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
|
||||
public:
|
||||
/**
|
||||
|
||||
@@ -14,15 +14,16 @@
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <frc/ErrorBase.h>
|
||||
#include <frc/WPIErrors.h>
|
||||
#include <wpi/ArrayRef.h>
|
||||
|
||||
#include "CommandGroupBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc/ErrorBase.h"
|
||||
#include "frc/WPIErrors.h"
|
||||
#include "frc2/command/CommandGroupBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandScheduler.h>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "frc2/command/CommandScheduler.h"
|
||||
|
||||
namespace frc2 {
|
||||
class Command;
|
||||
/**
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <frc/smartdashboard/Sendable.h>
|
||||
#include <frc/smartdashboard/SendableHelper.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Subsystem.h"
|
||||
#include "frc2/command/Subsystem.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -5,15 +5,16 @@
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <frc/trajectory/TrapezoidProfile.h>
|
||||
#include <frc2/Timer.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
|
||||
#pragma once
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,12 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/Timer.h>
|
||||
#include <units/units.h>
|
||||
#include <wpi/Twine.h>
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "CommandHelper.h"
|
||||
#include "frc2/Timer.h"
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
/**
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CommandBase.h"
|
||||
#include "frc/Timer.h"
|
||||
#include <functional>
|
||||
|
||||
#include <units/units.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/CommandHelper.h"
|
||||
|
||||
namespace frc2 {
|
||||
@@ -36,7 +39,7 @@ class WaitUntilCommand : public CommandHelper<CommandBase, WaitUntilCommand> {
|
||||
*
|
||||
* @param time the match time after which to end, in seconds
|
||||
*/
|
||||
explicit WaitUntilCommand(double time);
|
||||
explicit WaitUntilCommand(units::second_t time);
|
||||
|
||||
WaitUntilCommand(WaitUntilCommand&& other) = default;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user