Skip to content

Commit 75c4e26

Browse files
committed
Merge commit '6c12ac97444642c557f360fd5ca52acf2fbdcce7' into upstream
2 parents 1523e6e + 6c12ac9 commit 75c4e26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2169
-772
lines changed

commands2/src/cpp/frc2/command/Command.cpp

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44

55
#include "frc2/command/Command.h"
66

7+
#include "frc2/command/CommandHelper.h"
78
#include "frc2/command/CommandScheduler.h"
9+
#include "frc2/command/ConditionalCommand.h"
810
#include "frc2/command/InstantCommand.h"
911
#include "frc2/command/ParallelCommandGroup.h"
1012
#include "frc2/command/ParallelDeadlineGroup.h"
1113
#include "frc2/command/ParallelRaceGroup.h"
1214
#include "frc2/command/PerpetualCommand.h"
1315
#include "frc2/command/ProxyScheduleCommand.h"
16+
#include "frc2/command/RepeatCommand.h"
1417
#include "frc2/command/SequentialCommandGroup.h"
1518
#include "frc2/command/WaitCommand.h"
1619
#include "frc2/command/WaitUntilCommand.h"
20+
#include "frc2/command/WrapperCommand.h"
1721

1822
using namespace frc2;
1923

@@ -30,69 +34,87 @@ void Command::Initialize() {}
3034
void Command::Execute() {}
3135
void Command::End(bool interrupted) {}
3236

