mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[commands] Enhance Command Sendable implementations (#4822)
This commit is contained in:
@@ -282,8 +282,7 @@ safe) semantics.
|
||||
[[nodiscard]] CommandPtr HandleInterrupt(std::function<void()> handler) &&;
|
||||
|
||||
/**
|
||||
* Decorates this Command with a name. Is an inline function for
|
||||
* #SetName(std::string_view);
|
||||
* Decorates this Command with a name.
|
||||
*
|
||||
* @param name name
|
||||
* @return the decorated Command
|
||||
|
||||
@@ -73,6 +73,8 @@ class ConditionalCommand
|
||||
|
||||
bool RunsWhenDisabled() const override;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Command> m_onTrue;
|
||||
std::unique_ptr<Command> m_onFalse;
|
||||
|
||||
@@ -96,6 +96,8 @@ class ParallelDeadlineGroup
|
||||
|
||||
Command::InterruptionBehavior GetInterruptionBehavior() const override;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
|
||||
|
||||
|
||||
@@ -61,6 +61,8 @@ class ProxyCommand : public CommandHelper<CommandBase, ProxyCommand> {
|
||||
|
||||
bool IsFinished() override;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
wpi::unique_function<Command*()> m_supplier;
|
||||
Command* m_command = nullptr;
|
||||
|
||||
@@ -174,6 +174,8 @@ class RamseteCommand : public CommandHelper<CommandBase, RamseteCommand> {
|
||||
|
||||
bool IsFinished() override;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
frc::Trajectory m_trajectory;
|
||||
std::function<frc::Pose2d()> m_pose;
|
||||
|
||||
@@ -70,6 +70,8 @@ class RepeatCommand : public CommandHelper<CommandBase, RepeatCommand> {
|
||||
|
||||
Command::InterruptionBehavior GetInterruptionBehavior() const override;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Command> m_command;
|
||||
bool m_ended;
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
#include "frc2/command/CommandBase.h"
|
||||
#include "frc2/command/PrintCommand.h"
|
||||
|
||||
@@ -122,6 +125,21 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override {
|
||||
CommandBase::InitSendable(builder);
|
||||
|
||||
builder.AddStringProperty(
|
||||
"selected",
|
||||
[this] {
|
||||
if (m_selectedCommand) {
|
||||
return m_selectedCommand->GetName();
|
||||
} else {
|
||||
return std::string{"null"};
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Command> TransferOwnership() && override {
|
||||
return std::make_unique<SelectCommand>(std::move(*this));
|
||||
|
||||
@@ -91,6 +91,8 @@ class SequentialCommandGroup
|
||||
|
||||
Command::InterruptionBehavior GetInterruptionBehavior() const override;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ class WaitCommand : public CommandHelper<CommandBase, WaitCommand> {
|
||||
|
||||
bool RunsWhenDisabled() const override;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
frc::Timer m_timer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user