RobotCore
1.0
WPILib port to raspberry Pi
Toggle main menu visibility
Loading...
Searching...
No Matches
Command.java
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
package
org.wpilib.command3;
6
7
import
static
org.wpilib.util.ErrorMessages.requireNonNullParam;
8
9
import
java.util.Collection;
10
import
java.util.Collections;
11
import
java.util.Set;
12
import
java.util.function.BooleanSupplier;
13
import
java.util.function.Consumer;
14
import
org.wpilib.annotation.NoDiscard;
15
import
org.wpilib.units.measure.Time;
16
97
@
NoDiscard
(
"Commands must be used! Did you mean to fork it or bind it to a trigger?"
)
98
public interface
Command
{
100
int
DEFAULT_PRIORITY
= 0;
101
106
int
LOWEST_PRIORITY
= Integer.MIN_VALUE;
107
112
int
HIGHEST_PRIORITY
= Integer.MAX_VALUE;
113
125
void
run
(
Coroutine
coroutine);
126
132
default
void
onCancel
() {
133
// NOP by default
134
}
135
142
default
void
onExit
() {
143
// NOP by default
144
}
145
151
@
NoDiscard
152
String
name
();
153
161
@
NoDiscard
162
Set<Mechanism>
requirements
();
163
173
@
NoDiscard
174
default
int
priority
() {
175
return
DEFAULT_PRIORITY
;
176
}
177
184
@
NoDiscard
185
default
boolean
isLowerPriorityThan
(
Command
other) {
186
requireNonNullParam(other,
"other"
,
"Command.isLowerPriorityThan"
);
187
188
return
priority
() < other.
priority
();
189
}
190
197
@
NoDiscard
198
default
boolean
requires
(
Mechanism
mechanism) {
199
return
requirements
().contains(mechanism);
200
}
201
209
@
NoDiscard
210
default
boolean
conflictsWith
(
Command
other) {
211
requireNonNullParam(other,
"other"
,
"Command.conflictsWith"
);
212
213
return
!Collections.disjoint(
requirements
(), other.
requirements
());
214
}
215
228
default
Command
withTimeout
(Time timeout) {
229
requireNonNullParam(timeout,
"timeout"
,
"Command.withTimeout"
);
230
231
return
race
(
this
,
waitFor
(timeout).named(
"Timeout: "
+ timeout.toLongString()))
232
.named(
name
() +
" ["
+ timeout.toLongString() +
" timeout]"
);
233
}
234
248
static
NeedsNameBuilderStage
noRequirements
(Consumer<Coroutine> body) {
249
return
new
StagedCommandBuilder
().noRequirements().executing(body);
250
}
251
262
static
NeedsExecutionBuilderStage
requiring
(
Mechanism
requirement,
Mechanism
... rest) {
263
// parameters will be null checked by the builder
264
return
new
StagedCommandBuilder
().
requiring
(requirement, rest);
265
}
266
276
static
NeedsExecutionBuilderStage
requiring
(Collection<Mechanism>
requirements
) {
277
// parameters will be null checked by the builder
278
return
new
StagedCommandBuilder
().
requiring
(
requirements
);
279
}
280
291
static
ParallelGroupBuilder
parallel
(
Command
... commands) {
292
// parameters will be null checked by the builder
293
return
new
ParallelGroupBuilder
().
requiring
(commands);
294
}
295
307
static
ParallelGroupBuilder
race
(
Command
... commands) {
308
// parameters will be null checked by the builder
309
return
new
ParallelGroupBuilder
().
optional
(commands);
310
}
311
323
static
SequentialGroupBuilder
sequence
(
Command
... commands) {
324
// parameters will be null checked by the builder
325
return
new
SequentialGroupBuilder
().
andThen
(commands);
326
}
327
338
static
NeedsNameBuilderStage
waitUntil
(BooleanSupplier condition) {
339
requireNonNullParam(condition,
"condition"
,
"Command.waitUntil"
);
340
341
return
noRequirements
(coroutine -> coroutine.waitUntil(condition));
342
}
343
351
static
NeedsNameBuilderStage
waitFor
(Time duration) {
352
requireNonNullParam(duration,
"duration"
,
"Command.waitFor"
);
353
354
return
noRequirements
(coroutine -> coroutine.wait(duration));
355
}
356
367
default
ParallelGroupBuilder
until
(BooleanSupplier endCondition) {
368
requireNonNullParam(endCondition,
"endCondition"
,
"Command.until"
);
369
370
return
new
ParallelGroupBuilder
()
371
.optional(
this
,
Command
.
waitUntil
(endCondition).
named
(
"Until Condition"
));
372
}
373
389
default
SequentialGroupBuilder
andThen
(
Command
next) {
390
// parameter will be null checked by the builder
391
return
new
SequentialGroupBuilder
().
andThen
(
this
).
andThen
(next);
392
}
393
411
default
ParallelGroupBuilder
alongWith
(
Command
...
parallel
) {
412
return
new
ParallelGroupBuilder
().
requiring
(
this
).
requiring
(
parallel
);
413
}
414
425
default
ParallelGroupBuilder
raceWith
(
Command
...
parallel
) {
426
return
new
ParallelGroupBuilder
().
optional
(
this
).
optional
(
parallel
);
427
}
428
}
org.wpilib.command3.Coroutine
Definition
Coroutine.java:35
org.wpilib.command3.ParallelGroupBuilder
Definition
ParallelGroupBuilder.java:23
org.wpilib.command3.ParallelGroupBuilder.ParallelGroupBuilder
ParallelGroupBuilder()
Definition
ParallelGroupBuilder.java:32
org.wpilib.command3.ParallelGroupBuilder.optional
ParallelGroupBuilder optional(Command... commands)
Definition
ParallelGroupBuilder.java:41
org.wpilib.command3.ParallelGroupBuilder.requiring
ParallelGroupBuilder requiring(Command... commands)
Definition
ParallelGroupBuilder.java:58
org.wpilib.command3.SequentialGroupBuilder
Definition
SequentialGroupBuilder.java:23
org.wpilib.command3.SequentialGroupBuilder.SequentialGroupBuilder
SequentialGroupBuilder()
Definition
SequentialGroupBuilder.java:31
org.wpilib.command3.SequentialGroupBuilder.andThen
SequentialGroupBuilder andThen(Command next)
Definition
SequentialGroupBuilder.java:39
org.wpilib.command3.StagedCommandBuilder.StagedCommandBuilder
StagedCommandBuilder()
Definition
StagedCommandBuilder.java:242
org.wpilib.annotation.NoDiscard
Definition
NoDiscard.java:20
org.wpilib.command3.Command
Definition
Command.java:98
org.wpilib.command3.Command.LOWEST_PRIORITY
int LOWEST_PRIORITY
Definition
Command.java:106
org.wpilib.command3.Command.waitUntil
static NeedsNameBuilderStage waitUntil(BooleanSupplier condition)
Definition
Command.java:338
org.wpilib.command3.Command.requiring
static NeedsExecutionBuilderStage requiring(Collection< Mechanism > requirements)
Definition
Command.java:276
org.wpilib.command3.Command.andThen
default SequentialGroupBuilder andThen(Command next)
Definition
Command.java:389
org.wpilib.command3.Command.DEFAULT_PRIORITY
int DEFAULT_PRIORITY
Definition
Command.java:100
org.wpilib.command3.Command.name
String name()
org.wpilib.command3.Command.onCancel
default void onCancel()
Definition
Command.java:132
org.wpilib.command3.Command.until
default ParallelGroupBuilder until(BooleanSupplier endCondition)
Definition
Command.java:367
org.wpilib.command3.Command.alongWith
default ParallelGroupBuilder alongWith(Command... parallel)
Definition
Command.java:411
org.wpilib.command3.Command.noRequirements
static NeedsNameBuilderStage noRequirements(Consumer< Coroutine > body)
Definition
Command.java:248
org.wpilib.command3.Command.parallel
static ParallelGroupBuilder parallel(Command... commands)
Definition
Command.java:291
org.wpilib.command3.Command.requiring
static NeedsExecutionBuilderStage requiring(Mechanism requirement, Mechanism... rest)
Definition
Command.java:262
org.wpilib.command3.Command.raceWith
default ParallelGroupBuilder raceWith(Command... parallel)
Definition
Command.java:425
org.wpilib.command3.Command.requires
default boolean requires(Mechanism mechanism)
Definition
Command.java:198
org.wpilib.command3.Command.withTimeout
default Command withTimeout(Time timeout)
Definition
Command.java:228
org.wpilib.command3.Command.HIGHEST_PRIORITY
int HIGHEST_PRIORITY
Definition
Command.java:112
org.wpilib.command3.Command.race
static ParallelGroupBuilder race(Command... commands)
Definition
Command.java:307
org.wpilib.command3.Command.sequence
static SequentialGroupBuilder sequence(Command... commands)
Definition
Command.java:323
org.wpilib.command3.Command.run
void run(Coroutine coroutine)
org.wpilib.command3.Command.priority
default int priority()
Definition
Command.java:174
org.wpilib.command3.Command.waitFor
static NeedsNameBuilderStage waitFor(Time duration)
Definition
Command.java:351
org.wpilib.command3.Command.onExit
default void onExit()
Definition
Command.java:142
org.wpilib.command3.Command.isLowerPriorityThan
default boolean isLowerPriorityThan(Command other)
Definition
Command.java:185
org.wpilib.command3.Command.conflictsWith
default boolean conflictsWith(Command other)
Definition
Command.java:210
org.wpilib.command3.Command.requirements
Set< Mechanism > requirements()
org.wpilib.command3.Mechanism
Definition
Mechanism.java:21
org.wpilib.command3.NeedsExecutionBuilderStage
Definition
NeedsExecutionBuilderStage.java:18
org.wpilib.command3.NeedsExecutionBuilderStage.requiring
NeedsExecutionBuilderStage requiring(Mechanism requirement)
org.wpilib.command3.NeedsNameBuilderStage
Definition
NeedsNameBuilderStage.java:17
org.wpilib.command3.NeedsNameBuilderStage.named
Command named(String name)
org
wpilib
command3
Command.java
Generated by
1.18.0