Skip to content

Commit ec39fdf

Browse files
committed
feat: add documentation for more command utilities
1 parent 4db3588 commit ec39fdf

2 files changed

Lines changed: 116 additions & 25 deletions

File tree

src/nextftc/commands/utilities.md

Lines changed: 81 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,74 @@
22

33
NextFTC has a bunch of utility commands to help you simplify your code!
44

5-
## `InstantCommand`
5+
## Instant Commands
66

77
An `InstantCommand` runs a function and ends instantly.
8+
The `instant` utility function can be used to create an `InstantCommand`.
89

910
:::tabs key:code
1011
== Kotlin
1112

1213
```kotlin
13-
InstantCommand {
14+
instant("name") {
15+
// code here
16+
}
17+
18+
// or
19+
20+
instant {
1421
// code here
1522
}
1623
```
1724

1825
== Java
1926

2027
```java
21-
new InstantCommand(() -> {
28+
instant("name", () -> {
2229
// code here
2330
})
31+
32+
// or
33+
34+
instant(() -> {
35+
// code here
36+
});
37+
```
38+
39+
:::
40+
41+
## Run Commands
42+
43+
A run command is similar to an `InstantCommand`, but it runs continuously until it is interrupted.
44+
There is no specific `RunCommand` class;
45+
instead, the `run` utility function can be used to create a run command.
46+
47+
:::tabs key:code
48+
49+
== Kotlin
50+
```kotlin
51+
run("name") {
52+
// code here
53+
}
54+
55+
// or
56+
57+
run {
58+
// code here
59+
}
60+
```
61+
62+
== Java
63+
```java
64+
run("name", () -> {
65+
// code here
66+
});
67+
68+
// or
69+
70+
run(() -> {
71+
// code here
72+
});
2473
```
2574

2675
:::
@@ -44,75 +93,82 @@ new NullCommand(parameter1, parameter2)
4493

4594
:::
4695

47-
## `ForcedParallelCommand`
96+
## `proxy`
4897

49-
A `ForcedParallelCommand` schedules another command and instantly ends. This can be useful in `SequentialGroups` where you want to start a command and move on.
98+
A proxy command schedules another command and instantly ends.
99+
This can be useful in `SequentialGroups` where you want to start a command and move on.
50100

51101
:::tabs key:code
52102
== Kotlin
53103

54104
```kotlin
55-
ForcedParallelCommand(command)
105+
proxy(command)
56106
```
57107

58108
== Java
59109

60110
```java
61-
new ForcedParallelCommand(command)
111+
proxy(command)
62112
```
63113

64114
:::
65115

66-
Alternatively, you can used the `.forcedParallel()` utility:
116+
Alternatively, you can used the `.asProxy()` utility:
67117

68118
:::tabs key:code
69119

70120
== Kotlin
71121

72122
```kotlin
73-
command.forcedParallel()
123+
command.asProxy()
74124
```
75125

76126
== Java
77127

78128
```java
79-
command.forcedParallel()
129+
command.asProxy()
80130
```
81131

82132
:::
83133

84-
## `PerpetualCommand`
134+
## `repeatedly`
85135

86-
A `PerpetualCommand` wraps another command and never finishes unless it is interrupted. It simply ignores the `isDone` condition on the command it wraps.
136+
The `repeatedly` decorator can be used to create a command that runs until it is interrupted or stopped,
137+
repeatedly executing a given block of code.
87138

88-
:::tabs key:code
89-
== Kotlin
139+
If `isDone` is true, the command will restart, causing `start` to be called again.
140+
This will happen infinitely until the command is interrupted,
141+
or stopped as part of a `ParallelRaceGroup` or `ParallelDeadlineGroup`.
142+
143+
::: tabs key:code
90144

145+
== Kotlin
91146
```kotlin
92-
PerpetualCommand(commandToWrap)
147+
command.repeatedly()
93148
```
94149

95150
== Java
96-
97151
```java
98-
new PerpetualCommand(commandToWrap)
152+
command.repeatedly();
99153
```
100154

101-
:::
155+
:::
102156

103-
Alternatively, you can use the `.perpetually()` utility:
157+
## `until`
104158

105-
:::tabs key:code
106-
== Kotlin
159+
The `until` decorator can be used to create a command that runs until a given condition is true.
107160

161+
::: tabs key:code
162+
163+
== Kotlin
108164
```kotlin
109-
commandToWrap.perpetually()
165+
command.until { /* condition */ }
110166
```
111167

112168
== Java
113-
114169
```java
115-
commandToWrap.perpetually()
170+
command.until(() -> { /* condition */ });
116171
```
117172

118-
:::
173+
:::
174+

src/nextftc/concepts/subsystems.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,41 @@ public Command pivotRight = new SetPosition(pivotServo, 0.0).requires(pivotServo
105105

106106
:::
107107

108+
## Subsystem Command Factories
109+
110+
Within a `Subsystem`, you can use the builtin `instant` and `run` functions
111+
to create commands that automatically require the subsystem.
112+
113+
:::tabs key:code
114+
115+
== Kotlin
116+
117+
```kotlin
118+
object MySubsystem : Subsystem {
119+
private val motor = MotorEx("motor")
120+
121+
val stopMotor = instant {
122+
motor.power = 0.0
123+
} // automatically requires this
124+
}
125+
```
126+
127+
== Java
128+
129+
```java
130+
public class MySubsystem implements Subsystem {
131+
public static MySubsystem INSTANCE = new MySubsystem();
132+
133+
private MotorEx motor = new MotorEx("motor");
134+
135+
public Command stopMotor = instant(() -> {
136+
motor.setPower(0.0);
137+
}); // automatically requires this
138+
}
139+
```
140+
141+
:::
142+
108143
## Subsystem Groups
109144

110145
NextFTC provides a `SubsystemGroup` class that can be used to group multiple

0 commit comments

Comments
 (0)