mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[examples] HatchbotInlined: Use Subsystem factories (#4765)
This commit is contained in:
@@ -33,11 +33,9 @@ void RobotContainer::ConfigureButtonBindings() {
|
||||
// Configure your button bindings here
|
||||
|
||||
// Grab the hatch when the 'Circle' button is pressed.
|
||||
m_driverController.Circle().OnTrue(
|
||||
frc2::cmd::RunOnce([this] { m_hatch.GrabHatch(); }, {&m_hatch}));
|
||||
m_driverController.Circle().OnTrue(m_hatch.GrabHatchCommand());
|
||||
// Release the hatch when the 'Square' button is pressed.
|
||||
m_driverController.Square().OnTrue(
|
||||
frc2::cmd::RunOnce([this] { m_hatch.ReleaseHatch(); }, {&m_hatch}));
|
||||
m_driverController.Square().OnTrue(m_hatch.ReleaseHatchCommand());
|
||||
// While holding R1, drive at half speed
|
||||
m_driverController.R1()
|
||||
.OnTrue(frc2::cmd::RunOnce([this] { m_drive.SetMaxOutput(0.5); }, {}))
|
||||
|
||||
@@ -51,7 +51,7 @@ frc2::CommandPtr autos::ComplexAuto(DriveSubsystem* drive,
|
||||
{drive})
|
||||
.ToPtr(),
|
||||
// Release the hatch
|
||||
frc2::cmd::RunOnce([hatch] { hatch->ReleaseHatch(); }, {hatch}),
|
||||
hatch->ReleaseHatchCommand(),
|
||||
// Drive backward the specified distance
|
||||
// Drive forward the specified distance
|
||||
frc2::FunctionalCommand(
|
||||
|
||||
@@ -10,10 +10,14 @@ HatchSubsystem::HatchSubsystem()
|
||||
: m_hatchSolenoid{frc::PneumaticsModuleType::CTREPCM,
|
||||
kHatchSolenoidPorts[0], kHatchSolenoidPorts[1]} {}
|
||||
|
||||
void HatchSubsystem::GrabHatch() {
|
||||
m_hatchSolenoid.Set(frc::DoubleSolenoid::kForward);
|
||||
frc2::CommandPtr HatchSubsystem::GrabHatchCommand() {
|
||||
// implicitly require `this`
|
||||
return this->RunOnce(
|
||||
[this] { m_hatchSolenoid.Set(frc::DoubleSolenoid::kForward); });
|
||||
}
|
||||
|
||||
void HatchSubsystem::ReleaseHatch() {
|
||||
m_hatchSolenoid.Set(frc::DoubleSolenoid::kReverse);
|
||||
frc2::CommandPtr HatchSubsystem::ReleaseHatchCommand() {
|
||||
// implicitly require `this`
|
||||
return this->RunOnce(
|
||||
[this] { m_hatchSolenoid.Set(frc::DoubleSolenoid::kReverse); });
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <frc/DoubleSolenoid.h>
|
||||
#include <frc/PneumaticsControlModule.h>
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
#include <frc2/command/SubsystemBase.h>
|
||||
|
||||
#include "Constants.h"
|
||||
@@ -19,12 +20,12 @@ class HatchSubsystem : public frc2::SubsystemBase {
|
||||
/**
|
||||
* Grabs the hatch.
|
||||
*/
|
||||
void GrabHatch();
|
||||
frc2::CommandPtr GrabHatchCommand();
|
||||
|
||||
/**
|
||||
* Releases the hatch.
|
||||
*/
|
||||
void ReleaseHatch();
|
||||
frc2::CommandPtr ReleaseHatchCommand();
|
||||
|
||||
private:
|
||||
// Components (e.g. motor controllers and sensors) should generally be
|
||||
|
||||
Reference in New Issue
Block a user