[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

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