mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-06 03:31:43 +00:00
[commands] Enhance Command Sendable implementations (#4822)
This commit is contained in:
@@ -446,14 +446,15 @@ public interface Command {
|
||||
default void setName(String name) {}
|
||||
|
||||
/**
|
||||
* Decorates this Command with a name. Is an inline function for #setName(String);
|
||||
* Decorates this Command with a name.
|
||||
*
|
||||
* @param name name
|
||||
* @return the decorated Command
|
||||
*/
|
||||
default Command withName(String name) {
|
||||
this.setName(name);
|
||||
return this;
|
||||
default WrapperCommand withName(String name) {
|
||||
WrapperCommand wrapper = new WrapperCommand(Command.this) {};
|
||||
wrapper.setName(name);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,12 +56,6 @@ public abstract class CommandBase implements Sendable, Command {
|
||||
SendableRegistry.setName(this, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandBase withName(String name) {
|
||||
this.setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the subsystem name of this Command.
|
||||
*
|
||||
@@ -105,5 +99,8 @@ public abstract class CommandBase implements Sendable, Command {
|
||||
});
|
||||
builder.addBooleanProperty(
|
||||
".isParented", () -> CommandScheduler.getInstance().isComposed(this), null);
|
||||
builder.addStringProperty(
|
||||
"interruptBehavior", () -> getInterruptionBehavior().toString(), null);
|
||||
builder.addBooleanProperty("runsWhenDisabled", this::runsWhenDisabled, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
/**
|
||||
@@ -71,4 +72,21 @@ public class ConditionalCommand extends CommandBase {
|
||||
public boolean runsWhenDisabled() {
|
||||
return m_onTrue.runsWhenDisabled() && m_onFalse.runsWhenDisabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
super.initSendable(builder);
|
||||
builder.addStringProperty("onTrue", m_onTrue::getName, null);
|
||||
builder.addStringProperty("onFalse", m_onFalse::getName, null);
|
||||
builder.addStringProperty(
|
||||
"selected",
|
||||
() -> {
|
||||
if (m_selectedCommand == null) {
|
||||
return "null";
|
||||
} else {
|
||||
return m_selectedCommand.getName();
|
||||
}
|
||||
},
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -130,4 +131,11 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
super.initSendable(builder);
|
||||
|
||||
builder.addStringProperty("deadline", m_deadline::getName, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -36,6 +37,7 @@ public class ProxyCommand extends CommandBase {
|
||||
*/
|
||||
public ProxyCommand(Command command) {
|
||||
this(() -> command);
|
||||
setName("Proxy(" + command.getName() + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,4 +75,11 @@ public class ProxyCommand extends CommandBase {
|
||||
public boolean runsWhenDisabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
super.initSendable(builder);
|
||||
builder.addStringProperty(
|
||||
"proxied", () -> m_command == null ? "null" : m_command.getName(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import edu.wpi.first.math.kinematics.ChassisSpeeds;
|
||||
import edu.wpi.first.math.kinematics.DifferentialDriveKinematics;
|
||||
import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds;
|
||||
import edu.wpi.first.math.trajectory.Trajectory;
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Supplier;
|
||||
@@ -211,4 +212,11 @@ public class RamseteCommand extends CommandBase {
|
||||
public boolean isFinished() {
|
||||
return m_timer.hasElapsed(m_trajectory.getTotalTimeSeconds());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
super.initSendable(builder);
|
||||
builder.addDoubleProperty("leftVelocity", () -> m_prevSpeeds.leftMetersPerSecond, null);
|
||||
builder.addDoubleProperty("rightVelocity", () -> m_prevSpeeds.rightMetersPerSecond, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
|
||||
/**
|
||||
* A command that runs another command repeatedly, restarting it when it ends, until this command is
|
||||
* interrupted. Command instances that are passed to it cannot be added to any other groups, or
|
||||
@@ -31,6 +33,7 @@ public class RepeatCommand extends CommandBase {
|
||||
m_command = requireNonNullParam(command, "command", "RepeatCommand");
|
||||
CommandScheduler.getInstance().registerComposedCommands(command);
|
||||
m_requirements.addAll(command.getRequirements());
|
||||
setName("Repeat(" + command.getName() + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,4 +75,10 @@ public class RepeatCommand extends CommandBase {
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_command.getInterruptionBehavior();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
super.initSendable(builder);
|
||||
builder.addStringProperty("command", m_command::getName, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -108,4 +109,12 @@ public class SelectCommand extends CommandBase {
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
super.initSendable(builder);
|
||||
|
||||
builder.addStringProperty(
|
||||
"selected", () -> m_selectedCommand == null ? "null" : m_selectedCommand.getName(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -104,4 +105,11 @@ public class SequentialCommandGroup extends CommandGroupBase {
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
super.initSendable(builder);
|
||||
|
||||
builder.addIntegerProperty("index", () -> m_currentCommandIndex, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj2.command;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableBuilder;
|
||||
import edu.wpi.first.util.sendable.SendableRegistry;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
@@ -47,4 +48,10 @@ public class WaitCommand extends CommandBase {
|
||||
public boolean runsWhenDisabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
super.initSendable(builder);
|
||||
builder.addDoubleProperty("duration", () -> m_duration, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public abstract class WrapperCommand extends CommandBase {
|
||||
protected WrapperCommand(Command command) {
|
||||
CommandScheduler.getInstance().registerComposedCommands(command);
|
||||
m_command = command;
|
||||
// copy the wrapped command's name
|
||||
setName(command.getName());
|
||||
}
|
||||
|
||||
/** The initial subroutine of a command. Called once when the command is initially scheduled. */
|
||||
|
||||
@@ -105,8 +105,7 @@ CommandPtr Command::HandleInterrupt(std::function<void(void)> handler) && {
|
||||
}
|
||||
|
||||
CommandPtr Command::WithName(std::string_view name) && {
|
||||
SetName(name);
|
||||
return std::move(*this).ToPtr();
|
||||
return std::move(*this).ToPtr().WithName(name);
|
||||
}
|
||||
|
||||
void Command::Schedule() {
|
||||
|
||||
@@ -64,4 +64,21 @@ void CommandBase::InitSendable(wpi::SendableBuilder& builder) {
|
||||
Cancel();
|
||||
}
|
||||
});
|
||||
builder.AddBooleanProperty(
|
||||
".isParented", [this] { return IsComposed(); }, nullptr);
|
||||
builder.AddStringProperty(
|
||||
"interruptBehavior",
|
||||
[this] {
|
||||
switch (GetInterruptionBehavior()) {
|
||||
case Command::InterruptionBehavior::kCancelIncoming:
|
||||
return "kCancelIncoming";
|
||||
case Command::InterruptionBehavior::kCancelSelf:
|
||||
return "kCancelSelf";
|
||||
default:
|
||||
return "Invalid";
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
"runsWhenDisabled", [this] { return RunsWhenDisabled(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -221,8 +221,9 @@ CommandPtr CommandPtr::HandleInterrupt(std::function<void(void)> handler) && {
|
||||
|
||||
CommandPtr CommandPtr::WithName(std::string_view name) && {
|
||||
AssertValid();
|
||||
m_ptr->SetName(name);
|
||||
return std::move(*this);
|
||||
WrapperCommand wrapper{std::move(m_ptr)};
|
||||
wrapper.SetName(name);
|
||||
return std::move(wrapper).ToPtr();
|
||||
}
|
||||
|
||||
CommandBase* CommandPtr::get() const {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc2/command/ConditionalCommand.h"
|
||||
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
ConditionalCommand::ConditionalCommand(std::unique_ptr<Command>&& onTrue,
|
||||
@@ -50,3 +52,21 @@ bool ConditionalCommand::IsFinished() {
|
||||
bool ConditionalCommand::RunsWhenDisabled() const {
|
||||
return m_runsWhenDisabled;
|
||||
}
|
||||
|
||||
void ConditionalCommand::InitSendable(wpi::SendableBuilder& builder) {
|
||||
CommandBase::InitSendable(builder);
|
||||
builder.AddStringProperty(
|
||||
"onTrue", [this] { return m_onTrue->GetName(); }, nullptr);
|
||||
builder.AddStringProperty(
|
||||
"onFalse", [this] { return m_onFalse->GetName(); }, nullptr);
|
||||
builder.AddStringProperty(
|
||||
"selected",
|
||||
[this] {
|
||||
if (m_selectedCommand) {
|
||||
return m_selectedCommand->GetName();
|
||||
} else {
|
||||
return std::string{"null"};
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc2/command/ParallelDeadlineGroup.h"
|
||||
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
ParallelDeadlineGroup::ParallelDeadlineGroup(
|
||||
@@ -93,3 +95,10 @@ void ParallelDeadlineGroup::SetDeadline(std::unique_ptr<Command>&& deadline) {
|
||||
AddRequirements(m_deadline->GetRequirements());
|
||||
m_runWhenDisabled &= m_deadline->RunsWhenDisabled();
|
||||
}
|
||||
|
||||
void ParallelDeadlineGroup::InitSendable(wpi::SendableBuilder& builder) {
|
||||
CommandBase::InitSendable(builder);
|
||||
|
||||
builder.AddStringProperty(
|
||||
"deadline", [this] { return m_deadline->GetName(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -4,13 +4,17 @@
|
||||
|
||||
#include "frc2/command/ProxyCommand.h"
|
||||
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
ProxyCommand::ProxyCommand(wpi::unique_function<Command*()> supplier)
|
||||
: m_supplier(std::move(supplier)) {}
|
||||
|
||||
ProxyCommand::ProxyCommand(Command* command)
|
||||
: m_supplier([command] { return command; }) {}
|
||||
: m_supplier([command] { return command; }) {
|
||||
SetName(std::string{"Proxy("}.append(command->GetName()).append(")"));
|
||||
}
|
||||
|
||||
ProxyCommand::ProxyCommand(std::unique_ptr<Command> command)
|
||||
: m_supplier([command = std::move(command)] { return command.get(); }) {}
|
||||
@@ -35,3 +39,17 @@ bool ProxyCommand::IsFinished() {
|
||||
// do whatever we want -- like return true.
|
||||
return m_command == nullptr || !m_command->IsScheduled();
|
||||
}
|
||||
|
||||
void ProxyCommand::InitSendable(wpi::SendableBuilder& builder) {
|
||||
CommandBase::InitSendable(builder);
|
||||
builder.AddStringProperty(
|
||||
"proxied",
|
||||
[this] {
|
||||
if (m_command) {
|
||||
return m_command->GetName();
|
||||
} else {
|
||||
return std::string{"null"};
|
||||
}
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
RamseteCommand::RamseteCommand(
|
||||
@@ -158,3 +160,11 @@ void RamseteCommand::End(bool interrupted) {
|
||||
bool RamseteCommand::IsFinished() {
|
||||
return m_timer.HasElapsed(m_trajectory.TotalTime());
|
||||
}
|
||||
|
||||
void RamseteCommand::InitSendable(wpi::SendableBuilder& builder) {
|
||||
CommandBase::InitSendable(builder);
|
||||
builder.AddDoubleProperty(
|
||||
"leftVelocity", [this] { return m_prevSpeeds.left.value(); }, nullptr);
|
||||
builder.AddDoubleProperty(
|
||||
"rightVelocity", [this] { return m_prevSpeeds.right.value(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc2/command/RepeatCommand.h"
|
||||
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
RepeatCommand::RepeatCommand(std::unique_ptr<Command>&& command) {
|
||||
@@ -11,6 +13,7 @@ RepeatCommand::RepeatCommand(std::unique_ptr<Command>&& command) {
|
||||
m_command = std::move(command);
|
||||
m_command->SetComposed(true);
|
||||
AddRequirements(m_command->GetRequirements());
|
||||
SetName(std::string{"Repeat("}.append(m_command->GetName()).append(")"));
|
||||
}
|
||||
|
||||
void RepeatCommand::Initialize() {
|
||||
@@ -46,3 +49,9 @@ bool RepeatCommand::RunsWhenDisabled() const {
|
||||
Command::InterruptionBehavior RepeatCommand::GetInterruptionBehavior() const {
|
||||
return m_command->GetInterruptionBehavior();
|
||||
}
|
||||
|
||||
void RepeatCommand::InitSendable(wpi::SendableBuilder& builder) {
|
||||
CommandBase::InitSendable(builder);
|
||||
builder.AddStringProperty(
|
||||
"command", [this] { return m_command->GetName(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc2/command/SequentialCommandGroup.h"
|
||||
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
SequentialCommandGroup::SequentialCommandGroup(
|
||||
@@ -79,3 +81,9 @@ void SequentialCommandGroup::AddCommands(
|
||||
m_commands.emplace_back(std::move(command));
|
||||
}
|
||||
}
|
||||
|
||||
void SequentialCommandGroup::InitSendable(wpi::SendableBuilder& builder) {
|
||||
CommandBase::InitSendable(builder);
|
||||
builder.AddIntegerProperty(
|
||||
"index", [this] { return m_currentCommandIndex; }, nullptr);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <frc/fmt/Units.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
|
||||
using namespace frc2;
|
||||
|
||||
@@ -29,3 +30,9 @@ bool WaitCommand::IsFinished() {
|
||||
bool WaitCommand::RunsWhenDisabled() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void WaitCommand::InitSendable(wpi::SendableBuilder& builder) {
|
||||
CommandBase::InitSendable(builder);
|
||||
builder.AddDoubleProperty(
|
||||
"duration", [this] { return m_duration.value(); }, nullptr);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ WrapperCommand::WrapperCommand(std::unique_ptr<Command>&& command) {
|
||||
CommandScheduler::GetInstance().RequireUngrouped(command.get());
|
||||
m_command = std::move(command);
|
||||
m_command->SetComposed(true);
|
||||
// copy the wrapped command's name
|
||||
SetName(m_command->GetName());
|
||||
}
|
||||
|
||||
void WrapperCommand::Initialize() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -291,4 +291,12 @@ class CommandDecoratorTest extends CommandTestBase {
|
||||
assertEquals(2, second.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void withNameTest() {
|
||||
InstantCommand command = new InstantCommand();
|
||||
String name = "Named";
|
||||
Command named = command.withName(name);
|
||||
assertEquals(name, named.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,3 +198,10 @@ TEST_F(CommandDecoratorTest, HandleInterrupt) {
|
||||
// if `second == 1`, the second lambda ran before the first one
|
||||
EXPECT_EQ(2, second);
|
||||
}
|
||||
|
||||
TEST_F(CommandDecoratorTest, WithName) {
|
||||
InstantCommand command;
|
||||
std::string name{"Named"};
|
||||
CommandPtr named = std::move(command).WithName(name);
|
||||
EXPECT_EQ(name, named.get()->GetName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user