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: commands/best-practices.md
+12-5
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ The implementation of these commands is entirely within the subsystem module, so
42
42
43
43
Take care in choosing which commands to implement and what to name them.
44
44
Remember that the core idea here is to isolate client code from knowing anything about subsystem implementation, including any specific values for position or speed.
45
-
If a subsystem has a number of positions, modes, or speeds then you will want to create a separate command for each one.
45
+
If a subsystem has a number of positions, modes, or speeds then you could expose an `enum`, but it is probably better to create a separate command factory for each one.
46
46
Internally, you may want to use `enum` to name and configure the different setpoints.
47
47
This allows you to use `setName` to give each one an appropriate label for debugging.
If a command needs configuration or other information from elsewhere, then either the factory or the Subsystem constructor should take a `Supplier`, e.g. a `BooleanSupplier` or a `DoubleSupplier`.
85
-
Pass it to the constructor if it's a universal piece of information; pass it to the command factory if it's a detail of the specific command being constructed.
85
+
Pass it to the constructor if it's a universal piece of information that might be used by multiple commands; pass it to the command factory if it's a detail of the specific command being constructed.
86
86
87
87
This supplier should be providing outside information from the problem space, not implementation specifics.
88
88
We prefer to pass a `Supplier` rather than a specific value because we want to be able to support dynamic configuration where the value changes.
@@ -178,8 +178,8 @@ anything that requires co-ordination between multiple subsystems.
178
178
179
179
Now that you have a good collection of Triggers, think about how they should be combined to make useful decisions about robot behaviour.
180
180
For example, when deciding whether to to shoot, you might think about various things:
181
-
* Is the driver pressing the "shoot" button? All drive buttons are already `Trigger`s.
182
-
* Is there a game piece in the right location? This might be determine by beam-break sensors, but the subsystem will package this in a `Trigger`.
181
+
* Is the driver pressing the "shoot" button? All driver buttons are already `Trigger`s.
182
+
* Is there a game piece in the right location? This might be determined by beam-break sensors, but the subsystem will package this in a `Trigger`.
183
183
* Is the robot within shooting range of the target? This may be based on a distance calculation, which in turn uses the location of the robot (and of the target).
184
184
* Are the shooter wheels ready? This may be a `Trigger` that compares the setpoint with the current speed.
185
185
* Are we aimed at the target? This may be a `Trigger` that compares the pivot mechanism's angle to the current setpoint.
@@ -213,9 +213,16 @@ m_shooter.isShooting
213
213
214
214
To bind a command to a trigger, simply use a method like `onTrue`, `whileTrue` or `toggleOnTrue`.
215
215
`onTrue` is good for instant commands that do something and immediately stop.
216
-
`whileTrue` is good for commands that should keep executing so long as the condition is true.
216
+
`whileTrue` is good for commands that should keep executing so long as the condition is true, or which have an `end` action (perhaps added using the `finallyDo` method).
217
217
`toggleOnTrue` is usually only used with driver buttons, so they can enable and disable some mode.
218
218
219
+
```java
220
+
// Deploy the intake while the button is held down
Copy file name to clipboardExpand all lines: commands/commandscheduler.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ You must learn how to break your code up into small pieces that execute quickly
7
7
8
8
The `CommandScheduler` will manage commands, calling their four lifecycle methods (`initialize`, `execute`, `isFinished`, `end`).
9
9
It will also call the `periodic` methods of your subsystems and test any triggers you may have (mostly this will be joystick buttons).
10
-
It is also responsible for managing the requirements of two commands, so two commands with overlapping requirements are never scheduled at the same time.
10
+
It is also responsible for managing the requirements of commands, so two commands with overlapping requirements are never scheduled at the same time.
11
11
12
12
There are a number of ways to invoke the `CommandScheduler`:
0 commit comments