Skip to content

Commit

Permalink
Merge pull request #109 from flamingchickens1540/issue-104
Browse files Browse the repository at this point in the history
Add SimpleAsyncCommand docs
  • Loading branch information
RobinsonZ authored Jan 9, 2019
2 parents de9b0aa + 6fbc4a5 commit 172ec34
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions docs/Simple Utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The Simple Utilities, located in the `util` and `triggers` packages, make develo

## SimpleButton

[`SimpleButton`](https://flamingchickens1540.github.io/ROOSTER/index.html?org/team1540/base/triggers/SimpleButton.html) is a way to create a WPILIb `Button` class based off of an arbitrary function returning a `boolean` in one line of code. This is useful if you want to set up complex control schemes; for example, having a button that is only considered pressed if a joystick is in a certain range.
[`SimpleButton`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/rooster/triggers/SimpleButton.html) is a way to create a WPILIb `Button` class based off of an arbitrary function returning a `boolean` in one line of code. This is useful if you want to set up complex control schemes; for example, having a button that is only considered pressed if a joystick is in a certain range.

### Examples

Expand Down Expand Up @@ -36,7 +36,7 @@ Button atLeast5TrueButton = new SimpleButton(() -> {

## SimpleCommand/SimpleLoopCommand

[`SimpleCommand`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/base/util/SimpleCommand.html) and [`SimpleLoopCommand`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/base/util/SimpleLoopCommand.html) are wrappers that allow the creation of WPILib `Commands` that run an arbitrary function when executed. `SimpleCommand` runs the provided code once before finishing, while `SimpleLoopCommand` will run until canceled or interrupted. Both types can have requirements just like normal commands.
[`SimpleCommand`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/base/rooster/SimpleCommand.html) and [`SimpleLoopCommand`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/rooster/util/SimpleLoopCommand.html) are wrappers that allow the creation of WPILib `Commands` that run an arbitrary function when executed. `SimpleCommand` runs the provided code once before finishing, while `SimpleLoopCommand` will run until canceled or interrupted. Both types can have requirements just like normal commands.

Note that the constructor for `SimpleCommand` requires a name; this is so that the command has a sensible name that is preserved across different program runs (as otherwise the names could be different depending on what order something is initialized statically).

Expand Down Expand Up @@ -75,7 +75,7 @@ Command printTime = new SimpleLoopCommand("Print Current Time", () -> System.out

## SimpleConditionalCommand

[`SimpleConditionalCommand`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/base/util/SimpleConditionalCommand.html) is a wrapper that allows the creation of WPILib `ConditionalCommand` instances based off of an arbitrary function returning a `boolean` in one line of code. `SimpleConditionalCommands`, like `ConditionalCommands`, can run a `Command` only if the provided condition is `true`, or run one of two commands depending on the condition.
[`SimpleConditionalCommand`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/rooster/util/SimpleConditionalCommand.html) is a wrapper that allows the creation of WPILib `ConditionalCommand` instances based off of an arbitrary function returning a `boolean` in one line of code. `SimpleConditionalCommands`, like `ConditionalCommands`, can run a `Command` only if the provided condition is `true`, or run one of two commands depending on the condition.

### Examples

Expand All @@ -93,3 +93,17 @@ Command somethingOrSomethingElse = new SimpleConditionalCommand(this::getFoo,
new DoSomethingElse());
```

## SimpleAsyncCommand

[`SimpleAsyncCommand`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/rooster/util/SimpleAsyncCommand.html) is a variant of `SimpleLoopCommand` which leverages the [`AsyncCommand`](https://flamingchickens1540.github.io/ROOSTER/org/team1540/rooster/util/AsyncCommand.html) class to run code in a seperate loop outside of the main robot loop. It's useful for mechanism control loops and other code that needs to update faster than the main robot loop. It is used exactly like a `SimpleLoopCommand`, with the exception of an additional parameter specifying the loop time.

Note that any code provided to the command will be run in a separate thread and thus must be thread-safe.

### Examples

Update a drivetrain's control loop every 10 milliseconds:

```java
Command controlLoopCommand = new SimpleAsyncCommand("Update", 20, Robot.drivetrain::update(), Robot.drivetrain);
```

0 comments on commit 172ec34

Please sign in to comment.