[hal, wpilib] Incorporate pneumatic control type into wpilibc/j (#3728)

This commit is contained in:
Thad House
2021-11-23 20:32:02 -08:00
committed by GitHub
parent 9aba2b7583
commit b156db400d
35 changed files with 693 additions and 216 deletions

View File

@@ -6,6 +6,11 @@ package edu.wpi.first.hal;
@SuppressWarnings("AbbreviationAsWordInName")
public class REVPHJNI extends JNIWrapper {
public static final int COMPRESSOR_CONFIG_TYPE_DISABLED = 0;
public static final int COMPRESSOR_CONFIG_TYPE_DIGITAL = 1;
public static final int COMPRESSOR_CONFIG_TYPE_ANALOG = 2;
public static final int COMPRESSOR_CONFIG_TYPE_HYBRID = 3;
public static native int initialize(int module);
public static native void free(int handle);
@@ -14,9 +19,24 @@ public class REVPHJNI extends JNIWrapper {
public static native boolean getCompressor(int handle);
public static native void setClosedLoopControl(int handle, boolean enabled);
public static native void setCompressorConfig(
int handle,
double minAnalogVoltage,
double maxAnalogVoltage,
boolean forceDisable,
boolean useDigital);
public static native boolean getClosedLoopControl(int handle);
public static native void setClosedLoopControlDisabled(int handle);
public static native void setClosedLoopControlDigital(int handle);
public static native void setClosedLoopControlAnalog(
int handle, double minAnalogVoltage, double maxAnalogVoltage);
public static native void setClosedLoopControlHybrid(
int handle, double minAnalogVoltage, double maxAnalogVoltage);
public static native int getCompressorConfig(int handle);
public static native boolean getPressureSwitch(int handle);

View File

@@ -35,14 +35,14 @@ public class REVPHDataJNI extends JNIWrapper {
public static native void setCompressorOn(int index, boolean compressorOn);
public static native int registerClosedLoopEnabledCallback(
public static native int registerCompressorConfigTypeCallback(
int index, NotifyCallback callback, boolean initialNotify);
public static native void cancelClosedLoopEnabledCallback(int index, int uid);
public static native void cancelCompressorConfigTypeCallback(int index, int uid);
public static native boolean getClosedLoopEnabled(int index);
public static native int getCompressorConfigType(int index);
public static native void setClosedLoopEnabled(int index, boolean closeLoopEnabled);
public static native void setCompressorConfigType(int index, int configType);
public static native int registerPressureSwitchCallback(
int index, NotifyCallback callback, boolean initialNotify);

View File

@@ -258,18 +258,8 @@ HAL_Bool HAL_GetREVPHCompressor(HAL_REVPHHandle handle, int32_t* status) {
return status0.compressor_on;
}
void HAL_SetREVPHClosedLoopControl(HAL_REVPHHandle handle, HAL_Bool enabled,
int32_t* status) {
// TODO
}
HAL_Bool HAL_GetREVPHClosedLoopControl(HAL_REVPHHandle handle,
int32_t* status) {
return false; // TODO
}
void HAL_SetREVPHCompressorConfig(HAL_REVPHHandle handle,
HAL_REVPHCompressorConfig config,
const HAL_REVPHCompressorConfig* config,
int32_t* status) {
auto ph = REVPHHandles->Get(handle);
if (ph == nullptr) {
@@ -278,10 +268,14 @@ void HAL_SetREVPHCompressorConfig(HAL_REVPHHandle handle,
}
PH_compressor_config_t frameData;
frameData.minimum_tank_pressure = config.minAnalogVoltage;
frameData.maximum_tank_pressure = config.maxAnalogVoltage;
frameData.force_disable = config.forceDisable;
frameData.use_digital = config.useDigital;
frameData.minimum_tank_pressure =
PH_compressor_config_minimum_tank_pressure_encode(
config->minAnalogVoltage);
frameData.maximum_tank_pressure =
PH_compressor_config_maximum_tank_pressure_encode(
config->maxAnalogVoltage);
frameData.force_disable = config->forceDisable;
frameData.use_digital = config->useDigital;
uint8_t packedData[PH_COMPRESSOR_CONFIG_LENGTH] = {0};
PH_compressor_config_pack(packedData, &frameData,
@@ -295,7 +289,7 @@ void HAL_SetREVPHClosedLoopControlDisabled(HAL_REVPHHandle handle,
HAL_REVPHCompressorConfig config = {0, 0, 0, 0};
config.forceDisable = true;
HAL_SetREVPHCompressorConfig(handle, config, status);
HAL_SetREVPHCompressorConfig(handle, &config, status);
}
void HAL_SetREVPHClosedLoopControlDigital(HAL_REVPHHandle handle,
@@ -303,7 +297,7 @@ void HAL_SetREVPHClosedLoopControlDigital(HAL_REVPHHandle handle,
HAL_REVPHCompressorConfig config = {0, 0, 0, 0};
config.useDigital = true;
HAL_SetREVPHCompressorConfig(handle, config, status);
HAL_SetREVPHCompressorConfig(handle, &config, status);
}
void HAL_SetREVPHClosedLoopControlAnalog(HAL_REVPHHandle handle,
@@ -311,12 +305,10 @@ void HAL_SetREVPHClosedLoopControlAnalog(HAL_REVPHHandle handle,
double maxAnalogVoltage,
int32_t* status) {
HAL_REVPHCompressorConfig config = {0, 0, 0, 0};
config.minAnalogVoltage =
PH_compressor_config_minimum_tank_pressure_encode(minAnalogVoltage);
config.maxAnalogVoltage =
PH_compressor_config_maximum_tank_pressure_encode(maxAnalogVoltage);
config.minAnalogVoltage = minAnalogVoltage;
config.maxAnalogVoltage = maxAnalogVoltage;
HAL_SetREVPHCompressorConfig(handle, config, status);
HAL_SetREVPHCompressorConfig(handle, &config, status);
}
void HAL_SetREVPHClosedLoopControlHybrid(HAL_REVPHHandle handle,
@@ -324,13 +316,11 @@ void HAL_SetREVPHClosedLoopControlHybrid(HAL_REVPHHandle handle,
double maxAnalogVoltage,
int32_t* status) {
HAL_REVPHCompressorConfig config = {0, 0, 0, 0};
config.minAnalogVoltage =
PH_compressor_config_minimum_tank_pressure_encode(minAnalogVoltage);
config.maxAnalogVoltage =
PH_compressor_config_maximum_tank_pressure_encode(maxAnalogVoltage);
config.minAnalogVoltage = minAnalogVoltage;
config.maxAnalogVoltage = maxAnalogVoltage;
config.useDigital = true;
HAL_SetREVPHCompressorConfig(handle, config, status);
HAL_SetREVPHCompressorConfig(handle, &config, status);
}
HAL_REVPHCompressorConfigType HAL_GetREVPHCompressorConfig(

View File

@@ -15,7 +15,8 @@ void HALSIM_ResetREVPHData(int32_t index) {}
HAL_SIMDATAVALUE_STUB_CAPI_CHANNEL(HAL_Bool, HALSIM, REVPHSolenoidOutput, false)
DEFINE_CAPI(HAL_Bool, Initialized, false)
DEFINE_CAPI(HAL_Bool, CompressorOn, false)
DEFINE_CAPI(HAL_Bool, ClosedLoopEnabled, false)
DEFINE_CAPI(HAL_REVPHCompressorConfigType, CompressorConfigType,
HAL_REVPHCompressorConfigType_kDisabled)
DEFINE_CAPI(HAL_Bool, PressureSwitch, false)
DEFINE_CAPI(double, CompressorCurrent, 0)

View File

@@ -12,6 +12,19 @@
#include "hal/REVPH.h"
#include "hal/handles/HandlesInternal.h"
static_assert(
edu_wpi_first_hal_REVPHJNI_COMPRESSOR_CONFIG_TYPE_DISABLED ==
HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kDisabled);
static_assert(
edu_wpi_first_hal_REVPHJNI_COMPRESSOR_CONFIG_TYPE_DIGITAL ==
HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kDigital);
static_assert(
edu_wpi_first_hal_REVPHJNI_COMPRESSOR_CONFIG_TYPE_ANALOG ==
HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kAnalog);
static_assert(
edu_wpi_first_hal_REVPHJNI_COMPRESSOR_CONFIG_TYPE_HYBRID ==
HAL_REVPHCompressorConfigType::HAL_REVPHCompressorConfigType_kHybrid);
using namespace hal;
extern "C" {
@@ -73,31 +86,97 @@ Java_edu_wpi_first_hal_REVPHJNI_getCompressor
/*
* Class: edu_wpi_first_hal_REVPHJNI
* Method: setClosedLoopControl
* Signature: (IZ)V
* Method: setCompressorConfig
* Signature: (IDDZZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_REVPHJNI_setClosedLoopControl
(JNIEnv* env, jclass, jint handle, jboolean enabled)
Java_edu_wpi_first_hal_REVPHJNI_setCompressorConfig
(JNIEnv* env, jclass, jint handle, jdouble minAnalogVoltage,
jdouble maxAnalogVoltage, jboolean forceDisable, jboolean useDigital)
{
int32_t status = 0;
HAL_SetREVPHClosedLoopControl(handle, enabled, &status);
HAL_REVPHCompressorConfig config;
config.minAnalogVoltage = minAnalogVoltage;
config.maxAnalogVoltage = maxAnalogVoltage;
config.useDigital = useDigital;
config.forceDisable = forceDisable;
HAL_SetREVPHCompressorConfig(handle, &config, &status);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_hal_REVPHJNI
* Method: getClosedLoopControl
* Signature: (I)Z
* Method: setClosedLoopControlDisabled
* Signature: (I)V
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_REVPHJNI_getClosedLoopControl
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_REVPHJNI_setClosedLoopControlDisabled
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto result = HAL_GetREVPHClosedLoopControl(handle, &status);
HAL_SetREVPHClosedLoopControlDisabled(handle, &status);
CheckStatus(env, status, false);
return result;
}
/*
* Class: edu_wpi_first_hal_REVPHJNI
* Method: setClosedLoopControlDigital
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_REVPHJNI_setClosedLoopControlDigital
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
HAL_SetREVPHClosedLoopControlDigital(handle, &status);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_hal_REVPHJNI
* Method: setClosedLoopControlAnalog
* Signature: (IDD)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_REVPHJNI_setClosedLoopControlAnalog
(JNIEnv* env, jclass, jint handle, jdouble minAnalogVoltage,
jdouble maxAnalogVoltage)
{
int32_t status = 0;
HAL_SetREVPHClosedLoopControlAnalog(handle, minAnalogVoltage,
maxAnalogVoltage, &status);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_hal_REVPHJNI
* Method: setClosedLoopControlHybrid
* Signature: (IDD)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_REVPHJNI_setClosedLoopControlHybrid
(JNIEnv* env, jclass, jint handle, jdouble minAnalogVoltage,
jdouble maxAnalogVoltage)
{
int32_t status = 0;
HAL_SetREVPHClosedLoopControlHybrid(handle, minAnalogVoltage,
maxAnalogVoltage, &status);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_hal_REVPHJNI
* Method: getCompressorConfig
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_REVPHJNI_getCompressorConfig
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto config = HAL_GetREVPHCompressorConfig(handle, &status);
CheckStatus(env, status, false);
return static_cast<jint>(config);
}
/*

View File

@@ -166,52 +166,54 @@ Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setCompressorOn
/*
* Class: edu_wpi_first_hal_simulation_REVPHDataJNI
* Method: registerClosedLoopEnabledCallback
* Method: registerCompressorConfigTypeCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerClosedLoopEnabledCallback
Java_edu_wpi_first_hal_simulation_REVPHDataJNI_registerCompressorConfigTypeCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterREVPHClosedLoopEnabledCallback);
return sim::AllocateCallback(
env, index, callback, initialNotify,
&HALSIM_RegisterREVPHCompressorConfigTypeCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_REVPHDataJNI
* Method: cancelClosedLoopEnabledCallback
* Method: cancelCompressorConfigTypeCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_REVPHDataJNI_cancelClosedLoopEnabledCallback
Java_edu_wpi_first_hal_simulation_REVPHDataJNI_cancelCompressorConfigTypeCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelREVPHClosedLoopEnabledCallback);
&HALSIM_CancelREVPHCompressorConfigTypeCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_REVPHDataJNI
* Method: getClosedLoopEnabled
* Signature: (I)Z
* Method: getCompressorConfigType
* Signature: (I)I
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_simulation_REVPHDataJNI_getClosedLoopEnabled
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_REVPHDataJNI_getCompressorConfigType
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetREVPHClosedLoopEnabled(index);
return static_cast<jint>(HALSIM_GetREVPHCompressorConfigType(index));
}
/*
* Class: edu_wpi_first_hal_simulation_REVPHDataJNI
* Method: setClosedLoopEnabled
* Signature: (IZ)V
* Method: setCompressorConfigType
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setClosedLoopEnabled
(JNIEnv*, jclass, jint index, jboolean value)
Java_edu_wpi_first_hal_simulation_REVPHDataJNI_setCompressorConfigType
(JNIEnv*, jclass, jint index, jint value)
{
HALSIM_SetREVPHClosedLoopEnabled(index, value);
HALSIM_SetREVPHCompressorConfigType(
index, static_cast<HAL_REVPHCompressorConfigType>(value));
}
/*

View File

@@ -89,11 +89,8 @@ HAL_Bool HAL_CheckREVPHSolenoidChannel(int32_t channel);
HAL_Bool HAL_CheckREVPHModuleNumber(int32_t module);
HAL_Bool HAL_GetREVPHCompressor(HAL_REVPHHandle handle, int32_t* status);
void HAL_SetREVPHClosedLoopControl(HAL_REVPHHandle handle, HAL_Bool enabled,
int32_t* status);
HAL_Bool HAL_GetREVPHClosedLoopControl(HAL_REVPHHandle handle, int32_t* status);
void HAL_SetREVPHCompressorConfig(HAL_REVPHHandle handle,
HAL_REVPHCompressorConfig config,
const HAL_REVPHCompressorConfig* config,
int32_t* status);
void HAL_SetREVPHClosedLoopControlDisabled(HAL_REVPHHandle handle,
int32_t* status);

View File

@@ -4,6 +4,7 @@
#pragma once
#include "hal/REVPH.h"
#include "hal/Types.h"
#include "hal/simulation/NotifyListener.h"
@@ -39,13 +40,14 @@ void HALSIM_CancelREVPHCompressorOnCallback(int32_t index, int32_t uid);
HAL_Bool HALSIM_GetREVPHCompressorOn(int32_t index);
void HALSIM_SetREVPHCompressorOn(int32_t index, HAL_Bool compressorOn);
int32_t HALSIM_RegisterREVPHClosedLoopEnabledCallback(
int32_t HALSIM_RegisterREVPHCompressorConfigTypeCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void HALSIM_CancelREVPHClosedLoopEnabledCallback(int32_t index, int32_t uid);
HAL_Bool HALSIM_GetREVPHClosedLoopEnabled(int32_t index);
void HALSIM_SetREVPHClosedLoopEnabled(int32_t index,
HAL_Bool closedLoopEnabled);
void HALSIM_CancelREVPHCompressorConfigTypeCallback(int32_t index, int32_t uid);
HAL_REVPHCompressorConfigType HALSIM_GetREVPHCompressorConfigType(
int32_t index);
void HALSIM_SetREVPHCompressorConfigType(
int32_t index, HAL_REVPHCompressorConfigType configType);
int32_t HALSIM_RegisterREVPHPressureSwitchCallback(int32_t index,
HAL_NotifyCallback callback,

View File

@@ -64,7 +64,8 @@ HAL_REVPHHandle HAL_InitializeREVPH(int32_t module,
SimREVPHData[module].initialized = true;
// Enable closed loop
SimREVPHData[module].closedLoopEnabled = true;
SimREVPHData[module].compressorConfigType =
HAL_REVPHCompressorConfigType_kDigital;
return handle;
}
@@ -97,26 +98,73 @@ HAL_Bool HAL_GetREVPHCompressor(HAL_REVPHHandle handle, int32_t* status) {
return SimREVPHData[pcm->module].compressorOn;
}
void HAL_SetREVPHClosedLoopControl(HAL_REVPHHandle handle, HAL_Bool enabled,
int32_t* status) {
void HAL_SetREVPHCompressorConfig(HAL_REVPHHandle handle,
const HAL_REVPHCompressorConfig* config,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimREVPHData[pcm->module].closedLoopEnabled = enabled;
// TODO
// SimREVPHData[pcm->module].compressorConfigType = config.
}
HAL_Bool HAL_GetREVPHClosedLoopControl(HAL_REVPHHandle handle,
int32_t* status) {
void HAL_SetREVPHClosedLoopControlDisabled(HAL_REVPHHandle handle,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return false;
return;
}
SimREVPHData[pcm->module].compressorConfigType =
HAL_REVPHCompressorConfigType_kDisabled;
}
return SimREVPHData[pcm->module].closedLoopEnabled;
void HAL_SetREVPHClosedLoopControlDigital(HAL_REVPHHandle handle,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimREVPHData[pcm->module].compressorConfigType =
HAL_REVPHCompressorConfigType_kDigital;
}
void HAL_SetREVPHClosedLoopControlAnalog(HAL_REVPHHandle handle,
double minAnalogVoltage,
double maxAnalogVoltage,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimREVPHData[pcm->module].compressorConfigType =
HAL_REVPHCompressorConfigType_kAnalog;
}
void HAL_SetREVPHClosedLoopControlHybrid(HAL_REVPHHandle handle,
double minAnalogVoltage,
double maxAnalogVoltage,
int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
SimREVPHData[pcm->module].compressorConfigType =
HAL_REVPHCompressorConfigType_kHybrid;
}
HAL_REVPHCompressorConfigType HAL_GetREVPHCompressorConfig(
HAL_REVPHHandle handle, int32_t* status) {
auto pcm = pcmHandles->Get(handle);
if (pcm == nullptr) {
*status = HAL_HANDLE_ERROR;
return HAL_REVPHCompressorConfigType_kDisabled;
}
return SimREVPHData[pcm->module].compressorConfigType;
}
HAL_Bool HAL_GetREVPHPressureSwitch(HAL_REVPHHandle handle, int32_t* status) {

View File

@@ -21,7 +21,7 @@ void REVPHData::ResetData() {
}
initialized.Reset(false);
compressorOn.Reset(false);
closedLoopEnabled.Reset(true);
compressorConfigType.Reset(HAL_REVPHCompressorConfigType_kDisabled);
pressureSwitch.Reset(false);
compressorCurrent.Reset(0.0);
}
@@ -39,7 +39,8 @@ HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(HAL_Bool, HALSIM, REVPHSolenoidOutput,
SimREVPHData, solenoidOutput)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(HAL_Bool, CompressorOn, compressorOn)
DEFINE_CAPI(HAL_Bool, ClosedLoopEnabled, closedLoopEnabled)
DEFINE_CAPI(HAL_REVPHCompressorConfigType, CompressorConfigType,
compressorConfigType)
DEFINE_CAPI(HAL_Bool, PressureSwitch, pressureSwitch)
DEFINE_CAPI(double, CompressorCurrent, compressorCurrent)
@@ -69,7 +70,7 @@ void HALSIM_RegisterREVPHAllNonSolenoidCallbacks(int32_t index,
HAL_Bool initialNotify) {
REGISTER(initialized);
REGISTER(compressorOn);
REGISTER(closedLoopEnabled);
REGISTER(compressorConfigType);
REGISTER(pressureSwitch);
REGISTER(compressorCurrent);
}

View File

@@ -13,7 +13,7 @@ class REVPHData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(SolenoidOutput)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorOn)
HAL_SIMDATAVALUE_DEFINE_NAME(ClosedLoopEnabled)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorConfigType)
HAL_SIMDATAVALUE_DEFINE_NAME(PressureSwitch)
HAL_SIMDATAVALUE_DEFINE_NAME(CompressorCurrent)
@@ -22,6 +22,11 @@ class REVPHData {
return false;
}
static inline HAL_Value MakeCompressorConfigTypeValue(
HAL_REVPHCompressorConfigType value) {
return HAL_MakeEnum(value);
}
public:
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetInitializedName> initialized{
false};
@@ -30,8 +35,10 @@ class REVPHData {
solenoidOutput[kNumREVPHChannels];
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetCompressorOnName> compressorOn{
false};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetClosedLoopEnabledName>
closedLoopEnabled{true};
SimDataValue<HAL_REVPHCompressorConfigType, MakeCompressorConfigTypeValue,
GetCompressorConfigTypeName>
compressorConfigType{HAL_REVPHCompressorConfigType::
HAL_REVPHCompressorConfigType_kDisabled};
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetPressureSwitchName> pressureSwitch{
false};
SimDataValue<double, HAL_MakeDouble, GetCompressorCurrentName>

View File

@@ -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(

View File

@@ -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 {

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -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(

View File

@@ -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;

View 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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.

View File

@@ -96,7 +96,7 @@ TEST(CTREPCMSimTest, SetCompressorOn) {
EXPECT_TRUE(callback.GetLastValue());
}
TEST(CTREPCMSimTest, SetClosedLoopEnabled) {
TEST(CTREPCMSimTest, SetEnableDigital) {
PneumaticsControlModule pcm;
CTREPCMSim sim(pcm);
sim.ResetData();
@@ -105,12 +105,12 @@ TEST(CTREPCMSimTest, SetClosedLoopEnabled) {
auto cb =
sim.RegisterClosedLoopEnabledCallback(callback.GetCallback(), false);
pcm.SetClosedLoopControl(false);
EXPECT_FALSE(pcm.GetClosedLoopControl());
pcm.DisableCompressor();
EXPECT_EQ(pcm.GetCompressorConfigType(), CompressorConfigType::Disabled);
pcm.SetClosedLoopControl(true);
pcm.EnableCompressorDigital();
EXPECT_TRUE(sim.GetClosedLoopEnabled());
EXPECT_TRUE(pcm.GetClosedLoopControl());
EXPECT_EQ(pcm.GetCompressorConfigType(), CompressorConfigType::Digital);
EXPECT_TRUE(callback.WasTriggered());
EXPECT_TRUE(callback.GetLastValue());
}

View File

@@ -96,23 +96,67 @@ TEST(REVPHSimTest, SetCompressorOn) {
EXPECT_TRUE(callback.GetLastValue());
}
TEST(REVPHSimTest, SetClosedLoopEnabled) {
TEST(REVPHSimTest, SetEnableDigital) {
PneumaticHub ph;
REVPHSim sim(ph);
sim.ResetData();
BooleanCallback callback;
EnumCallback callback;
auto cb =
sim.RegisterClosedLoopEnabledCallback(callback.GetCallback(), false);
sim.RegisterCompressorConfigTypeCallback(callback.GetCallback(), false);
ph.SetClosedLoopControl(false);
EXPECT_FALSE(ph.GetClosedLoopControl());
ph.DisableCompressor();
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Disabled);
ph.SetClosedLoopControl(true);
EXPECT_TRUE(sim.GetClosedLoopEnabled());
EXPECT_TRUE(ph.GetClosedLoopControl());
ph.EnableCompressorDigital();
EXPECT_EQ(sim.GetCompressorConfigType(),
static_cast<int>(CompressorConfigType::Digital));
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Digital);
EXPECT_TRUE(callback.WasTriggered());
EXPECT_TRUE(callback.GetLastValue());
EXPECT_EQ(callback.GetLastValue(),
static_cast<int>(CompressorConfigType::Digital));
}
TEST(REVPHSimTest, SetEnableAnalog) {
PneumaticHub ph;
REVPHSim sim(ph);
sim.ResetData();
EnumCallback callback;
auto cb =
sim.RegisterCompressorConfigTypeCallback(callback.GetCallback(), false);
ph.DisableCompressor();
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Disabled);
ph.EnableCompressorAnalog(1, 2);
EXPECT_EQ(sim.GetCompressorConfigType(),
static_cast<int>(CompressorConfigType::Analog));
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Analog);
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(callback.GetLastValue(),
static_cast<int>(CompressorConfigType::Analog));
}
TEST(REVPHSimTest, SetEnableHybrid) {
PneumaticHub ph;
REVPHSim sim(ph);
sim.ResetData();
EnumCallback callback;
auto cb =
sim.RegisterCompressorConfigTypeCallback(callback.GetCallback(), false);
ph.DisableCompressor();
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Disabled);
ph.EnableCompressorHybrid(1, 2);
EXPECT_EQ(sim.GetCompressorConfigType(),
static_cast<int>(CompressorConfigType::Hybrid));
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Hybrid);
EXPECT_TRUE(callback.WasTriggered());
EXPECT_EQ(callback.GetLastValue(),
static_cast<int>(CompressorConfigType::Hybrid));
}
TEST(REVPHSimTest, SetPressureSwitchEnabled) {

View File

@@ -35,7 +35,7 @@ class PCMTest : public testing::Test {
frc::DigitalInput m_fakeSolenoid2{TestBench::kFakeSolenoid2Channel};
void Reset() {
m_pneumaticsModule.SetClosedLoopControl(false);
m_pneumaticsModule.DisableCompressor();
m_fakePressureSwitch.Set(false);
}
};
@@ -46,7 +46,7 @@ class PCMTest : public testing::Test {
TEST_F(PCMTest, PressureSwitch) {
Reset();
m_pneumaticsModule.SetClosedLoopControl(true);
m_pneumaticsModule.EnableCompressorDigital();
// Turn on the compressor
m_fakePressureSwitch.Set(true);

View File

@@ -43,7 +43,7 @@ public class Compressor implements Sendable, AutoCloseable {
allocatedCompressor = true;
m_module.setClosedLoopControl(true);
m_module.enableCompressorDigital();
HAL.report(tResourceType.kResourceType_Compressor, module + 1);
SendableRegistry.addLW(this, "Compressor", module);
@@ -82,9 +82,12 @@ public class Compressor implements Sendable, AutoCloseable {
* <p>Use the method in cases where you would like to manually stop and start the compressor for
* applications such as conserving battery or making sure that the compressor motor doesn't start
* during critical operations.
*
* @deprecated Use enableDigital() instead.
*/
@Deprecated(since = "2022", forRemoval = true)
public void start() {
setClosedLoopControl(true);
enableDigital();
}
/**
@@ -93,9 +96,12 @@ public class Compressor implements Sendable, AutoCloseable {
* <p>Use the method in cases where you would like to manually stop and start the compressor for
* applications such as conserving battery or making sure that the compressor motor doesn't start
* during critical operations.
*
* @deprecated Use disable() instead.
*/
@Deprecated(since = "2022", forRemoval = true)
public void stop() {
setClosedLoopControl(false);
disable();
}
/**
@@ -121,33 +127,56 @@ public class Compressor implements Sendable, AutoCloseable {
*
* @return current consumed by the compressor in amps
*/
public double getCompressorCurrent() {
public double getCurrent() {
return m_module.getCompressorCurrent();
}
/**
* Set the PCM in closed loop control mode.
*
* @param on if true sets the compressor to be in closed loop control mode (default)
*/
public void setClosedLoopControl(boolean on) {
m_module.setClosedLoopControl(on);
/** Disable the compressor. */
public void disable() {
m_module.disableCompressor();
}
/** Enable compressor closed loop control using digital input. */
public void enableDigital() {
m_module.enableCompressorDigital();
}
/**
* Gets the current operating mode of the PCM.
* 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
*/
public void enableAnalog(double minAnalogVoltage, double maxAnalogVoltage) {
m_module.enableCompressorAnalog(minAnalogVoltage, maxAnalogVoltage);
}
/**
* Enable compressor closed loop control using hybrid 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
*/
public void enableHybrid(double minAnalogVoltage, double maxAnalogVoltage) {
m_module.enableCompressorHybrid(minAnalogVoltage, maxAnalogVoltage);
}
/**
* Gets the current operating mode of the Compressor.
*
* @return true if compressor is operating on closed-loop mode
*/
public boolean getClosedLoopControl() {
return m_module.getClosedLoopControl();
public CompressorConfigType getConfigType() {
return m_module.getCompressorConfigType();
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Compressor");
builder.addBooleanProperty(
"Closed Loop Control", this::getClosedLoopControl, this::setClosedLoopControl);
builder.addBooleanProperty("Enabled", this::enabled, null);
builder.addBooleanProperty("Pressure switch", this::getPressureSwitchValue, null);
}

View File

@@ -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.
package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.REVPHJNI;
public enum CompressorConfigType {
Disabled(REVPHJNI.COMPRESSOR_CONFIG_TYPE_DISABLED),
Digital(REVPHJNI.COMPRESSOR_CONFIG_TYPE_DIGITAL),
Analog(REVPHJNI.COMPRESSOR_CONFIG_TYPE_ANALOG),
Hybrid(REVPHJNI.COMPRESSOR_CONFIG_TYPE_HYBRID);
public final int value;
CompressorConfigType(int value) {
this.value = value;
}
/**
* Gets a type from an int value.
*
* @param value int value
* @return type
*/
public static CompressorConfigType fromValue(int value) {
switch (value) {
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_HYBRID:
return Hybrid;
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_ANALOG:
return Analog;
case REVPHJNI.COMPRESSOR_CONFIG_TYPE_DIGITAL:
return Digital;
default:
return Disabled;
}
}
public int getValue() {
return value;
}
}

View File

@@ -92,13 +92,8 @@ public class PneumaticHub implements PneumaticsBase {
}
@Override
public void setClosedLoopControl(boolean enabled) {
REVPHJNI.setClosedLoopControl(m_handle, enabled);
}
@Override
public boolean getClosedLoopControl() {
return REVPHJNI.getClosedLoopControl(m_handle);
public CompressorConfigType getCompressorConfigType() {
return CompressorConfigType.fromValue(REVPHJNI.getCompressorConfig(m_handle));
}
@Override
@@ -200,4 +195,24 @@ public class PneumaticHub implements PneumaticsBase {
// TODO Get this working
return 0;
}
@Override
public void disableCompressor() {
REVPHJNI.setClosedLoopControlDisabled(m_handle);
}
@Override
public void enableCompressorDigital() {
REVPHJNI.setClosedLoopControlDigital(m_handle);
}
@Override
public void enableCompressorAnalog(double minAnalogVoltage, double maxAnalogVoltage) {
REVPHJNI.setClosedLoopControlAnalog(m_handle, minAnalogVoltage, maxAnalogVoltage);
}
@Override
public void enableCompressorHybrid(double minAnalogVoltage, double maxAnalogVoltage) {
REVPHJNI.setClosedLoopControlHybrid(m_handle, minAnalogVoltage, maxAnalogVoltage);
}
}

View File

@@ -86,9 +86,15 @@ public interface PneumaticsBase extends AutoCloseable {
double getCompressorCurrent();
void setClosedLoopControl(boolean on);
void disableCompressor();
boolean getClosedLoopControl();
void enableCompressorDigital();
void enableCompressorAnalog(double minAnalogVoltage, double maxAnalogVoltage);
void enableCompressorHybrid(double minAnalogVoltage, double maxAnalogVoltage);
CompressorConfigType getCompressorConfigType();
/**
* Check if a solenoid channel is valid.

View File

@@ -91,16 +91,6 @@ public class PneumaticsControlModule implements PneumaticsBase {
return CTREPCMJNI.getCompressor(m_handle);
}
@Override
public void setClosedLoopControl(boolean enabled) {
CTREPCMJNI.setClosedLoopControl(m_handle, enabled);
}
@Override
public boolean getClosedLoopControl() {
return CTREPCMJNI.getClosedLoopControl(m_handle);
}
@Override
public boolean getPressureSwitch() {
return CTREPCMJNI.getPressureSwitch(m_handle);
@@ -233,4 +223,31 @@ public class PneumaticsControlModule implements PneumaticsBase {
m_dataStore.m_compressorReserved = false;
}
}
@Override
public void disableCompressor() {
CTREPCMJNI.setClosedLoopControl(m_handle, false);
}
@Override
public void enableCompressorDigital() {
CTREPCMJNI.setClosedLoopControl(m_handle, true);
}
@Override
public void enableCompressorAnalog(double minAnalogVoltage, double maxAnalogVoltage) {
CTREPCMJNI.setClosedLoopControl(m_handle, false);
}
@Override
public void enableCompressorHybrid(double minAnalogVoltage, double maxAnalogVoltage) {
CTREPCMJNI.setClosedLoopControl(m_handle, false);
}
@Override
public CompressorConfigType getCompressorConfigType() {
return CTREPCMJNI.getClosedLoopControl(m_handle)
? CompressorConfigType.Digital
: CompressorConfigType.Disabled;
}
}

View File

@@ -144,28 +144,28 @@ public class REVPHSim {
* @return the {@link CallbackStore} object associated with this callback. Save a reference to
* this object so GC doesn't cancel the callback.
*/
public CallbackStore registerClosedLoopEnabledCallback(
public CallbackStore registerCompressorConfigTypeCallback(
NotifyCallback callback, boolean initialNotify) {
int uid = REVPHDataJNI.registerClosedLoopEnabledCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelClosedLoopEnabledCallback);
int uid = REVPHDataJNI.registerCompressorConfigTypeCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, REVPHDataJNI::cancelCompressorConfigTypeCallback);
}
/**
* Check whether the closed loop compressor control is active.
*
* @return true if active
* @return config type
*/
public boolean getClosedLoopEnabled() {
return REVPHDataJNI.getClosedLoopEnabled(m_index);
public int getCompressorConfigType() {
return REVPHDataJNI.getCompressorConfigType(m_index);
}
/**
* Turn on/off the closed loop control of the compressor.
*
* @param closedLoopEnabled whether the control loop is active
* @param compressorConfigType compressor config type
*/
public void setClosedLoopEnabled(boolean closedLoopEnabled) {
REVPHDataJNI.setClosedLoopEnabled(m_index, closedLoopEnabled);
public void setCompressorConfigType(int compressorConfigType) {
REVPHDataJNI.setCompressorConfigType(m_index, compressorConfigType);
}
/**

View File

@@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.CompressorConfigType;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticsControlModule;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
@@ -109,7 +110,7 @@ class CTREPCMSimTest {
}
@Test
void setClosedLoopEnabled() {
void setEnableDigital() {
HAL.initialize(500, 0);
CTREPCMSim sim = new CTREPCMSim(0);
@@ -117,12 +118,12 @@ class CTREPCMSimTest {
try (PneumaticsControlModule pcm = new PneumaticsControlModule(0);
CallbackStore cb = sim.registerClosedLoopEnabledCallback(callback, false)) {
pcm.setClosedLoopControl(false);
assertFalse(pcm.getClosedLoopControl());
pcm.disableCompressor();
assertEquals(pcm.getCompressorConfigType(), CompressorConfigType.Disabled);
pcm.setClosedLoopControl(true);
pcm.enableCompressorDigital();
assertTrue(sim.getClosedLoopEnabled());
assertTrue(pcm.getClosedLoopControl());
assertEquals(pcm.getCompressorConfigType(), CompressorConfigType.Digital);
assertTrue(callback.wasTriggered());
assertTrue(callback.getSetValue());
}

View File

@@ -10,11 +10,13 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.CompressorConfigType;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticHub;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
import edu.wpi.first.wpilibj.simulation.testutils.BooleanCallback;
import edu.wpi.first.wpilibj.simulation.testutils.DoubleCallback;
import edu.wpi.first.wpilibj.simulation.testutils.EnumCallback;
import org.junit.jupiter.api.Test;
@SuppressWarnings("AbbreviationAsWordInName")
@@ -109,22 +111,62 @@ class REVPHSimTest {
}
@Test
void setClosedLoopEnabled() {
void setEnableDigital() {
HAL.initialize(500, 0);
REVPHSim sim = new REVPHSim(1);
BooleanCallback callback = new BooleanCallback();
EnumCallback callback = new EnumCallback();
try (PneumaticHub ph = new PneumaticHub(1);
CallbackStore cb = sim.registerClosedLoopEnabledCallback(callback, false)) {
ph.setClosedLoopControl(false);
assertFalse(ph.getClosedLoopControl());
CallbackStore cb = sim.registerCompressorConfigTypeCallback(callback, false)) {
ph.disableCompressor();
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Disabled);
ph.setClosedLoopControl(true);
assertTrue(sim.getClosedLoopEnabled());
assertTrue(ph.getClosedLoopControl());
ph.enableCompressorDigital();
assertEquals(sim.getCompressorConfigType(), CompressorConfigType.Digital.getValue());
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Digital);
assertTrue(callback.wasTriggered());
assertTrue(callback.getSetValue());
assertEquals(callback.getSetValue(), CompressorConfigType.Digital.getValue());
}
}
@Test
void setEnableAnalog() {
HAL.initialize(500, 0);
REVPHSim sim = new REVPHSim(1);
EnumCallback callback = new EnumCallback();
try (PneumaticHub ph = new PneumaticHub(1);
CallbackStore cb = sim.registerCompressorConfigTypeCallback(callback, false)) {
ph.disableCompressor();
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Disabled);
ph.enableCompressorAnalog(1, 2);
assertEquals(sim.getCompressorConfigType(), CompressorConfigType.Analog.getValue());
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Analog);
assertTrue(callback.wasTriggered());
assertEquals(callback.getSetValue(), CompressorConfigType.Analog.getValue());
}
}
@Test
void setEnableHybrid() {
HAL.initialize(500, 0);
REVPHSim sim = new REVPHSim(1);
EnumCallback callback = new EnumCallback();
try (PneumaticHub ph = new PneumaticHub(1);
CallbackStore cb = sim.registerCompressorConfigTypeCallback(callback, false)) {
ph.disableCompressor();
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Disabled);
ph.enableCompressorHybrid(1, 2);
assertEquals(sim.getCompressorConfigType(), CompressorConfigType.Hybrid.getValue());
assertEquals(ph.getCompressorConfigType(), CompressorConfigType.Hybrid);
assertTrue(callback.wasTriggered());
assertEquals(callback.getSetValue(), CompressorConfigType.Hybrid.getValue());
}
}

View File

@@ -64,7 +64,7 @@ public class PCMTest extends AbstractComsSetup {
@Before
public void reset() {
pcm.setClosedLoopControl(false);
pcm.disableCompressor();
fakePressureSwitch.set(false);
}
@@ -73,7 +73,7 @@ public class PCMTest extends AbstractComsSetup {
public void testPressureSwitch() throws Exception {
final double range = 0.5;
reset();
pcm.setClosedLoopControl(true);
pcm.enableCompressorDigital();
// Turn on the compressor
fakePressureSwitch.set(true);

View File

@@ -4,7 +4,7 @@
#pragma once
#include <limits.h> // NOLINT
#include <climits> // NOLINT
#ifdef __cplusplus
#include <initializer_list>