Skip to content

Commit 69f6a33

Browse files
committed
Merge commit '8a4df9ddf30c0e830446b31b1a76de147705a903' into upstream
2 parents 75c4e26 + 8a4df9d commit 69f6a33

16 files changed

+949
-182
lines changed

commands2/src/cpp/frc2/command/CommandPtr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "frc2/command/ParallelCommandGroup.h"
1111
#include "frc2/command/ParallelDeadlineGroup.h"
1212
#include "frc2/command/ParallelRaceGroup.h"
13-
#include "frc2/command/PerpetualCommand.h"
13+
#include "frc2/command/PrintCommand.h"
1414
#include "frc2/command/ProxyScheduleCommand.h"
1515
#include "frc2/command/RepeatCommand.h"
1616
#include "frc2/command/SequentialCommandGroup.h"
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
#include "frc2/command/Commands.h"
6+
7+
#include "frc2/command/ConditionalCommand.h"
8+
#include "frc2/command/FunctionalCommand.h"
9+
#include "frc2/command/InstantCommand.h"
10+
#include "frc2/command/ParallelCommandGroup.h"
11+
#include "frc2/command/ParallelDeadlineGroup.h"
12+
#include "frc2/command/ParallelRaceGroup.h"
13+
#include "frc2/command/PerpetualCommand.h"
14+
#include "frc2/command/PrintCommand.h"
15+
#include "frc2/command/ProxyScheduleCommand.h"
16+
#include "frc2/command/RunCommand.h"
17+
#include "frc2/command/SelectCommand.h"
18+
#include "frc2/command/SequentialCommandGroup.h"
19+
#include "frc2/command/WaitCommand.h"
20+
#include "frc2/command/WaitUntilCommand.h"
21+
22+
using namespace frc2;
23+
24+
// Factories
25+
26+
CommandPtr cmd::None() {
27+
return InstantCommand().ToPtr();
28+
}
29+
30+
CommandPtr cmd::RunOnce(std::function<void()> action,
31+
std::initializer_list<Subsystem*> requirements) {
32+
return InstantCommand(std::move(action), requirements).ToPtr();
33+
}
34+
35+
CommandPtr cmd::RunOnce(std::function<void()> action,
36+
std::span<Subsystem* const> requirements) {
37+
return InstantCommand(std::move(action), requirements).ToPtr();
38+
}
39+
40+
CommandPtr cmd::Run(std::function<void()> action,
41+
std::initializer_list<Subsystem*> requirements) {
42+
return RunCommand(std::move(action), requirements).ToPtr();
43+
}
44+
45+
CommandPtr cmd::Run(std::function<void()> action,
46+
std::span<Subsystem* const> requirements) {
47+
return RunCommand(std::move(action), requirements).ToPtr();
48+
}
49+
50+
CommandPtr cmd::StartEnd(std::function<void()> start, std::function<void()> end,
51+
std::initializer_list<Subsystem*> requirements) {
52+
return FunctionalCommand(
53+
std::move(start), [] {},
54+
[end = std::move(end)](bool interrupted) { end(); },
55+
[] { return false; }, requirements)
56+
.ToPtr();
57+
}
58+
59+
CommandPtr cmd::StartEnd(std::function<void()> start, std::function<void()> end,
60+
std::span<Subsystem* const> requirements) {
61+
return FunctionalCommand(
62+
std::move(start), [] {},
63+
[end = std::move(end)](bool interrupted) { end(); },
64+
[] { return false; }, requirements)
65+
.ToPtr();
66+
}
67+
68+
CommandPtr cmd::RunEnd(std::function<void()> run, std::function<void()> end,
69+
std::initializer_list<Subsystem*> requirements) {
70+
return FunctionalCommand([] {}, std::move(run),
71+
[end = std::move(end)](bool interrupted) { end(); },
72+
[] { return false; }, requirements)
73+
.ToPtr();
74+
}
75+
76+
CommandPtr cmd::RunEnd(std::function<void()> run, std::function<void()> end,
77+
std::span<Subsystem* const> requirements) {
78+
return FunctionalCommand([] {}, std::move(run),
79+
[end = std::move(end)](bool interrupted) { end(); },
80+
[] { return false; }, requirements)
81+
.ToPtr();
82+
}
83+
84+
CommandPtr cmd::Print(std::string_view msg) {
85+
return PrintCommand(msg).ToPtr();
86+
}
87+
88+
CommandPtr cmd::Wait(units::second_t duration) {
89+
return WaitCommand(duration).ToPtr();
90+
}
91+
92+
CommandPtr cmd::WaitUntil(std::function<bool()> condition) {
93+
return WaitUntilCommand(condition).ToPtr();
94+
}
95+
96+
CommandPtr cmd::Either(CommandPtr&& onTrue, CommandPtr&& onFalse,
97+
std::function<bool()> selector) {
98+
return ConditionalCommand(std::move(onTrue).Unwrap(),
99+
std::move(onFalse).Unwrap(), std::move(selector))
100+
.ToPtr();
101+
}
102+
103+
template <typename Key>
104+
CommandPtr cmd::Select(std::function<Key()> selector,
105+
std::vector<std::pair<Key, CommandPtr>> commands) {
106+
return SelectCommand(std::move(selector),
107+
CommandPtr::UnwrapVector(std::move(commands)))
108+
.ToPtr();
109+
}
110+
111+
CommandPtr cmd::Sequence(std::vector<CommandPtr>&& commands) {
112+
return SequentialCommandGroup(CommandPtr::UnwrapVector(std::move(commands)))
113+
.ToPtr();
114+
}
115+
116+
CommandPtr cmd::RepeatingSequence(std::vector<CommandPtr>&& commands) {
117+
return Sequence(std::move(commands)).Repeatedly();
118+
}
119+
120+
CommandPtr cmd::Parallel(std::vector<CommandPtr>&& commands) {
121+
return ParallelCommandGroup(CommandPtr::UnwrapVector(std::move(commands)))
122+
.ToPtr();
123+
}
124+
125+
CommandPtr cmd::Race(std::vector<CommandPtr>&& commands) {
126+
return ParallelRaceGroup(CommandPtr::UnwrapVector(std::move(commands)))
127+
.ToPtr();
128+
}
129+
130+
CommandPtr cmd::Deadline(CommandPtr&& deadline,
131+
std::vector<CommandPtr>&& others) {
132+
return ParallelDeadlineGroup(std::move(deadline).Unwrap(),
133+
CommandPtr::UnwrapVector(std::move(others)))
134+
.ToPtr();
135+
}

