-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCommand.cpp.inl
175 lines (170 loc) · 7.7 KB
/
Command.cpp.inl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Decorators taken from Java
#define DECORATOR_NOTE \
"\n" \
"Note: This decorator works by composing this command within a CommandGroup. The command\n" \
"cannot be used independently after being decorated, or be re-decorated with a different\n" \
"decorator, unless it is manually cleared from the list of grouped commands with Command.setGrouped(False)\n" \
"The decorated command can, however, be further decorated without issue\n"
cls_Command
.def("andThen",
[](std::shared_ptr<Command> self, std::function<void()> toRun, wpi::span<std::shared_ptr<Subsystem>> requirements) {
std::vector<std::shared_ptr<Command>> temp;
temp.emplace_back(self);
temp.emplace_back(
std::make_shared<InstantCommand>(std::move(toRun), requirements));
return SequentialCommandGroup(std::move(temp));
},
py::arg("toRun"), py::arg("requirements") = wpi::span<std::shared_ptr<Subsystem>>{},
"Decorates this command with a runnable to run after the command finishes.\n"
DECORATOR_NOTE)
.def("andThen",
[](std::shared_ptr<Command> self, py::args cmds) {
std::vector<std::shared_ptr<Command>> commands;
commands.emplace_back(self);
for (auto cmd : cmds) {
auto cmdptr = py::cast<std::shared_ptr<Command>>(cmd);
commands.emplace_back(cmdptr);
}
return std::make_shared<SequentialCommandGroup>(std::move(commands));
},
"Decorates this command with a set of commands to run after it in sequence. Often more\n"
"convenient/less-verbose than constructing a new :class:`.SequentialCommandGroup` explicitly.\n"
DECORATOR_NOTE)
.def("alongWith",
[](std::shared_ptr<Command> self, py::args cmds) {
std::vector<std::shared_ptr<Command>> commands;
commands.emplace_back(self);
for (auto cmd : cmds) {
auto cmdptr = py::cast<std::shared_ptr<Command>>(cmd);
commands.emplace_back(cmdptr);
}
return std::make_shared<ParallelCommandGroup>(std::move(commands));
},
"Decorates this command with a set of commands to run parallel to it, "
"ending when the last\n"
"command ends. Often more convenient/less-verbose than constructing a new\n"
"ParallelCommandGroup explicitly.\n"
DECORATOR_NOTE)
.def("asProxy",
[](std::shared_ptr<Command> self) {
return std::make_shared<ProxyScheduleCommand>(self);
},
"Decorates this command to run \"by proxy\" by wrapping it in a\n"
"ProxyScheduleCommand. This is useful for \"forking off\" from command groups\n"
"when the user does not wish to extend the command's requirements to the\n"
"entire command group.\n"
"\n"
":returns: the decorated command\n"
DECORATOR_NOTE
)
.def("beforeStarting",
[](std::shared_ptr<Command> self, std::function<void()> toRun, wpi::span<std::shared_ptr<Subsystem>> requirements) {
std::vector<std::shared_ptr<Command>> temp;
temp.emplace_back(std::make_shared<InstantCommand>(std::move(toRun), requirements));
temp.emplace_back(self);
return std::make_shared<SequentialCommandGroup>(std::move(temp));
},
py::arg("toRun"), py::arg("requirements")=wpi::span<std::shared_ptr<Subsystem> >{},
"Decorates this command with a runnable to run before this command starts.\n"
"\n"
":param toRun: the Runnable to run\n"
":param requirements: the required subsystems\n"
"\n"
":returns: the decorated command\n"
DECORATOR_NOTE)
.def("deadlineWith",
[](std::shared_ptr<Command> self, py::args cmds) {
return std::make_shared<ParallelDeadlineGroup>(
self, std::move(pyargs2cmdList(cmds)));
},
"Decorates this command with a set of commands to run parallel to it, ending when the calling\n"
"command ends and interrupting all the others. Often more convenient/less-verbose than\n"
"constructing a new :class:`.ParallelDeadlineGroup` explicitly.\n"
DECORATOR_NOTE)
.def("perpetually",
[](std::shared_ptr<Command> self) {
return std::make_shared<PerpetualCommand>(self);
},
"Decorates this command to run perpetually, ignoring its ordinary end\n"
"conditions. The decorated command can still be interrupted or canceled.\n"
"\n"
":returns: the decorated command\n"
DECORATOR_NOTE)
.def("raceWith",
[](std::shared_ptr<Command> self, py::args cmds) {
std::vector<std::shared_ptr<Command>> commands;
commands.emplace_back(self);
for (auto cmd : cmds) {
auto cmdptr = py::cast<std::shared_ptr<Command>>(cmd);
commands.emplace_back(cmdptr);
}
return std::make_shared<ParallelRaceGroup>(std::move(commands));
},
"Decorates this command with a set of commands to run parallel to it, ending when the first\n"
"command ends. Often more convenient/less-verbose than constructing a new\n"
"ParallelRaceGroup explicitly.\n"
DECORATOR_NOTE)
.def("until",
[](std::shared_ptr<Command> self, std::function<bool()> condition) {
std::vector<std::shared_ptr<Command>> temp;
temp.emplace_back(std::make_shared<WaitUntilCommand>(std::move(condition)));
temp.emplace_back(self);
return std::make_shared<ParallelRaceGroup>(std::move(temp));
},
py::arg("condition"),
"Decorates this command with an interrupt condition. If the specified\n"
"condition becomes true before the command finishes normally, the command\n"
"will be interrupted and un-scheduled. Note that this only applies to the\n"
"command returned by this method; the calling command is not itself changed.\n"
"\n"
":param condition: the interrupt condition\n"
"\n"
":returns: the command with the interrupt condition added\n"
DECORATOR_NOTE)
.def("withInterrupt",
[](std::shared_ptr<Command> self, std::function<bool()> condition) {
std::vector<std::shared_ptr<Command>> temp;
temp.emplace_back(std::make_shared<WaitUntilCommand>(std::move(condition)));
temp.emplace_back(self);
return std::make_shared<ParallelRaceGroup>(std::move(temp));
},
py::arg("condition"),
"Decorates this command with an interrupt condition. If the specified\n"
"condition becomes true before the command finishes normally, the command\n"
"will be interrupted and un-scheduled. Note that this only applies to the\n"
"command returned by this method; the calling command is not itself changed.\n"
"\n"
":param condition: the interrupt condition\n"
"\n"
":returns: the command with the interrupt condition added\n"
DECORATOR_NOTE)
.def("withTimeout",
[](std::shared_ptr<Command> self, units::second_t duration) {
std::vector<std::shared_ptr<Command>> temp;
temp.emplace_back(std::make_shared<WaitCommand>(duration));
temp.emplace_back(self);
return std::make_shared<ParallelRaceGroup>(std::move(temp));
},
py::arg("duration"),
"Decorates this command with a timeout. If the specified timeout is\n"
"exceeded before the command finishes normally, the command will be\n"
"interrupted and un-scheduled. Note that the timeout only applies to the\n"
"command returned by this method; the calling command is not itself changed.\n"
"\n"
":param duration: the timeout duration\n"
"\n"
":returns: the command with the timeout added\n"
DECORATOR_NOTE)
.def("__iter__",
[](std::shared_ptr<Command> self) {
return py::make_iterator(CommandIterator(self), CommandIteratorSentinel());
},
py::keep_alive<0, 1>(),
"Creates an Iterator for this command. The iterator will run the command and\n"
"will only exhaust when the command is finished.\n"
"Note that the iterator will not run the command in the background. It must be\n"
"explicitly be iterated over.\n"
"\n"
":returns: an iterator for this command\n"
)
;