Skip to content

Commit 1b2ed8d

Browse files
authored
Merge beta docs into main (#29)
* refactor: move command creation info to the custom commands page * feat: add documentation for more command utilities
1 parent 0c39e4a commit 1b2ed8d

4 files changed

Lines changed: 233 additions & 148 deletions

File tree

src/nextftc/commands/custom-commands.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,120 @@ fun runToPosition(
4949
5050
The `setStart`, `setUpdate`, `setIsDone`, and `setStop`
5151
methods directly map to the methods of the `Command` class.
52+
53+
In general, a lambda command can be created as follows:
54+
55+
:::tabs key:code
56+
== Kotlin
57+
58+
```kotlin
59+
val myLambdaCommand = LambdaCommand()
60+
.setStart {
61+
// Runs on start
62+
}
63+
.setUpdate {
64+
// Runs on update
65+
}
66+
.setStop { interrupted ->
67+
// Runs on stop
68+
}
69+
.setIsDone { true } // Returns if the commmand has finished
70+
.requires(/* subsystems the command implements */)
71+
.setInterruptible(true)
72+
.named("My Command") // sets the name of the command; optional
73+
```
74+
75+
== Java
76+
77+
```java
78+
Command myLambdaCommand = new LambdaCommand()
79+
.setStart(() -> {
80+
// Runs on start
81+
})
82+
.setUpdate(() -> {
83+
// Runs on update
84+
})
85+
.setStop(interrupted -> {
86+
// Runs on stop
87+
})
88+
.setIsDone(() -> true) // Returns if the command has finished
89+
.requires(/* subsystems the command implements */)
90+
.setInterruptible(true)
91+
.named("My Command"); // sets the name of the command; optional
92+
```
93+
94+
:::
95+
96+
> [!TIP]
97+
> All functions are completely optional. You only need to call the ones you will
98+
> use. They can be called in any order.
99+
100+
## Command Classes
101+
102+
### Commands as Classes
103+
104+
It is unlikely that you will need to use this very often, but you can also
105+
create a command as a class. This is useful for cases where you need to reuse
106+
your command a lot. An command can be created as a class as follows:
107+
108+
:::tabs key:code
109+
== Kotlin
110+
111+
```kotlin
112+
class MyCommand(): Command() {
113+
114+
init {
115+
requires(/* subsystems */)
116+
setInterruptible(true) // this is the default, so you don't need to specify
117+
}
118+
119+
override val isDone: Boolean
120+
get() = false // whether or not the command is done
121+
122+
override fun start() {
123+
// executed when the command begins
124+
}
125+
126+
override fun update() {
127+
// executed on every update of the command
128+
}
129+
130+
override fun stop(interrupted: Boolean) {
131+
// executed when the command ends
132+
}
133+
}
134+
```
135+
136+
== Java
137+
138+
```java
139+
public class MyCommand extends Command {
140+
141+
public MyCommand() {
142+
requires(/* subsystems */);
143+
setInterrptuptible(true); // this is the default, so you don't need to specify
144+
}
145+
146+
@Override
147+
public boolean isDone() {
148+
return false; // whether or not the command is done
149+
}
150+
151+
@Override
152+
public void start() {
153+
// executed when the command begins
154+
}
155+
156+
@Override
157+
public void update() {
158+
// executed on every update of the command
159+
}
160+
161+
@Override
162+
public void stop(boolean interrupted) {
163+
// executed when the command ends
164+
}
165+
}
166+
```
167+
168+
:::

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+

0 commit comments

Comments
 (0)