commands2/src/cpp/frc2/command/button/Button.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,91 @@ using namespace frc2;
99
Button::Button(std::function<bool()> isPressed) : Trigger(isPressed) {}
1010

1111
Button Button::WhenPressed(Command* command) {
12+
WPI_IGNORE_DEPRECATED
1213
WhenActive(command);
13-
return *this;
14-
}
15-
16-
Button Button::WhenPressed(CommandPtr&& command) {
17-
WhenActive(std::move(command));
14+
WPI_UNIGNORE_DEPRECATED
1815
return *this;
1916
}
2017

2118
Button Button::WhenPressed(std::function<void()> toRun,
2219
std::initializer_list<Subsystem*> requirements) {
20+
WPI_IGNORE_DEPRECATED
2321
WhenActive(std::move(toRun), requirements);
22+
WPI_UNIGNORE_DEPRECATED
2423
return *this;
2524
}
2625

2726
Button Button::WhenPressed(std::function<void()> toRun,
2827
std::span<Subsystem* const> requirements) {
28+
WPI_IGNORE_DEPRECATED
2929
WhenActive(std::move(toRun), requirements);
30+
WPI_UNIGNORE_DEPRECATED
3031
return *this;
3132
}
3233

3334
Button Button::WhileHeld(Command* command) {
35+
WPI_IGNORE_DEPRECATED
3436
WhileActiveContinous(command);
35-
return *this;
36-
}
37-
38-
Button Button::WhileHeld(CommandPtr&& command) {
39-
WhileActiveContinous(std::move(command));
37+
WPI_UNIGNORE_DEPRECATED
4038
return *this;
4139
}
4240

4341
Button Button::WhileHeld(std::function<void()> toRun,
4442
std::initializer_list<Subsystem*> requirements) {
43+
WPI_IGNORE_DEPRECATED
4544
WhileActiveContinous(std::move(toRun), requirements);
45+
WPI_UNIGNORE_DEPRECATED
4646
return *this;
4747
}
4848

4949
Button Button::WhileHeld(std::function<void()> toRun,
5050
std::span<Subsystem* const> requirements) {
51+
WPI_IGNORE_DEPRECATED
5152
WhileActiveContinous(std::move(toRun), requirements);
53+
WPI_UNIGNORE_DEPRECATED
5254
return *this;
5355
}
5456

5557
Button Button::WhenHeld(Command* command) {
58+
WPI_IGNORE_DEPRECATED
5659
WhileActiveOnce(command);
57-
return *this;
58-
}
59-
60-
Button Button::WhenHeld(CommandPtr&& command) {
61-
WhileActiveOnce(std::move(command));
60+
WPI_UNIGNORE_DEPRECATED
6261
return *this;
6362
}
6463

6564
Button Button::WhenReleased(Command* command) {
65+
WPI_IGNORE_DEPRECATED
6666
WhenInactive(command);
67-
return *this;
68-
}
69-
70-
Button Button::WhenReleased(CommandPtr&& command) {
71-
WhenInactive(std::move(command));
67+
WPI_UNIGNORE_DEPRECATED
7268
return *this;
7369
}
7470

7571
Button Button::WhenReleased(std::function<void()> toRun,
7672
std::initializer_list<Subsystem*> requirements) {
73+
WPI_IGNORE_DEPRECATED
7774
WhenInactive(std::move(toRun), requirements);
75+
WPI_UNIGNORE_DEPRECATED
7876
return *this;
7977
}
8078