33-
ParallelRaceGroup Command::WithTimeout(units::second_t duration) && {
34-
std::vector<std::unique_ptr<Command>> temp;
35-
temp.emplace_back(std::make_unique<WaitCommand>(duration));
36-
temp.emplace_back(std::move(*this).TransferOwnership());
37-
return ParallelRaceGroup(std::move(temp));
37+
CommandPtr Command::WithTimeout(units::second_t duration) && {
38+
return CommandPtr(std::move(*this).TransferOwnership()).WithTimeout(duration);
3839
}
3940

40-
ParallelRaceGroup Command::Until(std::function<bool()> condition) && {
41-
std::vector<std::unique_ptr<Command>> temp;
42-
temp.emplace_back(std::make_unique<WaitUntilCommand>(std::move(condition)));
43-
temp.emplace_back(std::move(*this).TransferOwnership());
44-
return ParallelRaceGroup(std::move(temp));
41+
CommandPtr Command::Until(std::function<bool()> condition) && {
42+
return CommandPtr(std::move(*this).TransferOwnership())
43+
.Until(std::move(condition));
4544
}
4645

47-
ParallelRaceGroup Command::WithInterrupt(std::function<bool()> condition) && {
48-
std::vector<std::unique_ptr<Command>> temp;
49-
temp.emplace_back(std::make_unique<WaitUntilCommand>(std::move(condition)));
50-
temp.emplace_back(std::move(*this).TransferOwnership());
51-
return ParallelRaceGroup(std::move(temp));
46+
CommandPtr Command::IgnoringDisable(bool doesRunWhenDisabled) && {
47+
return CommandPtr(std::move(*this).TransferOwnership())
48+
.IgnoringDisable(doesRunWhenDisabled);
5249
}
5350

54-
SequentialCommandGroup Command::BeforeStarting(
51+
CommandPtr Command::WithInterruptBehavior(
52+
InterruptionBehavior interruptBehavior) && {
53+
return CommandPtr(std::move(*this).TransferOwnership())
54+
.WithInterruptBehavior(interruptBehavior);
55+
}
56+
57+
CommandPtr Command::WithInterrupt(std::function<bool()> condition) && {
58+
return CommandPtr(std::move(*this).TransferOwnership())
59+
.Until(std::move(condition));
60+
}
61+
62+
CommandPtr Command::BeforeStarting(
5563
std::function<void()> toRun,
5664
std::initializer_list<Subsystem*> requirements) && {
5765
return std::move(*this).BeforeStarting(
5866
std::move(toRun), {requirements.begin(), requirements.end()});
5967
}
6068

61-
SequentialCommandGroup Command::BeforeStarting(
62-
std::function<void()> toRun, wpi::span<Subsystem* const> requirements) && {
63-
std::vector<std::unique_ptr<Command>> temp;
64-
temp.emplace_back(
65-
std::make_unique<InstantCommand>(std::move(toRun), requirements));
66-
temp.emplace_back(std::move(*this).TransferOwnership());
67-
return SequentialCommandGroup(std::move(temp));
69+
CommandPtr Command::BeforeStarting(
70+
std::function<void()> toRun, std::span<Subsystem* const> requirements) && {
71+
return CommandPtr(std::move(*this).TransferOwnership())
72+
.BeforeStarting(std::move(toRun), requirements);
6873
}
6974

70-
SequentialCommandGroup Command::AndThen(
71-
std::function<void()> toRun,
72-
std::initializer_list<Subsystem*> requirements) && {
75+
CommandPtr Command::AndThen(std::function<void()> toRun,
76+
std::initializer_list<Subsystem*> requirements) && {
7377
return std::move(*this).AndThen(std::move(toRun),
7478
{requirements.begin(), requirements.end()});
7579
}
7680

77-
SequentialCommandGroup Command::AndThen(
78-
std::function<void()> toRun, wpi::span<Subsystem* const> requirements) && {
79-
std::vector<std::unique_ptr<Command>> temp;
80-
temp.emplace_back(std::move(*this).TransferOwnership());
81-
temp.emplace_back(
82-
std::make_unique<InstantCommand>(std::move(toRun), requirements));
83-
return SequentialCommandGroup(std::move(temp));
81+
CommandPtr Command::AndThen(std::function<void()> toRun,
82+
std::span<Subsystem* const> requirements) && {
83+
return CommandPtr(std::move(*this).TransferOwnership())
84+
.AndThen(std::move(toRun), requirements);
8485
}
8586

8687
PerpetualCommand Command::Perpetually() && {
88+
WPI_IGNORE_DEPRECATED
8789
return PerpetualCommand(std::move(*this).TransferOwnership());
90+
WPI_UNIGNORE_DEPRECATED
91+
}
92+
93+
CommandPtr Command::Repeatedly() && {
94+
return CommandPtr(std::move(*this).TransferOwnership()).Repeatedly();
95+
}
96+
97+
CommandPtr Command::AsProxy() && {
98+
return CommandPtr(std::move(*this).TransferOwnership()).AsProxy();
99+
}
100+
101+
CommandPtr Command::Unless(std::function<bool()> condition) && {
102+
return CommandPtr(std::move(*this).TransferOwnership())
103+
.Unless(std::move(condition));
104+
}
105+
106+
CommandPtr Command::FinallyDo(std::function<void(bool)> end) && {
107+
return CommandPtr(std::move(*this).TransferOwnership())
108+
.FinallyDo(std::move(end));
88109
}
89110

90-
ProxyScheduleCommand Command::AsProxy() {
91-
return ProxyScheduleCommand(this);
111+
CommandPtr Command::HandleInterrupt(std::function<void(void)> handler) && {
112+
return CommandPtr(std::move(*this).TransferOwnership())
113+
.HandleInterrupt(std::move(handler));
92114
}
93115

94-
void Command::Schedule(bool interruptible) {
95-
CommandScheduler::GetInstance().Schedule(interruptible, this);
116+
void Command::Schedule() {
117+
CommandScheduler::GetInstance().Schedule(this);
96118
}
97119

98120
void Command::Cancel() {

commands2/src/cpp/frc2/command/CommandBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void CommandBase::AddRequirements(
1818
m_requirements.insert(requirements.begin(), requirements.end());
1919
}
2020

21-
void CommandBase::AddRequirements(wpi::span<Subsystem* const> requirements) {
21+
void CommandBase::AddRequirements(std::span<Subsystem* const> requirements) {
2222
m_requirements.insert(requirements.begin(), requirements.end());
2323
}
2424

commands2/src/cpp/frc2/command/CommandGroupBase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using namespace frc2;
99
bool CommandGroupBase::RequireUngrouped(const Command& command) {
1010
if (command.IsGrouped()) {
1111
throw FRC_MakeError(
12-
frc::err::CommandIllegalUse, "{}",
12+
frc::err::CommandIllegalUse,
1313
"Commands cannot be added to more than one CommandGroup");
1414
}
1515
return true;
@@ -20,14 +20,14 @@ bool CommandGroupBase::RequireUngrouped(const Command* command) {
2020
}
2121

2222
bool CommandGroupBase::RequireUngrouped(
23-
wpi::span<const std::unique_ptr<Command>> commands) {
23+
std::span<const std::unique_ptr<Command>> commands) {
2424
bool allUngrouped = true;
2525
for (auto&& command : commands) {
2626
allUngrouped &= !command.get()->IsGrouped();
2727
}
2828
if (!allUngrouped) {
2929
throw FRC_MakeError(
30-
frc::err::CommandIllegalUse, "{}",
30+
frc::err::CommandIllegalUse,
3131
"Commands cannot be added to more than one CommandGroup");
3232
}
3333
return allUngrouped;
@@ -41,7 +41,7 @@ bool CommandGroupBase::RequireUngrouped(
4141
}
4242
if (!allUngrouped) {
4343
throw FRC_MakeError(
44-
frc::err::CommandIllegalUse, "{}",
44+
frc::err::CommandIllegalUse,
4545
"Commands cannot be added to more than one CommandGroup");
4646
}
4747
return allUngrouped;

0 commit comments

Comments
 (0)