-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional support for command-based robots (#116)
* Add a CommandRobot base Takes care of the boilerplate for running the scheduler. Does not implement any of the logic for selecting or creating autonomous modes. * Add SubsystemCommand to extras It behaves as a regular command, but automatically calls `.Requires` on the provided subsystem and stores a reference to it as `m_subsystem` * Fix comments to provide more accurate description
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
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,26 @@ | ||
using WPILib.Commands; | ||
|
||
namespace WPILib.Extras | ||
{ | ||
/// <summary> | ||
/// Implements the boilerplate needed to use an <see cref="IterativeRobot"/> | ||
/// with the command-based model, by running the scheduler as needed. | ||
/// </summary> | ||
public abstract class CommandRobot : IterativeRobot | ||
{ | ||
// This function is called periodically while disabled | ||
public override void DisabledPeriodic() => Scheduler.Instance.Run(); | ||
|
||
// This function is called periodically during autonomous | ||
public override void AutonomousPeriodic() => Scheduler.Instance.Run(); | ||
|
||
// This function is called when the disabled button is hit. | ||
public override void DisabledInit() { } | ||
|
||
// This function is called periodically during operator control | ||
public override void TeleopPeriodic() => Scheduler.Instance.Run(); | ||
|
||
// This function is called periodically during test mode | ||
public override void TestPeriodic() => LiveWindow.LiveWindow.Run(); | ||
} | ||
} |
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,37 @@ | ||
using System; | ||
using WPILib.Commands; | ||
|
||
namespace WPILib.Extras | ||
{ | ||
/// <summary> | ||
/// A <see cref="SubsystemCommand"/> depends on the given <see cref="Subsystem"/>. | ||
/// It stores a local reference to its <see cref="Subsystem" /> to ease access. | ||
/// </summary> | ||
public abstract class SubsystemCommand : Command | ||
{ | ||
protected readonly Subsystem m_subsystem; | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="SubsystemCommand"/> which will depend on the given <see cref="Subsystem"/>. | ||
/// </summary> | ||
/// <param name="action">The <see cref="Action"/> to run.</param> | ||
public SubsystemCommand(Subsystem subsystem) | ||
{ | ||
Requires(subsystem); | ||
m_subsystem = subsystem; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="SubsystemCommand"/> with a specific name, | ||
/// which will depend on the given <see cref="Subsystem"/>. | ||
/// </summary> | ||
/// <param name="subsystem">The <see cref="Subsystem"/> to require.</param> | ||
/// <param name="name">The name for the command.</param> | ||
public SubsystemCommand(Subsystem subsystem, string name) | ||
: base(name) | ||
{ | ||
Requires(subsystem); | ||
m_subsystem = subsystem; | ||
} | ||
} | ||
} |
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