8179
Button Button::WhenReleased(std::function<void()> toRun,
8280
std::span<Subsystem* const> requirements) {
81+
WPI_IGNORE_DEPRECATED
8382
WhenInactive(std::move(toRun), requirements);
83+
WPI_UNIGNORE_DEPRECATED
8484
return *this;
8585
}
8686

8787
Button Button::ToggleWhenPressed(Command* command) {
88+
WPI_IGNORE_DEPRECATED
8889
ToggleWhenActive(command);
89-
return *this;
90-
}
91-
92-
Button Button::ToggleWhenPressed(CommandPtr&& command) {
93-
ToggleWhenActive(std::move(command));
90+
WPI_UNIGNORE_DEPRECATED
9491
return *this;
9592
}
9693

9794
Button Button::CancelWhenPressed(Command* command) {
95+
WPI_IGNORE_DEPRECATED
9896
CancelWhenActive(command);
97+
WPI_UNIGNORE_DEPRECATED
9998
return *this;
10099
}

commands2/src/cpp/frc2/command/button/CommandGenericHID.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,48 @@ using namespace frc2;
99
Trigger CommandGenericHID::Button(int button, frc::EventLoop* loop) const {
1010
return GenericHID::Button(button, loop).CastTo<Trigger>();
1111
}
12+
13+
Trigger CommandGenericHID::POV(int angle, frc::EventLoop* loop) const {
14+
return POV(0, angle, loop);
15+
}
16+
17+
Trigger CommandGenericHID::POV(int pov, int angle, frc::EventLoop* loop) const {
18+
return Trigger(loop,
19+
[this, pov, angle] { return this->GetPOV(pov) == angle; });
20+
}
21+
22+
Trigger CommandGenericHID::POVUp(frc::EventLoop* loop) const {
23+
return POV(0, loop);
24+
}
25+
26+
Trigger CommandGenericHID::POVUpRight(frc::EventLoop* loop) const {
27+
return POV(45, loop);
28+
}
29+
30+
Trigger CommandGenericHID::POVRight(frc::EventLoop* loop) const {
31+
return POV(90, loop);
32+
}
33+
34+
Trigger CommandGenericHID::POVDownRight(frc::EventLoop* loop) const {
35+
return POV(135, loop);
36+
}
37+
38+
Trigger CommandGenericHID::POVDown(frc::EventLoop* loop) const {
39+
return POV(180, loop);
40+
}
41+
42+
Trigger CommandGenericHID::POVDownLeft(frc::EventLoop* loop) const {
43+
return POV(225, loop);
44+
}
45+
46+
Trigger CommandGenericHID::POVLeft(frc::EventLoop* loop) const {
47+
return POV(270, loop);
48+
}
49+
50+
Trigger CommandGenericHID::POVUpLeft(frc::EventLoop* loop) const {
51+
return POV(315, loop);
52+
}
53+
54+
Trigger CommandGenericHID::POVCenter(frc::EventLoop* loop) const {
55+
return POV(360, loop);
56+
}

commands2/src/cpp/frc2/command/button/CommandPS4Controller.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
using namespace frc2;
88

9+
Trigger CommandPS4Controller::Button(int button, frc::EventLoop* loop) const {
10+
return GenericHID::Button(button, loop).CastTo<Trigger>();
11+
}
12+
913
Trigger CommandPS4Controller::Square(frc::EventLoop* loop) const {
1014
return PS4Controller::Square(loop).CastTo<Trigger>();
1115
}

commands2/src/cpp/frc2/command/button/CommandXboxController.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
using namespace frc2;
88

9+
Trigger CommandXboxController::Button(int button, frc::EventLoop* loop) const {
10+
return GenericHID::Button(button, loop).CastTo<Trigger>();
11+
}
12+
913
Trigger CommandXboxController::LeftBumper(frc::EventLoop* loop) const {
1014
return XboxController::LeftBumper(loop).CastTo<Trigger>();
1115
}

commands2/src/cpp/frc2/command/button/NetworkButton.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44

55
#include "frc2/command/button/NetworkButton.h"
66

7+
#include <wpi/deprecated.h>
8+
79
using namespace frc2;
810

11+
WPI_IGNORE_DEPRECATED
912
NetworkButton::NetworkButton(nt::BooleanTopic topic)
1013
: NetworkButton(topic.Subscribe(false)) {}
1114

1215
NetworkButton::NetworkButton(nt::BooleanSubscriber sub)
1316
: Button([sub = std::make_shared<nt::BooleanSubscriber>(std::move(sub))] {
1417
return sub->GetTopic().GetInstance().IsConnected() && sub->Get();
1518
}) {}
19+
WPI_UNIGNORE_DEPRECATED
1620

1721
NetworkButton::NetworkButton(std::shared_ptr<nt::NetworkTable> table,
1822
std::string_view field)

0 commit comments

Comments
 (0)