-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from flamingchickens1540/adjustable-manager
Improve AdjustableManager
- Loading branch information
Showing
5 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/org/team1540/base/util/SimpleLoopCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.team1540.base.util; | ||
|
||
import edu.wpi.first.wpilibj.Sendable; | ||
import edu.wpi.first.wpilibj.command.Command; | ||
import edu.wpi.first.wpilibj.command.Subsystem; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
/** | ||
* A simple way to construct a {@link Command} which executes every tick. <p> To create a {@code | ||
* SimpleLoopCommand} easily, simply pass it a no-argument lambda containing the code you would like | ||
* to execute. For example, to create a {@link Command} that requires the {@code Robot.shifter} | ||
* {@link Subsystem}, simply write: | ||
* <pre> | ||
* Command shift = new SimpleLoopCommand(() -> Robot.shifter.shift(), Robot.shifter); | ||
* </pre> | ||
* | ||
* Multiple {@code Subystems} can be added onto the end of the constructor to add multiple | ||
* requirements. <p> This can be used to quickly and easily put a button on the | ||
* SmartDashboard/Shuffleboard to run some code. Use {@link SmartDashboard#putData(Sendable)} to | ||
* pass it a newly created instance of this class. | ||
*/ | ||
public class SimpleLoopCommand extends Command { | ||
|
||
private Executable executable; | ||
|
||
/** | ||
* Creates a new {@code SimpleLoopCommand}. | ||
* | ||
* @param name The name of the commmand. This is required to avoid everything being called | ||
* SimpleCommand. | ||
* @param action The code to run when the command executes. | ||
* @param requirements The {@link Subsystem Subsystems} required by the command (if any). | ||
*/ | ||
public SimpleLoopCommand(String name, Executable action, Subsystem... requirements) { | ||
super(name); | ||
executable = action; | ||
|
||
for (Subsystem requirement : requirements) { | ||
requires(requirement); // java_irl | ||
} | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
executable.execute(); | ||
} | ||
|
||
@Override | ||
protected boolean isFinished() { | ||
return false; | ||
} | ||
} |