mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal, wpilib] Incorporate pneumatic control type into wpilibc/j (#3728)
This commit is contained in:
@@ -19,7 +19,7 @@ Compressor::Compressor(int module, PneumaticsModuleType moduleType)
|
||||
throw FRC_MakeError(err::ResourceAlreadyAllocated, "{}", module);
|
||||
}
|
||||
|
||||
SetClosedLoopControl(true);
|
||||
m_module->EnableCompressorDigital();
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_Compressor, module + 1);
|
||||
wpi::SendableRegistry::AddLW(this, "Compressor", module);
|
||||
@@ -33,11 +33,11 @@ Compressor::~Compressor() {
|
||||
}
|
||||
|
||||
void Compressor::Start() {
|
||||
SetClosedLoopControl(true);
|
||||
EnableDigital();
|
||||
}
|
||||
|
||||
void Compressor::Stop() {
|
||||
SetClosedLoopControl(false);
|
||||
Disable();
|
||||
}
|
||||
|
||||
bool Compressor::Enabled() const {
|
||||
@@ -48,23 +48,34 @@ bool Compressor::GetPressureSwitchValue() const {
|
||||
return m_module->GetPressureSwitch();
|
||||
}
|
||||
|
||||
double Compressor::GetCompressorCurrent() const {
|
||||
double Compressor::GetCurrent() const {
|
||||
return m_module->GetCompressorCurrent();
|
||||
}
|
||||
|
||||
void Compressor::SetClosedLoopControl(bool on) {
|
||||
m_module->SetClosedLoopControl(on);
|
||||
void Compressor::Disable() {
|
||||
m_module->DisableCompressor();
|
||||
}
|
||||
|
||||
bool Compressor::GetClosedLoopControl() const {
|
||||
return m_module->GetClosedLoopControl();
|
||||
void Compressor::EnableDigital() {
|
||||
m_module->EnableCompressorDigital();
|
||||
}
|
||||
|
||||
void Compressor::EnableAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
m_module->EnableCompressorAnalog(minAnalogVoltage, maxAnalogVoltage);
|
||||
}
|
||||
|
||||
void Compressor::EnableHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
m_module->EnableCompressorHybrid(minAnalogVoltage, maxAnalogVoltage);
|
||||
}
|
||||
|
||||
CompressorConfigType Compressor::GetConfigType() const {
|
||||
return m_module->GetCompressorConfigType();
|
||||
}
|
||||
|
||||
void Compressor::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("Compressor");
|
||||
builder.AddBooleanProperty(
|
||||
"Closed Loop Control", [=]() { return GetClosedLoopControl(); },
|
||||
[=](bool value) { SetClosedLoopControl(value); });
|
||||
builder.AddBooleanProperty(
|
||||
"Enabled", [=] { return Enabled(); }, nullptr);
|
||||
builder.AddBooleanProperty(
|
||||
|
||||
@@ -80,17 +80,39 @@ bool PneumaticHub::GetCompressor() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
void PneumaticHub::SetClosedLoopControl(bool enabled) {
|
||||
void PneumaticHub::DisableCompressor() {
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControl(m_handle, enabled, &status);
|
||||
HAL_SetREVPHClosedLoopControlDisabled(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
bool PneumaticHub::GetClosedLoopControl() const {
|
||||
void PneumaticHub::EnableCompressorDigital() {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHClosedLoopControl(m_handle, &status);
|
||||
HAL_SetREVPHClosedLoopControlDigital(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return result;
|
||||
}
|
||||
|
||||
void PneumaticHub::EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControlAnalog(m_handle, minAnalogVoltage,
|
||||
maxAnalogVoltage, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticHub::EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControlHybrid(m_handle, minAnalogVoltage,
|
||||
maxAnalogVoltage, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
CompressorConfigType PneumaticHub::GetCompressorConfigType() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHCompressorConfig(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return static_cast<CompressorConfigType>(result);
|
||||
}
|
||||
|
||||
bool PneumaticHub::GetPressureSwitch() const {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "frc/PneumaticsBase.h"
|
||||
|
||||
#include <hal/REVPH.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/PneumaticHub.h"
|
||||
#include "frc/PneumaticsControlModule.h"
|
||||
@@ -11,6 +13,19 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
static_assert(
|
||||
static_cast<int>(CompressorConfigType::Disabled) ==
|
||||
HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kDisabled);
|
||||
static_assert(
|
||||
static_cast<int>(CompressorConfigType::Digital) ==
|
||||
HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kDigital);
|
||||
static_assert(
|
||||
static_cast<int>(CompressorConfigType::Analog) ==
|
||||
HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kAnalog);
|
||||
static_assert(
|
||||
static_cast<int>(CompressorConfigType::Hybrid) ==
|
||||
HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kHybrid);
|
||||
|
||||
std::shared_ptr<PneumaticsBase> PneumaticsBase::GetForType(
|
||||
int module, PneumaticsModuleType moduleType) {
|
||||
if (moduleType == PneumaticsModuleType::CTREPCM) {
|
||||
|
||||
@@ -84,17 +84,38 @@ bool PneumaticsControlModule::GetCompressor() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
void PneumaticsControlModule::SetClosedLoopControl(bool enabled) {
|
||||
void PneumaticsControlModule::DisableCompressor() {
|
||||
int32_t status = 0;
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, enabled, &status);
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, false, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
bool PneumaticsControlModule::GetClosedLoopControl() const {
|
||||
void PneumaticsControlModule::EnableCompressorDigital() {
|
||||
int32_t status = 0;
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticsControlModule::EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticsControlModule::EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
CompressorConfigType PneumaticsControlModule::GetCompressorConfigType() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetCTREPCMClosedLoopControl(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return result;
|
||||
return result ? CompressorConfigType::Digital
|
||||
: CompressorConfigType::Disabled;
|
||||
}
|
||||
|
||||
bool PneumaticsControlModule::GetPressureSwitch() const {
|
||||
|
||||
@@ -73,21 +73,23 @@ void REVPHSim::SetCompressorOn(bool compressorOn) {
|
||||
HALSIM_SetREVPHCompressorOn(m_index, compressorOn);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> REVPHSim::RegisterClosedLoopEnabledCallback(
|
||||
std::unique_ptr<CallbackStore> REVPHSim::RegisterCompressorConfigTypeCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelREVPHClosedLoopEnabledCallback);
|
||||
store->SetUid(HALSIM_RegisterREVPHClosedLoopEnabledCallback(
|
||||
m_index, -1, callback, &HALSIM_CancelREVPHCompressorConfigTypeCallback);
|
||||
store->SetUid(HALSIM_RegisterREVPHCompressorConfigTypeCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool REVPHSim::GetClosedLoopEnabled() const {
|
||||
return HALSIM_GetREVPHClosedLoopEnabled(m_index);
|
||||
int REVPHSim::GetCompressorConfigType() const {
|
||||
return HALSIM_GetREVPHCompressorConfigType(m_index);
|
||||
}
|
||||
|
||||
void REVPHSim::SetClosedLoopEnabled(bool closedLoopEnabled) {
|
||||
HALSIM_SetREVPHClosedLoopEnabled(m_index, closedLoopEnabled);
|
||||
void REVPHSim::SetCompressorConfigType(int compressorConfigType) {
|
||||
HALSIM_SetREVPHCompressorConfigType(
|
||||
m_index,
|
||||
static_cast<HAL_REVPHCompressorConfigType>(compressorConfigType));
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> REVPHSim::RegisterPressureSwitchCallback(
|
||||
|
||||
Reference in New Issue
Block a user