Skip to content

Commit ec1b772

Browse files
committed
Tweaks, add finallyDo to diagrams
1 parent a0e82cd commit ec1b772

5 files changed

+13
-6
lines changed

Diff for: commands/best-practices.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The implementation of these commands is entirely within the subsystem module, so
4242

4343
Take care in choosing which commands to implement and what to name them.
4444
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.
4646
Internally, you may want to use `enum` to name and configure the different setpoints.
4747
This allows you to use `setName` to give each one an appropriate label for debugging.
4848

@@ -82,7 +82,7 @@ private Command setAngle(DoubleSupplier angle) {
8282
```
8383

8484
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.
8686

8787
This supplier should be providing outside information from the problem space, not implementation specifics.
8888
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.
178178

179179
Now that you have a good collection of Triggers, think about how they should be combined to make useful decisions about robot behaviour.
180180
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`.
183183
* 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).
184184
* Are the shooter wheels ready? This may be a `Trigger` that compares the setpoint with the current speed.
185185
* 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
213213

214214
To bind a command to a trigger, simply use a method like `onTrue`, `whileTrue` or `toggleOnTrue`.
215215
`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).
217217
`toggleOnTrue` is usually only used with driver buttons, so they can enable and disable some mode.
218218

219+
```java
220+
// Deploy the intake while the button is held down
221+
JoystockButton(m_driverJoystick, 3)
222+
.whileTrue(m_intake.deploy()
223+
.finallyDo(m_intake.stop()));
224+
```
225+
219226

220227
<div style="clear:both" />
221228

Diff for: commands/commandscheduler.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ You must learn how to break your code up into small pieces that execute quickly
77

88
The `CommandScheduler` will manage commands, calling their four lifecycle methods (`initialize`, `execute`, `isFinished`, `end`).
99
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.
1111

1212
There are a number of ways to invoke the `CommandScheduler`:
1313

Diff for: commands/main-diagram-dark.jpg

80.1 KB
Loading

Diff for: commands/main-diagram-dark.png

-399 KB
Loading

Diff for: commands/main-diagram-light.png

-402 KB
Loading

0 commit comments

Comments
 (0)