mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +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(
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
#include <memory>
|
||||
|
||||
#include <hal/Types.h>
|
||||
#include <wpi/deprecated.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
|
||||
#include "frc/CompressorConfigType.h"
|
||||
#include "frc/PneumaticsBase.h"
|
||||
#include "frc/PneumaticsModuleType.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
@@ -59,13 +61,19 @@ class Compressor : public wpi::Sendable,
|
||||
/**
|
||||
* Starts closed-loop control. Note that closed loop control is enabled by
|
||||
* default.
|
||||
*
|
||||
* @deprecated Use EnableDigital() instead.
|
||||
*/
|
||||
WPI_DEPRECATED("Use EnableDigital() instead")
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* Stops closed-loop control. Note that closed loop control is enabled by
|
||||
* default.
|
||||
*
|
||||
* @deprecated Use Disable() instead.
|
||||
*/
|
||||
WPI_DEPRECATED("Use Disable() instead")
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
@@ -87,25 +95,39 @@ class Compressor : public wpi::Sendable,
|
||||
*
|
||||
* @return The current through the compressor, in amps
|
||||
*/
|
||||
double GetCompressorCurrent() const;
|
||||
double GetCurrent() const;
|
||||
|
||||
/**
|
||||
* Enables or disables automatically turning the compressor on when the
|
||||
* pressure is low.
|
||||
*
|
||||
* @param on Set to true to enable closed loop control of the compressor.
|
||||
* False to disable.
|
||||
* Disable the compressor.
|
||||
*/
|
||||
void SetClosedLoopControl(bool on);
|
||||
void Disable();
|
||||
|
||||
/**
|
||||
* Returns true if the compressor will automatically turn on when the
|
||||
* pressure is low.
|
||||
*
|
||||
* @return True if closed loop control of the compressor is enabled. False if
|
||||
* disabled.
|
||||
* Enable compressor closed loop control using digital input.
|
||||
*/
|
||||
bool GetClosedLoopControl() const;
|
||||
void EnableDigital();
|
||||
|
||||
/**
|
||||
* Enable compressor closed loop control using analog input.
|
||||
*
|
||||
* <p>On CTRE PCM, this will enable digital control.
|
||||
*
|
||||
* @param minAnalogVoltage The minimum voltage to enable compressor
|
||||
* @param maxAnalogVoltage The maximum voltage to disable compressor
|
||||
*/
|
||||
void EnableAnalog(double minAnalogVoltage, double maxAnalogVoltage);
|
||||
|
||||
/**
|
||||
* Enable compressor closed loop control using hybrid input.
|
||||
*
|
||||
* On CTRE PCM, this will enable digital control.
|
||||
*
|
||||
* @param minAnalogVoltage The minimum voltage to enable compressor
|
||||
* @param maxAnalogVoltage The maximum voltage to disable compressor
|
||||
*/
|
||||
void EnableHybrid(double minAnalogVoltage, double maxAnalogVoltage);
|
||||
|
||||
CompressorConfigType GetConfigType() const;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
|
||||
15
wpilibc/src/main/native/include/frc/CompressorConfigType.h
Normal file
15
wpilibc/src/main/native/include/frc/CompressorConfigType.h
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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
|
||||
|
||||
namespace frc {
|
||||
enum class CompressorConfigType {
|
||||
Disabled = 0,
|
||||
Digital = 1,
|
||||
Analog = 2,
|
||||
Hybrid = 3
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -22,9 +22,17 @@ class PneumaticHub : public PneumaticsBase {
|
||||
|
||||
bool GetCompressor() const override;
|
||||
|
||||
void SetClosedLoopControl(bool enabled) override;
|
||||
void DisableCompressor() override;
|
||||
|
||||
bool GetClosedLoopControl() const override;
|
||||
void EnableCompressorDigital() override;
|
||||
|
||||
void EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) override;
|
||||
|
||||
void EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) override;
|
||||
|
||||
CompressorConfigType GetCompressorConfigType() const override;
|
||||
|
||||
bool GetPressureSwitch() const override;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <units/time.h>
|
||||
|
||||
#include "frc/CompressorConfigType.h"
|
||||
#include "frc/PneumaticsModuleType.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -24,9 +25,17 @@ class PneumaticsBase {
|
||||
|
||||
virtual double GetCompressorCurrent() const = 0;
|
||||
|
||||
virtual void SetClosedLoopControl(bool on) = 0;
|
||||
virtual void DisableCompressor() = 0;
|
||||
|
||||
virtual bool GetClosedLoopControl() const = 0;
|
||||
virtual void EnableCompressorDigital() = 0;
|
||||
|
||||
virtual void EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) = 0;
|
||||
|
||||
virtual void EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) = 0;
|
||||
|
||||
virtual CompressorConfigType GetCompressorConfigType() const = 0;
|
||||
|
||||
virtual void SetSolenoids(int mask, int values) = 0;
|
||||
|
||||
|
||||
@@ -22,9 +22,17 @@ class PneumaticsControlModule : public PneumaticsBase {
|
||||
|
||||
bool GetCompressor() const override;
|
||||
|
||||
void SetClosedLoopControl(bool enabled) override;
|
||||
void DisableCompressor() override;
|
||||
|
||||
bool GetClosedLoopControl() const override;
|
||||
void EnableCompressorDigital() override;
|
||||
|
||||
void EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) override;
|
||||
|
||||
void EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) override;
|
||||
|
||||
CompressorConfigType GetCompressorConfigType() const override;
|
||||
|
||||
bool GetPressureSwitch() const override;
|
||||
|
||||
|
||||
@@ -119,22 +119,22 @@ class REVPHSim {
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore>
|
||||
RegisterClosedLoopEnabledCallback(NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
RegisterCompressorConfigTypeCallback(NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check whether the closed loop compressor control is active.
|
||||
*
|
||||
* @return true if active
|
||||
* @return compressor config type
|
||||
*/
|
||||
bool GetClosedLoopEnabled() const;
|
||||
int GetCompressorConfigType() const;
|
||||
|
||||
/**
|
||||
* Turn on/off the closed loop control of the compressor.
|
||||
*
|
||||
* @param closedLoopEnabled whether the control loop is active
|
||||
* @param compressorConfigType compressor config type
|
||||
*/
|
||||
void SetClosedLoopEnabled(bool closedLoopEnabled);
|
||||
void SetCompressorConfigType(int compressorConfigType);
|
||||
|
||||
/**
|
||||
* Register a callback to be run whenever the pressure switch value changes.
|
||||
|
||||
Reference in New Issue
Block a user