[commands] Enhance Command Sendable implementations (#4822)

This commit is contained in:
Starlight220
2022-12-16 04:28:52 +02:00
committed by GitHub
parent 7713f68772
commit fbabd0ef15
33 changed files with 239 additions and 17 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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));

View File

@@ -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;

View File

@@ -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;