Skip to content

Commit

Permalink
Fix typo, add subsystem methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bovlb committed Jan 27, 2025
1 parent 5be79e3 commit 344b081
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 19 additions & 5 deletions commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,34 @@ The following commands are useful to build command groups. Some of them take co

## Runnable wrappers

Here are some wrappers that turn runnables (e.g. [lambda expressions](lambda.md)) into commands. These can be used in command groups, but they are also used in `RobotContainer` to create command on-the-fly. When using these methods, please remember to add the subsystem(s) as the last parameter(s) to make subsystem requirements work correctly.
Here are some wrapper classes that turn runnables (e.g. [lambda expressions](lambda.md)) into commands. These can be used in command groups, but they are also used in `RobotContainer` to create command on-the-fly. When using these methods, please remember to add the subsystem(s) as the last parameter(s) to make subsystem requirements work correctly.

* `InstantCommand`: The given runnable is used as the `initialize` method, there is no `execute` or `end`, and `isFinished` returns `true`. You will also sometimes inherit from `InstantCommand` instead of `BaseCommand`.
* `RunCommand`: The given runnable is used as the `execute` method, there is no `initialize` or `end`, and `isFinished` returns `false`. Often used with a decorator that adds an `isFinished` condition.
* `StartEndCommand`: The given runnables are used as the `initialize` and `end` methods, there is no `execute`, and `isFinished` returns `false`. Commonly used for commands that start and stop motors.
* `FunctionalCommand`: Allows you you set all four life-cycle methods. Not used if one of the above will suffice.

| Wrapper | `initialize` | `execute` | `end` | `isFinished` |
| Class | `initialize` | `execute` | `end` | `isFinished` |
| --- | --- | --- | --- | --- |
| `InstantCommand` | arg 1 | empty | empty | `true` |
| `RunCommand` | empty | arg 1 | empty | `false` |
| `StartEndCommand` | arg 1 | empty | arg 2 | `false` |
| `InstantCommand` | arg 1 | | | `true` |
| `RunCommand` | | arg 1 | | `false` |
| `StartEndCommand` | arg 1 | | arg 2 | `false` |
| `FunctionalCommand` | arg 1 | arg 2 | arg 3 | arg 4 |

## Subsystem wrapper methods

The `Subsystem` class provides some useful methods that provide more or less the same functionality as the classes above, with the feature that they automatically get the subsystem as a requirement.

| Method | `initialize` | `execute` | `end` | `isFinished` | Equivalent to |
| --- | --- | --- | --- | --- | --- |
| `run` | | arg 1 | | `false` | `RunCommand ` |
| `runEnd` | | arg 1 | arg 2 | `false` |
| `runOnce` | arg 1 | | | `true` | `InstantCommand` |
| `startEnd` | arg 1 | | arg 2 | `false` | `StartEndCommand` |
| `startRun` | arg1 | arg 2 | | `false` |

`Subsystem` also provides a method `defer` which is used to create `DeferedCommand`. This take a `Command` supplier, so the underlying command is not determined until `initialize`.

## Command decorators

These are methods that are provided by all `Command`s and allow you to create new commands that modify the underlying command in some way, or implicitly create command groups. These can be used as an alternative way to write command groups, but are also used when creating commands on-the-fly in `RobotContainer`.
Expand Down
4 changes: 2 additions & 2 deletions commands/lambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MySubsystem ... {

...

private final MySubsystem subsystem = new Subsystem();
private final MySubsystem subsystem = new MySubsystem();

// Get an anonoymous function reference with the same arguments
// and return type. Use this as a boolean supplier without
Expand Down Expand Up @@ -163,7 +163,7 @@ In WPILIB, `Trigger`s implement the `BooleanSupplier` interface and often accept

A `Runnable` is a class that has a `void run()` method.
It can be created from an anonymous function that takes no arguments (and any return value is ignored).
In WPILIB, it can be used to create commands on-the-fly using `InstantCommand`, `RunCommand`, `StartEndCommand`, or `FunctionalCommand`.
In WPILIB, it can be used to create commands on-the-fly using the classes`InstantCommand`, `RunCommand`, `StartEndCommand`, or `FunctionalCommand` or certain `Subsystem` methods `.
It can also be passed to many trigger methods (along with a required subsystem).

```java
Expand Down

0 comments on commit 344b081

Please sign in to comment.