mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[examples] Improve Pneumatics example coverage in Solenoid and RapidReactCmdBot examples (#4998)
This commit is contained in:
@@ -40,6 +40,10 @@ void RapidReactCommandBot::ConfigureBindings() {
|
||||
m_storage.RunCommand())
|
||||
// Since we composed this inline we should give it a name
|
||||
.WithName("Shoot"));
|
||||
|
||||
// Toggle compressor with the Start button
|
||||
m_driverController.Start().ToggleOnTrue(
|
||||
m_pneumatics.DisableCompressorCommand());
|
||||
}
|
||||
|
||||
frc2::CommandPtr RapidReactCommandBot::GetAutonomousCommand() {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include "subsystems/Pneumatics.h"
|
||||
|
||||
Pneumatics::Pneumatics() {}
|
||||
|
||||
frc2::CommandPtr Pneumatics::DisableCompressorCommand() {
|
||||
return StartEnd(
|
||||
[&] {
|
||||
// Disable closed-loop mode on the compressor.
|
||||
m_compressor.Disable();
|
||||
},
|
||||
[&] {
|
||||
// Enable closed-loop mode based on the digital pressure switch
|
||||
// connected to the PCM/PH. The switch is open when the pressure is over
|
||||
// ~120 PSI.
|
||||
m_compressor.EnableDigital();
|
||||
});
|
||||
}
|
||||
|
||||
units::pounds_per_square_inch_t Pneumatics::GetPressure() {
|
||||
// Get the pressure (in PSI) from an analog pressure sensor connected to
|
||||
// the RIO.
|
||||
return units::pounds_per_square_inch_t{m_pressureTransducer.Get()};
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Constants.h"
|
||||
#include "subsystems/Drive.h"
|
||||
#include "subsystems/Intake.h"
|
||||
#include "subsystems/Pneumatics.h"
|
||||
#include "subsystems/Shooter.h"
|
||||
#include "subsystems/Storage.h"
|
||||
|
||||
@@ -45,6 +46,7 @@ class RapidReactCommandBot {
|
||||
Intake m_intake;
|
||||
Shooter m_shooter;
|
||||
Storage m_storage;
|
||||
Pneumatics m_pneumatics;
|
||||
|
||||
// The driver's controller
|
||||
frc2::CommandXboxController m_driverController{
|
||||
|
||||
@@ -28,7 +28,9 @@ class Intake : public frc2::SubsystemBase {
|
||||
|
||||
private:
|
||||
frc::PWMSparkMax m_motor{IntakeConstants::kMotorPort};
|
||||
frc::DoubleSolenoid m_piston{frc::PneumaticsModuleType::REVPH,
|
||||
|
||||
// Double solenoid connected to two channels of a PCM with the default CAN ID
|
||||
frc::DoubleSolenoid m_piston{frc::PneumaticsModuleType::CTREPCM,
|
||||
IntakeConstants::kSolenoidPorts[0],
|
||||
IntakeConstants::kSolenoidPorts[1]};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/AnalogPotentiometer.h>
|
||||
#include <frc/Compressor.h>
|
||||
#include <frc/PneumaticsControlModule.h>
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
#include <frc2/command/SubsystemBase.h>
|
||||
#include <units/pressure.h>
|
||||
|
||||
#include "Constants.h"
|
||||
|
||||
class Pneumatics : frc2::SubsystemBase {
|
||||
public:
|
||||
Pneumatics();
|
||||
/** Returns a command that disables the compressor indefinitely. */
|
||||
[[nodiscard]] frc2::CommandPtr DisableCompressorCommand();
|
||||
|
||||
/**
|
||||
* Query the analog pressure sensor.
|
||||
*
|
||||
* @return the measured pressure, in PSI
|
||||
*/
|
||||
units::pounds_per_square_inch_t GetPressure();
|
||||
|
||||
private:
|
||||
// External analog pressure sensor
|
||||
// product-specific voltage->pressure conversion, see product manual
|
||||
// in this case, 250(V/5)-25
|
||||
// the scale parameter in the AnalogPotentiometer constructor is scaled from
|
||||
// 1 instead of 5, so if r is the raw AnalogPotentiometer output, the
|
||||
// pressure is 250r-25
|
||||
static constexpr double kScale = 250;
|
||||
static constexpr double kOffset = -25;
|
||||
frc::AnalogPotentiometer m_pressureTransducer{/* the AnalogIn port*/ 2,
|
||||
kScale, kOffset};
|
||||
|
||||
// Compressor connected to a PH with a default CAN ID
|
||||
frc::Compressor m_compressor{frc::PneumaticsModuleType::CTREPCM};
|
||||
};
|
||||
Reference in New Issue
Block a user