You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/nextftc/concepts/commands.md
+36-17Lines changed: 36 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,44 @@
1
1
# Commands
2
2
3
-
_Why use commands?_ Commands allow you to **organize your code** much more efficiently than you could otherwise. They are an excellent alternative to [finite state machines](https://gm0.org/en/latest/docs/software/concepts/finite-state-machines.html), but are a lot easier to create and modify, and can reach higher levels of complexity than a finite state machine can.
3
+
_Why use commands?_ Commands allow you to **organize your code** much more
4
+
efficiently than you could otherwise. They are an excellent alternative
5
+
to [finite state machines](https://gm0.org/en/latest/docs/software/concepts/finite-state-machines.html),
6
+
are a lot easier to create and modify, and can reach higher levels of complexity
7
+
than a finite state machine can.
4
8
5
9
## Parts of a Command
6
10
7
11
A command has four main components: `isDone`, `start`, `update`, and `stop`.
8
12
9
-
-`isDone` is checked every loop. If it ever evaluates to `true`, the command will stop running.
10
-
-`start` is run once, when the command is scheduled. It is used for setting up starting states and doing other things that should only happen once.
11
-
-`update` runs every loop, many times per second. Because of this, it is crucial that it never takes more than a trivial amount of time to execute. You should be extremely careful of looping or doing anything else that could take significant amounts of time
12
-
-`stop` runs once when the command ends, and recieves a parameter of whether or not it was interrupted by a different command.
13
+
-`isDone` is checked every loop. If it ever evaluates to `true`, the command
14
+
will stop running.
15
+
-`start` is run once, when the command is scheduled. It is used for setting up
16
+
starting states and doing other things that should only happen once.
17
+
-`update` runs every loop, many times per second. Because of this, it is
18
+
crucial that it never takes more than a trivial amount of time to execute. You
19
+
should be extremely careful of looping or doing anything else that could take
20
+
significant amounts of time
21
+
-`stop` runs once when the command ends, and receives a parameter of
22
+
whether it was interrupted by a different command.
13
23
14
24
Additionally, it has two more properties:
15
25
16
-
-`interruptible` determines whether or not the command is able to be interrupted. A command is interrupted when another command is scheduled that requires a subsystem the command is using. If a command is not interruptible, then the new command will not run.
17
-
-`subsystems` is a set of all the subsystems a command uses. This is used for determing when two commands requrie the same subsystem. This is passed to the constructor of most premade commands.
26
+
-`interruptible` determines whether the command is able to be
27
+
interrupted. A command is interrupted when another command is scheduled that
28
+
requires a subsystem the command is using. If a command is not interruptible,
29
+
then the new command will not run.
30
+
-`requirements` is a set of all the requirements a command has. This is
31
+
used to determine when two commands require the same resource.
18
32
19
33
## Creating Commands
20
34
21
-
There are two ways to create a command: a `LambdaCommand` and by creating your own command class.
35
+
There are two ways to create a command: a `LambdaCommand` and by creating your
36
+
own command class.
22
37
23
38
### Lambda Commands
24
39
25
-
A lambda command is the main way to create a command in NextFTC. A lambda command can be created as follows:
40
+
A lambda command is the main way to create a command in NextFTC. A lambda
41
+
command can be created as follows:
26
42
27
43
:::tabs key:code
28
44
== Kotlin
@@ -39,7 +55,7 @@ val myLambdaCommand = LambdaCommand()
39
55
// Runs on stop
40
56
}
41
57
.setIsDone { true } // Returns if the commmand has finished
42
-
.setRequirements(/* subsystems the command implements */)
58
+
.requires(/* subsystems the command implements */)
43
59
.setInterruptible(true)
44
60
```
45
61
@@ -57,18 +73,21 @@ Command myLambdaCommand = new LambdaCommand()
57
73
// Runs on stop
58
74
})
59
75
.setIsDone(() ->true) // Returns if the command has finished
60
-
.setRequirements(/* subsystems the command implements */)
76
+
.requires(/* subsystems the command implements */)
61
77
.setInterruptible(true)
62
78
```
63
79
64
80
:::
65
81
66
82
> [!TIP]
67
-
> All functions are completely optional. You only need to call the ones you will use. They can be called in any order.
83
+
> All functions are completely optional. You only need to call the ones you will
84
+
> use. They can be called in any order.
68
85
69
86
## Commands as Classes
70
87
71
-
It is unlikely that you will need to use this very often, but you can also create a command as a class. This is useful for cases where you need to reuse your command a lot. An command can be created as a class as follows:
88
+
It is unlikely that you will need to use this very often, but you can also
89
+
create a command as a class. This is useful for cases where you need to reuse
90
+
your command a lot. An command can be created as a class as follows:
72
91
73
92
:::tabs key:code
74
93
== Kotlin
@@ -77,7 +96,7 @@ It is unlikely that you will need to use this very often, but you can also creat
77
96
classMyCommand(): Command() {
78
97
79
98
init {
80
-
setRequirements(/* subsystems */)// you can make this a constructor parameter, if needed
99
+
requires(/* subsystems */)
81
100
setInterruptible(true) // this is the default, so you don't need to specify
82
101
}
83
102
@@ -104,7 +123,7 @@ class MyCommand(): Command() {
104
123
publicclassMyCommandextendsCommand {
105
124
106
125
publicMyCommand() {
107
-
setRequirements(/* subsystems */);// you can make this a constructor parameter, if needed
126
+
requires(/* subsystems */);
108
127
setInterrptuptible(true); // this is the default, so you don't need to specify
109
128
}
110
129
@@ -134,9 +153,8 @@ public class MyCommand extends Command {
134
153
135
154
## Executing Commands
136
155
137
-
There are two ways to schedule a command.
156
+
There are two ways to schedule a command. You can either call:
Copy file name to clipboardExpand all lines: src/nextftc/concepts/units.md
+12-39Lines changed: 12 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,15 @@
1
1
# Units
2
2
3
-
NextFTC has an immutable, type-safe units system that allows you to pass quantities in any unit. It also prevents you from mixing up units accidentally. NextFTC has three types of units: `Distance`, `Angle`, and `TimeSpan`. All units extend the `Quantity` abstract class.
3
+
NextFTC has an immutable, type-safe units system that allows you to pass
4
+
quantities in any unit. It also prevents you from mixing up units accidentally.
5
+
NextFTC has two types of units: `Distance` and `Angle`. All units extend the
6
+
`Quantity` abstract class.
4
7
5
8
## `Distance`
6
9
7
-
The first unit we'll look at is `Distance`. There are six units `Distance` accepts: millimeters, centimeters, meters, inches, feet, and yards. Internally it is stored in millimeters.
10
+
The first unit we'll look at is `Distance`. There are six units `Distance`
11
+
accepts: millimeters, centimeters, meters, inches, feet, and yards. Internally
12
+
it is stored in millimeters.
8
13
9
14
Creating a `Distance` is simple:
10
15
@@ -83,7 +88,6 @@ val inch = 1.inch
83
88
84
89
val sum = foot + inch // 13 in
85
90
val difference = foot - inch // 11 in
86
-
val product = foot * inch // 12 in (should be in^2 but NextFTC isn't THAT complicated)
87
91
val quotient = foot / inch // 12
88
92
89
93
val bigger = foot *2// 24 in
@@ -115,7 +119,6 @@ Distance inch = Distance.fromIn(1);
115
119
116
120
Distance sum = foot.plus(inch); // 13 in
117
121
Distance difference = foot.minus(inch); // 11 in
118
-
Distance product = foot.times(inch); // 12 in (should be in^2 but NextFTC isn't THAT complicated)
`TimeSpan` is very similar to `Distance`, only with different units. Supported units are microseconds, milliseconds, and seconds. Internally it is stored in microseconds.
146
-
147
-
Using `TimeSpans` is simple:
148
-
149
-
:::tabs key:code
150
-
== Kotlin
151
-
152
-
```kotlin
153
-
val seconds =1.sec
154
-
val milliseconds =5.ms
155
-
val microseconds =70000000.us
156
-
157
-
val secondsInMilliseconds = seconds.inMs // 1,000
158
-
val millisecondsInMicroseconds = milliseconds.inUs // 5,000
159
-
val microsecondsInSeconds = microseconds.inSec // 70
An `Angle` is very similar to `Distance` and `TimeSpan`, but it also has functionality for wrapping and normalizing. Angles can be in radians, degrees, or full revolutions, and are stored internally as radians.
148
+
`Angle` is very similar to `Distance`, but it also has
149
+
functionality for wrapping and normalizing. Angles can be in radians, degrees,
150
+
or full revolutions, and are stored internally as radians.
0 commit comments