mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpilib, hal] High Level REV PH changes (#3792)
More functionality was implemented at the HAL level, so expose that to the wpilib level. This also does units changes for all the PH related functionality.
This commit is contained in:
104
hal/src/main/java/edu/wpi/first/hal/REVPHFaults.java
Normal file
104
hal/src/main/java/edu/wpi/first/hal/REVPHFaults.java
Normal file
@@ -0,0 +1,104 @@
|
||||
// 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.hal;
|
||||
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public class REVPHFaults {
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel0Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel1Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel2Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel3Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel4Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel5Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel6Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel7Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel8Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel9Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel10Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel11Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel12Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel13Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel14Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Channel15Fault;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean CompressorOverCurrent;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean CompressorOpen;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean SolenoidOverCurrent;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Brownout;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean CanWarning;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean HardwareFault;
|
||||
|
||||
/**
|
||||
* Called from HAL to construct.
|
||||
*
|
||||
* @param faults the fault bitfields
|
||||
*/
|
||||
public REVPHFaults(int faults) {
|
||||
Channel0Fault = (faults & 0x1) != 0;
|
||||
Channel1Fault = (faults & 0x2) != 0;
|
||||
Channel2Fault = (faults & 0x4) != 0;
|
||||
Channel3Fault = (faults & 0x8) != 0;
|
||||
Channel4Fault = (faults & 0x10) != 0;
|
||||
Channel5Fault = (faults & 0x20) != 0;
|
||||
Channel6Fault = (faults & 0x40) != 0;
|
||||
Channel7Fault = (faults & 0x80) != 0;
|
||||
Channel8Fault = (faults & 0x100) != 0;
|
||||
Channel9Fault = (faults & 0x200) != 0;
|
||||
Channel10Fault = (faults & 0x400) != 0;
|
||||
Channel11Fault = (faults & 0x800) != 0;
|
||||
Channel12Fault = (faults & 0x1000) != 0;
|
||||
Channel13Fault = (faults & 0x2000) != 0;
|
||||
Channel14Fault = (faults & 0x4000) != 0;
|
||||
Channel15Fault = (faults & 0x8000) != 0;
|
||||
CompressorOverCurrent = (faults & 0x8000) != 0;
|
||||
CompressorOpen = (faults & 0x10000) != 0;
|
||||
SolenoidOverCurrent = (faults & 0x20000) != 0;
|
||||
Brownout = (faults & 0x40000) != 0;
|
||||
CanWarning = (faults & 0x80000) != 0;
|
||||
HardwareFault = (faults & 0x100000) != 0;
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class REVPHJNI extends JNIWrapper {
|
||||
|
||||
public static native boolean getPressureSwitch(int handle);
|
||||
|
||||
public static native double getAnalogPressure(int handle, int channel);
|
||||
public static native double getAnalogVoltage(int handle, int channel);
|
||||
|
||||
public static native double getCompressorCurrent(int handle);
|
||||
|
||||
@@ -49,4 +49,28 @@ public class REVPHJNI extends JNIWrapper {
|
||||
public static native void setSolenoids(int handle, int mask, int values);
|
||||
|
||||
public static native void fireOneShot(int handle, int index, int durMs);
|
||||
|
||||
public static native void clearStickyFaults(int handle);
|
||||
|
||||
public static native double getInputVoltage(int handle);
|
||||
|
||||
public static native double get5VVoltage(int handle);
|
||||
|
||||
public static native double getSolenoidCurrent(int handle);
|
||||
|
||||
public static native double getSolenoidVoltage(int handle);
|
||||
|
||||
public static native int getStickyFaultsNative(int handle);
|
||||
|
||||
public static REVPHStickyFaults getStickyFaults(int handle) {
|
||||
return new REVPHStickyFaults(getStickyFaultsNative(handle));
|
||||
}
|
||||
|
||||
public static native int getFaultsNative(int handle);
|
||||
|
||||
public static REVPHFaults getFaults(int handle) {
|
||||
return new REVPHFaults(getFaultsNative(handle));
|
||||
}
|
||||
|
||||
public static native REVPHVersion getVersion(int handle);
|
||||
}
|
||||
|
||||
44
hal/src/main/java/edu/wpi/first/hal/REVPHStickyFaults.java
Normal file
44
hal/src/main/java/edu/wpi/first/hal/REVPHStickyFaults.java
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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.hal;
|
||||
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public class REVPHStickyFaults {
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean CompressorOverCurrent;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean CompressorOpen;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean SolenoidOverCurrent;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean Brownout;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean CanWarning;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean CanBusOff;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final boolean HasReset;
|
||||
|
||||
/**
|
||||
* Called from HAL.
|
||||
*
|
||||
* @param faults sticky fault bit mask
|
||||
*/
|
||||
public REVPHStickyFaults(int faults) {
|
||||
CompressorOverCurrent = (faults & 0x1) != 0;
|
||||
CompressorOpen = (faults & 0x2) != 0;
|
||||
SolenoidOverCurrent = (faults & 0x4) != 0;
|
||||
Brownout = (faults & 0x8) != 0;
|
||||
CanWarning = (faults & 0x10) != 0;
|
||||
CanBusOff = (faults & 0x20) != 0;
|
||||
HasReset = (faults & 0x40) != 0;
|
||||
}
|
||||
}
|
||||
51
hal/src/main/java/edu/wpi/first/hal/REVPHVersion.java
Normal file
51
hal/src/main/java/edu/wpi/first/hal/REVPHVersion.java
Normal file
@@ -0,0 +1,51 @@
|
||||
// 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.hal;
|
||||
|
||||
@SuppressWarnings("AbbreviationAsWordInName")
|
||||
public class REVPHVersion {
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int firmwareMajor;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int firmwareMinor;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int firmwareFix;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int hardwareMinor;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int hardwareMajor;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public final int uniqueId;
|
||||
|
||||
/**
|
||||
* Constructs a revph version (Called from the HAL).
|
||||
*
|
||||
* @param firmwareMajor firmware major
|
||||
* @param firmwareMinor firmware minor
|
||||
* @param firmwareFix firmware fix
|
||||
* @param hardwareMinor hardware minor
|
||||
* @param hardwareMajor hardware major
|
||||
* @param uniqueId unique id
|
||||
*/
|
||||
public REVPHVersion(
|
||||
int firmwareMajor,
|
||||
int firmwareMinor,
|
||||
int firmwareFix,
|
||||
int hardwareMinor,
|
||||
int hardwareMajor,
|
||||
int uniqueId) {
|
||||
this.firmwareMajor = firmwareMajor;
|
||||
this.firmwareMinor = firmwareMinor;
|
||||
this.firmwareFix = firmwareFix;
|
||||
this.hardwareMinor = hardwareMinor;
|
||||
this.hardwareMajor = hardwareMajor;
|
||||
this.uniqueId = uniqueId;
|
||||
}
|
||||
}
|
||||
@@ -376,8 +376,8 @@ double HAL_GetREVPHCompressorCurrent(HAL_REVPHHandle handle, int32_t* status) {
|
||||
return PH_status_1_compressor_current_decode(status1.compressor_current);
|
||||
}
|
||||
|
||||
double HAL_GetREVPHAnalogPressure(HAL_REVPHHandle handle, int32_t channel,
|
||||
int32_t* status) {
|
||||
double HAL_GetREVPHAnalogVoltage(HAL_REVPHHandle handle, int32_t channel,
|
||||
int32_t* status) {
|
||||
auto ph = REVPHHandles->Get(handle);
|
||||
if (ph == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -467,9 +467,9 @@ double HAL_GetREVPHSolenoidVoltage(HAL_REVPHHandle handle, int32_t* status) {
|
||||
return PH_status_1_solenoid_voltage_decode(status1.solenoid_voltage);
|
||||
}
|
||||
|
||||
HAL_REVPHVersion HAL_GetREVPHVersion(HAL_REVPHHandle handle, int32_t* status) {
|
||||
HAL_REVPHVersion version;
|
||||
std::memset(&version, 0, sizeof(version));
|
||||
void HAL_GetREVPHVersion(HAL_REVPHHandle handle, HAL_REVPHVersion* version,
|
||||
int32_t* status) {
|
||||
std::memset(version, 0, sizeof(*version));
|
||||
uint8_t packedData[8] = {0};
|
||||
int32_t length = 0;
|
||||
uint64_t timestamp = 0;
|
||||
@@ -477,33 +477,31 @@ HAL_REVPHVersion HAL_GetREVPHVersion(HAL_REVPHHandle handle, int32_t* status) {
|
||||
auto ph = REVPHHandles->Get(handle);
|
||||
if (ph == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return version;
|
||||
return;
|
||||
}
|
||||
|
||||
HAL_WriteCANRTRFrame(ph->hcan, PH_VERSION_LENGTH, PH_VERSION_FRAME_API,
|
||||
status);
|
||||
|
||||
if (*status != 0) {
|
||||
return version;
|
||||
return;
|
||||
}
|
||||
|
||||
HAL_ReadCANPacketTimeout(ph->hcan, PH_VERSION_FRAME_API, packedData, &length,
|
||||
×tamp, kDefaultControlPeriod * 2, status);
|
||||
|
||||
if (*status != 0) {
|
||||
return version;
|
||||
return;
|
||||
}
|
||||
|
||||
PH_version_unpack(&result, packedData, PH_VERSION_LENGTH);
|
||||
|
||||
version.firmwareMajor = result.firmware_year;
|
||||
version.firmwareMinor = result.firmware_minor;
|
||||
version.firmwareFix = result.firmware_fix;
|
||||
version.hardwareMinor = result.hardware_minor;
|
||||
version.hardwareMajor = result.hardware_major;
|
||||
version.uniqueId = result.unique_id;
|
||||
|
||||
return version;
|
||||
version->firmwareMajor = result.firmware_year;
|
||||
version->firmwareMinor = result.firmware_minor;
|
||||
version->firmwareFix = result.firmware_fix;
|
||||
version->hardwareMinor = result.hardware_minor;
|
||||
version->hardwareMajor = result.hardware_major;
|
||||
version->uniqueId = result.unique_id;
|
||||
}
|
||||
|
||||
int32_t HAL_GetREVPHSolenoids(HAL_REVPHHandle handle, int32_t* status) {
|
||||
@@ -660,60 +658,58 @@ void HAL_FireREVPHOneShot(HAL_REVPHHandle handle, int32_t index, int32_t durMs,
|
||||
PH_PULSE_ONCE_FRAME_API, status);
|
||||
}
|
||||
|
||||
HAL_REVPHFaults HAL_GetREVPHFaults(HAL_REVPHHandle handle, int32_t* status) {
|
||||
HAL_REVPHFaults faults = {};
|
||||
void HAL_GetREVPHFaults(HAL_REVPHHandle handle, HAL_REVPHFaults* faults,
|
||||
int32_t* status) {
|
||||
std::memset(faults, 0, sizeof(*faults));
|
||||
auto ph = REVPHHandles->Get(handle);
|
||||
if (ph == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return faults;
|
||||
return;
|
||||
}
|
||||
|
||||
PH_status_0_t status0 = HAL_ReadREVPHStatus0(ph->hcan, status);
|
||||
faults.channel0Fault = status0.channel_0_fault;
|
||||
faults.channel1Fault = status0.channel_1_fault;
|
||||
faults.channel2Fault = status0.channel_2_fault;
|
||||
faults.channel3Fault = status0.channel_3_fault;
|
||||
faults.channel4Fault = status0.channel_4_fault;
|
||||
faults.channel5Fault = status0.channel_5_fault;
|
||||
faults.channel6Fault = status0.channel_6_fault;
|
||||
faults.channel7Fault = status0.channel_7_fault;
|
||||
faults.channel8Fault = status0.channel_8_fault;
|
||||
faults.channel9Fault = status0.channel_9_fault;
|
||||
faults.channel10Fault = status0.channel_10_fault;
|
||||
faults.channel11Fault = status0.channel_11_fault;
|
||||
faults.channel12Fault = status0.channel_12_fault;
|
||||
faults.channel13Fault = status0.channel_13_fault;
|
||||
faults.channel14Fault = status0.channel_14_fault;
|
||||
faults.channel15Fault = status0.channel_15_fault;
|
||||
faults.compressorOverCurrent = status0.compressor_oc_fault;
|
||||
faults.compressorOpen = status0.compressor_open_fault;
|
||||
faults.solenoidOverCurrent = status0.solenoid_oc_fault;
|
||||
faults.brownout = status0.brownout_fault;
|
||||
faults.canWarning = status0.can_warning_fault;
|
||||
faults.hardwareFault = status0.hardware_fault;
|
||||
|
||||
return faults;
|
||||
faults->channel0Fault = status0.channel_0_fault;
|
||||
faults->channel1Fault = status0.channel_1_fault;
|
||||
faults->channel2Fault = status0.channel_2_fault;
|
||||
faults->channel3Fault = status0.channel_3_fault;
|
||||
faults->channel4Fault = status0.channel_4_fault;
|
||||
faults->channel5Fault = status0.channel_5_fault;
|
||||
faults->channel6Fault = status0.channel_6_fault;
|
||||
faults->channel7Fault = status0.channel_7_fault;
|
||||
faults->channel8Fault = status0.channel_8_fault;
|
||||
faults->channel9Fault = status0.channel_9_fault;
|
||||
faults->channel10Fault = status0.channel_10_fault;
|
||||
faults->channel11Fault = status0.channel_11_fault;
|
||||
faults->channel12Fault = status0.channel_12_fault;
|
||||
faults->channel13Fault = status0.channel_13_fault;
|
||||
faults->channel14Fault = status0.channel_14_fault;
|
||||
faults->channel15Fault = status0.channel_15_fault;
|
||||
faults->compressorOverCurrent = status0.compressor_oc_fault;
|
||||
faults->compressorOpen = status0.compressor_open_fault;
|
||||
faults->solenoidOverCurrent = status0.solenoid_oc_fault;
|
||||
faults->brownout = status0.brownout_fault;
|
||||
faults->canWarning = status0.can_warning_fault;
|
||||
faults->hardwareFault = status0.hardware_fault;
|
||||
}
|
||||
|
||||
HAL_REVPHStickyFaults HAL_GetREVPHStickyFaults(HAL_REVPHHandle handle,
|
||||
int32_t* status) {
|
||||
HAL_REVPHStickyFaults stickyFaults = {};
|
||||
void HAL_GetREVPHStickyFaults(HAL_REVPHHandle handle,
|
||||
HAL_REVPHStickyFaults* stickyFaults,
|
||||
int32_t* status) {
|
||||
std::memset(stickyFaults, 0, sizeof(*stickyFaults));
|
||||
auto ph = REVPHHandles->Get(handle);
|
||||
if (ph == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return stickyFaults;
|
||||
return;
|
||||
}
|
||||
|
||||
PH_status_1_t status1 = HAL_ReadREVPHStatus1(ph->hcan, status);
|
||||
stickyFaults.compressorOverCurrent = status1.sticky_compressor_oc_fault;
|
||||
stickyFaults.compressorOpen = status1.sticky_compressor_open_fault;
|
||||
stickyFaults.solenoidOverCurrent = status1.sticky_solenoid_oc_fault;
|
||||
stickyFaults.brownout = status1.sticky_brownout_fault;
|
||||
stickyFaults.canWarning = status1.sticky_can_warning_fault;
|
||||
stickyFaults.canBusOff = status1.sticky_can_bus_off_fault;
|
||||
stickyFaults.hasReset = status1.sticky_has_reset_fault;
|
||||
|
||||
return stickyFaults;
|
||||
stickyFaults->compressorOverCurrent = status1.sticky_compressor_oc_fault;
|
||||
stickyFaults->compressorOpen = status1.sticky_compressor_open_fault;
|
||||
stickyFaults->solenoidOverCurrent = status1.sticky_solenoid_oc_fault;
|
||||
stickyFaults->brownout = status1.sticky_brownout_fault;
|
||||
stickyFaults->canWarning = status1.sticky_can_warning_fault;
|
||||
stickyFaults->canBusOff = status1.sticky_can_bus_off_fault;
|
||||
stickyFaults->hasReset = status1.sticky_has_reset_fault;
|
||||
}
|
||||
|
||||
void HAL_ClearREVPHStickyFaults(HAL_REVPHHandle handle, int32_t* status) {
|
||||
|
||||
@@ -53,6 +53,7 @@ static JClass accumulatorResultCls;
|
||||
static JClass canDataCls;
|
||||
static JClass halValueCls;
|
||||
static JClass baseStoreCls;
|
||||
static JClass revPHVersionCls;
|
||||
|
||||
static const JClassInit classes[] = {
|
||||
{"edu/wpi/first/hal/PWMConfigDataResult", &pwmConfigDataResultCls},
|
||||
@@ -61,7 +62,8 @@ static const JClassInit classes[] = {
|
||||
{"edu/wpi/first/hal/AccumulatorResult", &accumulatorResultCls},
|
||||
{"edu/wpi/first/hal/CANData", &canDataCls},
|
||||
{"edu/wpi/first/hal/HALValue", &halValueCls},
|
||||
{"edu/wpi/first/hal/DMAJNISample$BaseStore", &baseStoreCls}};
|
||||
{"edu/wpi/first/hal/DMAJNISample$BaseStore", &baseStoreCls},
|
||||
{"edu/wpi/first/hal/REVPHVersion", &revPHVersionCls}};
|
||||
|
||||
static const JExceptionInit exceptions[] = {
|
||||
{"java/lang/IllegalArgumentException", &illegalArgExCls},
|
||||
@@ -238,6 +240,19 @@ jobject CreatePWMConfigDataResult(JNIEnv* env, int32_t maxPwm,
|
||||
static_cast<jint>(deadbandMinPwm), static_cast<jint>(minPwm));
|
||||
}
|
||||
|
||||
jobject CreateREVPHVersion(JNIEnv* env, uint32_t firmwareMajor,
|
||||
uint32_t firmwareMinor, uint32_t firmwareFix,
|
||||
uint32_t hardwareMinor, uint32_t hardwareMajor,
|
||||
uint32_t uniqueId) {
|
||||
static jmethodID constructor =
|
||||
env->GetMethodID(revPHVersionCls, "<init>", "(IIIIII)V");
|
||||
return env->NewObject(
|
||||
revPHVersionCls, constructor, static_cast<jint>(firmwareMajor),
|
||||
static_cast<jint>(firmwareMinor), static_cast<jint>(firmwareFix),
|
||||
static_cast<jint>(hardwareMinor), static_cast<jint>(hardwareMajor),
|
||||
static_cast<jint>(uniqueId));
|
||||
}
|
||||
|
||||
void SetCanStatusObject(JNIEnv* env, jobject canStatus,
|
||||
float percentBusUtilization, uint32_t busOffCount,
|
||||
uint32_t txFullCount, uint32_t receiveErrorCount,
|
||||
|
||||
@@ -59,6 +59,11 @@ jobject CreatePWMConfigDataResult(JNIEnv* env, int32_t maxPwm,
|
||||
int32_t deadbandMaxPwm, int32_t centerPwm,
|
||||
int32_t deadbandMinPwm, int32_t minPwm);
|
||||
|
||||
jobject CreateREVPHVersion(JNIEnv* env, uint32_t firmwareMajor,
|
||||
uint32_t firmwareMinor, uint32_t firmwareFix,
|
||||
uint32_t hardwareMinor, uint32_t hardwareMajor,
|
||||
uint32_t uniqueId);
|
||||
|
||||
void SetCanStatusObject(JNIEnv* env, jobject canStatus,
|
||||
float percentBusUtilization, uint32_t busOffCount,
|
||||
uint32_t txFullCount, uint32_t receiveErrorCount,
|
||||
|
||||
@@ -196,15 +196,15 @@ Java_edu_wpi_first_hal_REVPHJNI_getPressureSwitch
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getAnalogPressure
|
||||
* Method: getAnalogVoltage
|
||||
* Signature: (II)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getAnalogPressure
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getAnalogVoltage
|
||||
(JNIEnv* env, jclass, jint handle, jint channel)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHAnalogPressure(handle, channel, &status);
|
||||
auto result = HAL_GetREVPHAnalogVoltage(handle, channel, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return result;
|
||||
}
|
||||
@@ -267,4 +267,137 @@ Java_edu_wpi_first_hal_REVPHJNI_fireOneShot
|
||||
CheckStatus(env, status, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: clearStickyFaults
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_clearStickyFaults
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_ClearREVPHStickyFaults(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getInputVoltage
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getInputVoltage
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHVoltage(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: get5VVoltage
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_get5VVoltage
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPH5VVoltage(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getSolenoidCurrent
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getSolenoidCurrent
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHSolenoidCurrent(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getSolenoidVoltage
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getSolenoidVoltage
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHSolenoidVoltage(handle, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getStickyFaultsNative
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getStickyFaultsNative
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_REVPHStickyFaults halFaults;
|
||||
std::memset(&halFaults, 0, sizeof(halFaults));
|
||||
HAL_GetREVPHStickyFaults(handle, &halFaults, &status);
|
||||
CheckStatus(env, status, false);
|
||||
jint faults;
|
||||
static_assert(sizeof(faults) == sizeof(halFaults));
|
||||
std::memcpy(&faults, &halFaults, sizeof(faults));
|
||||
return faults;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getFaultsNative
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getFaultsNative
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_REVPHFaults halFaults;
|
||||
std::memset(&halFaults, 0, sizeof(halFaults));
|
||||
HAL_GetREVPHFaults(handle, &halFaults, &status);
|
||||
CheckStatus(env, status, false);
|
||||
jint faults;
|
||||
static_assert(sizeof(faults) == sizeof(halFaults));
|
||||
std::memcpy(&faults, &halFaults, sizeof(faults));
|
||||
return faults;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_hal_REVPHJNI
|
||||
* Method: getVersion
|
||||
* Signature: (I)Ljava/lang/Object;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_edu_wpi_first_hal_REVPHJNI_getVersion
|
||||
(JNIEnv* env, jclass, jint handle)
|
||||
{
|
||||
int32_t status = 0;
|
||||
HAL_REVPHVersion version;
|
||||
std::memset(&version, 0, sizeof(version));
|
||||
HAL_GetREVPHVersion(handle, &version, &status);
|
||||
CheckStatus(env, status, false);
|
||||
return CreateREVPHVersion(env, version.firmwareMajor, version.firmwareMinor,
|
||||
version.firmwareFix, version.hardwareMinor,
|
||||
version.hardwareMajor, version.uniqueId);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -120,13 +120,14 @@ HAL_REVPHCompressorConfigType HAL_GetREVPHCompressorConfig(
|
||||
HAL_REVPHHandle handle, int32_t* status);
|
||||
HAL_Bool HAL_GetREVPHPressureSwitch(HAL_REVPHHandle handle, int32_t* status);
|
||||
double HAL_GetREVPHCompressorCurrent(HAL_REVPHHandle handle, int32_t* status);
|
||||
double HAL_GetREVPHAnalogPressure(HAL_REVPHHandle handle, int32_t channel,
|
||||
int32_t* status);
|
||||
double HAL_GetREVPHAnalogVoltage(HAL_REVPHHandle handle, int32_t channel,
|
||||
int32_t* status);
|
||||
double HAL_GetREVPHVoltage(HAL_REVPHHandle handle, int32_t* status);
|
||||
double HAL_GetREVPH5VVoltage(HAL_REVPHHandle handle, int32_t* status);
|
||||
double HAL_GetREVPHSolenoidCurrent(HAL_REVPHHandle handle, int32_t* status);
|
||||
double HAL_GetREVPHSolenoidVoltage(HAL_REVPHHandle handle, int32_t* status);
|
||||
HAL_REVPHVersion HAL_GetREVPHVersion(HAL_REVPHHandle handle, int32_t* status);
|
||||
void HAL_GetREVPHVersion(HAL_REVPHHandle handle, HAL_REVPHVersion* version,
|
||||
int32_t* status);
|
||||
|
||||
int32_t HAL_GetREVPHSolenoids(HAL_REVPHHandle handle, int32_t* status);
|
||||
void HAL_SetREVPHSolenoids(HAL_REVPHHandle handle, int32_t mask, int32_t values,
|
||||
@@ -135,10 +136,12 @@ void HAL_SetREVPHSolenoids(HAL_REVPHHandle handle, int32_t mask, int32_t values,
|
||||
void HAL_FireREVPHOneShot(HAL_REVPHHandle handle, int32_t index, int32_t durMs,
|
||||
int32_t* status);
|
||||
|
||||
HAL_REVPHFaults HAL_GetREVPHFaults(HAL_REVPHHandle handle, int32_t* status);
|
||||
void HAL_GetREVPHFaults(HAL_REVPHHandle handle, HAL_REVPHFaults* faults,
|
||||
int32_t* status);
|
||||
|
||||
HAL_REVPHStickyFaults HAL_GetREVPHStickyFaults(HAL_REVPHHandle handle,
|
||||
int32_t* status);
|
||||
void HAL_GetREVPHStickyFaults(HAL_REVPHHandle handle,
|
||||
HAL_REVPHStickyFaults* stickyFaults,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_ClearREVPHStickyFaults(HAL_REVPHHandle handle, int32_t* status);
|
||||
|
||||
|
||||
@@ -177,8 +177,8 @@ HAL_Bool HAL_GetREVPHPressureSwitch(HAL_REVPHHandle handle, int32_t* status) {
|
||||
return SimREVPHData[pcm->module].pressureSwitch;
|
||||
}
|
||||
|
||||
double HAL_GetREVPHAnalogPressure(HAL_REVPHHandle handle, int32_t channel,
|
||||
int32_t* status) {
|
||||
double HAL_GetREVPHAnalogVoltage(HAL_REVPHHandle handle, int32_t channel,
|
||||
int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -227,3 +227,31 @@ void HAL_SetREVPHSolenoids(HAL_REVPHHandle handle, int32_t mask, int32_t values,
|
||||
|
||||
void HAL_FireREVPHOneShot(HAL_REVPHHandle handle, int32_t index, int32_t durMs,
|
||||
int32_t* status) {}
|
||||
|
||||
double HAL_GetREVPHVoltage(HAL_REVPHHandle handle, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double HAL_GetREVPH5VVoltage(HAL_REVPHHandle handle, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double HAL_GetREVPHSolenoidCurrent(HAL_REVPHHandle handle, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double HAL_GetREVPHSolenoidVoltage(HAL_REVPHHandle handle, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HAL_GetREVPHVersion(HAL_REVPHHandle handle, HAL_REVPHVersion* version,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_GetREVPHFaults(HAL_REVPHHandle handle, HAL_REVPHFaults* faults,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_GetREVPHStickyFaults(HAL_REVPHHandle handle,
|
||||
HAL_REVPHStickyFaults* stickyFaults,
|
||||
int32_t* status) {}
|
||||
|
||||
void HAL_ClearREVPHStickyFaults(HAL_REVPHHandle handle, int32_t* status) {}
|
||||
|
||||
@@ -48,10 +48,14 @@ bool Compressor::GetPressureSwitchValue() const {
|
||||
return m_module->GetPressureSwitch();
|
||||
}
|
||||
|
||||
double Compressor::GetCurrent() const {
|
||||
units::ampere_t Compressor::GetCurrent() const {
|
||||
return m_module->GetCompressorCurrent();
|
||||
}
|
||||
|
||||
units::volt_t Compressor::GetAnalogVoltage() const {
|
||||
return m_module->GetAnalogVoltage(0);
|
||||
}
|
||||
|
||||
void Compressor::Disable() {
|
||||
m_module->DisableCompressor();
|
||||
}
|
||||
@@ -60,13 +64,13 @@ void Compressor::EnableDigital() {
|
||||
m_module->EnableCompressorDigital();
|
||||
}
|
||||
|
||||
void Compressor::EnableAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
void Compressor::EnableAnalog(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) {
|
||||
m_module->EnableCompressorAnalog(minAnalogVoltage, maxAnalogVoltage);
|
||||
}
|
||||
|
||||
void Compressor::EnableHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
void Compressor::EnableHybrid(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) {
|
||||
m_module->EnableCompressorHybrid(minAnalogVoltage, maxAnalogVoltage);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ class PneumaticHub::DataStore {
|
||||
bool m_compressorReserved{false};
|
||||
wpi::mutex m_reservedLock;
|
||||
PneumaticHub m_moduleObject{HAL_kInvalidHandle, 0};
|
||||
std::array<units::second_t, 16> m_oneShotDurMs{0_s};
|
||||
};
|
||||
|
||||
PneumaticHub::PneumaticHub()
|
||||
@@ -76,69 +77,69 @@ PneumaticHub::PneumaticHub(HAL_REVPHHandle handle, int module)
|
||||
bool PneumaticHub::GetCompressor() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHCompressor(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return result;
|
||||
}
|
||||
|
||||
void PneumaticHub::DisableCompressor() {
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControlDisabled(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticHub::EnableCompressorDigital() {
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControlDigital(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticHub::EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
void PneumaticHub::EnableCompressorAnalog(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControlAnalog(m_handle, minAnalogVoltage,
|
||||
maxAnalogVoltage, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
HAL_SetREVPHClosedLoopControlAnalog(m_handle, minAnalogVoltage.value(),
|
||||
maxAnalogVoltage.value(), &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticHub::EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
void PneumaticHub::EnableCompressorHybrid(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHClosedLoopControlHybrid(m_handle, minAnalogVoltage,
|
||||
maxAnalogVoltage, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
HAL_SetREVPHClosedLoopControlHybrid(m_handle, minAnalogVoltage.value(),
|
||||
maxAnalogVoltage.value(), &status);
|
||||
FRC_ReportError(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);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return static_cast<CompressorConfigType>(result);
|
||||
}
|
||||
|
||||
bool PneumaticHub::GetPressureSwitch() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHPressureSwitch(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return result;
|
||||
}
|
||||
|
||||
double PneumaticHub::GetCompressorCurrent() const {
|
||||
units::ampere_t PneumaticHub::GetCompressorCurrent() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHCompressorCurrent(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return result;
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::ampere_t{result};
|
||||
}
|
||||
|
||||
void PneumaticHub::SetSolenoids(int mask, int values) {
|
||||
int32_t status = 0;
|
||||
HAL_SetREVPHSolenoids(m_handle, mask, values, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
int PneumaticHub::GetSolenoids() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetREVPHSolenoids(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -147,27 +148,26 @@ int PneumaticHub::GetModuleNumber() const {
|
||||
}
|
||||
|
||||
int PneumaticHub::GetSolenoidDisabledList() const {
|
||||
return 0;
|
||||
// TODO Fix me
|
||||
// int32_t status = 0;
|
||||
// auto result = HAL_GetREVPHSolenoidDisabledList(m_handle, &status);
|
||||
// FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
// return result;
|
||||
int32_t status = 0;
|
||||
HAL_REVPHStickyFaults faults;
|
||||
std::memset(&faults, 0, sizeof(faults));
|
||||
HAL_GetREVPHStickyFaults(m_handle, &faults, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
uint32_t intFaults = 0;
|
||||
static_assert(sizeof(faults) == sizeof(intFaults));
|
||||
std::memcpy(&intFaults, &faults, sizeof(faults));
|
||||
return intFaults & 0xFFFF;
|
||||
}
|
||||
|
||||
void PneumaticHub::FireOneShot(int index) {
|
||||
// TODO Fix me
|
||||
// int32_t status = 0;
|
||||
// HAL_FireREVPHOneShot(m_handle, index, &status);
|
||||
// FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
int32_t status = 0;
|
||||
HAL_FireREVPHOneShot(m_handle, index,
|
||||
m_dataStore->m_oneShotDurMs[index].value(), &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticHub::SetOneShotDuration(int index, units::second_t duration) {
|
||||
// TODO Fix me
|
||||
// int32_t status = 0;
|
||||
// units::millisecond_t millis = duration;
|
||||
// HAL_SetREVPHOneShotDuration(m_handle, index, millis.to<int32_t>(),
|
||||
// &status); FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
m_dataStore->m_oneShotDurMs[index] = duration;
|
||||
}
|
||||
|
||||
bool PneumaticHub::CheckSolenoidChannel(int channel) const {
|
||||
@@ -203,6 +203,89 @@ void PneumaticHub::UnreserveCompressor() {
|
||||
m_dataStore->m_compressorReserved = false;
|
||||
}
|
||||
|
||||
PneumaticHub::Version PneumaticHub::GetVersion() const {
|
||||
int32_t status = 0;
|
||||
HAL_REVPHVersion halVersions;
|
||||
std::memset(&halVersions, 0, sizeof(halVersions));
|
||||
HAL_GetREVPHVersion(m_handle, &halVersions, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
PneumaticHub::Version versions;
|
||||
static_assert(sizeof(halVersions) == sizeof(versions));
|
||||
static_assert(std::is_standard_layout_v<decltype(versions)>);
|
||||
static_assert(std::is_trivial_v<decltype(versions)>);
|
||||
std::memcpy(&versions, &halVersions, sizeof(versions));
|
||||
return versions;
|
||||
}
|
||||
|
||||
PneumaticHub::Faults PneumaticHub::GetFaults() const {
|
||||
int32_t status = 0;
|
||||
HAL_REVPHFaults halFaults;
|
||||
std::memset(&halFaults, 0, sizeof(halFaults));
|
||||
HAL_GetREVPHFaults(m_handle, &halFaults, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
PneumaticHub::Faults faults;
|
||||
static_assert(sizeof(halFaults) == sizeof(faults));
|
||||
static_assert(std::is_standard_layout_v<decltype(faults)>);
|
||||
static_assert(std::is_trivial_v<decltype(faults)>);
|
||||
std::memcpy(&faults, &halFaults, sizeof(faults));
|
||||
return faults;
|
||||
}
|
||||
|
||||
PneumaticHub::StickyFaults PneumaticHub::GetStickyFaults() const {
|
||||
int32_t status = 0;
|
||||
HAL_REVPHStickyFaults halStickyFaults;
|
||||
std::memset(&halStickyFaults, 0, sizeof(halStickyFaults));
|
||||
HAL_GetREVPHStickyFaults(m_handle, &halStickyFaults, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
PneumaticHub::StickyFaults stickyFaults;
|
||||
static_assert(sizeof(halStickyFaults) == sizeof(stickyFaults));
|
||||
static_assert(std::is_standard_layout_v<decltype(stickyFaults)>);
|
||||
static_assert(std::is_trivial_v<decltype(stickyFaults)>);
|
||||
std::memcpy(&stickyFaults, &halStickyFaults, sizeof(stickyFaults));
|
||||
return stickyFaults;
|
||||
}
|
||||
|
||||
void PneumaticHub::ClearStickyFaults() {
|
||||
int32_t status = 0;
|
||||
HAL_ClearREVPHStickyFaults(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
units::volt_t PneumaticHub::GetInputVoltage() const {
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHVoltage(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::volt_t{voltage};
|
||||
}
|
||||
|
||||
units::volt_t PneumaticHub::Get5VRegulatedVoltage() const {
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPH5VVoltage(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::volt_t{voltage};
|
||||
}
|
||||
|
||||
units::ampere_t PneumaticHub::GetSolenoidsTotalCurrent() const {
|
||||
int32_t status = 0;
|
||||
auto current = HAL_GetREVPHSolenoidCurrent(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::ampere_t{current};
|
||||
}
|
||||
|
||||
units::volt_t PneumaticHub::GetSolenoidsVoltage() const {
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHSolenoidVoltage(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::volt_t{voltage};
|
||||
}
|
||||
|
||||
units::volt_t PneumaticHub::GetAnalogVoltage(int channel) const {
|
||||
int32_t status = 0;
|
||||
auto voltage = HAL_GetREVPHAnalogVoltage(m_handle, channel, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return units::volt_t{voltage};
|
||||
}
|
||||
|
||||
Solenoid PneumaticHub::MakeSolenoid(int channel) {
|
||||
return Solenoid{m_module, PneumaticsModuleType::REVPH, channel};
|
||||
}
|
||||
|
||||
@@ -96,15 +96,15 @@ void PneumaticsControlModule::EnableCompressorDigital() {
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticsControlModule::EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
void PneumaticsControlModule::EnableCompressorAnalog(
|
||||
units::volt_t minAnalogVoltage, units::volt_t maxAnalogVoltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PneumaticsControlModule::EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) {
|
||||
void PneumaticsControlModule::EnableCompressorHybrid(
|
||||
units::volt_t minAnalogVoltage, units::volt_t maxAnalogVoltage) {
|
||||
int32_t status = 0;
|
||||
HAL_SetCTREPCMClosedLoopControl(m_handle, true, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
@@ -125,11 +125,11 @@ bool PneumaticsControlModule::GetPressureSwitch() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
double PneumaticsControlModule::GetCompressorCurrent() const {
|
||||
units::ampere_t PneumaticsControlModule::GetCompressorCurrent() const {
|
||||
int32_t status = 0;
|
||||
auto result = HAL_GetCTREPCMCompressorCurrent(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return result;
|
||||
return units::ampere_t{result};
|
||||
}
|
||||
|
||||
bool PneumaticsControlModule::GetCompressorCurrentTooHighFault() const {
|
||||
@@ -261,6 +261,10 @@ void PneumaticsControlModule::UnreserveCompressor() {
|
||||
m_dataStore->m_compressorReserved = false;
|
||||
}
|
||||
|
||||
units::volt_t PneumaticsControlModule::GetAnalogVoltage(int channel) const {
|
||||
return units::volt_t{0};
|
||||
}
|
||||
|
||||
Solenoid PneumaticsControlModule::MakeSolenoid(int channel) {
|
||||
return Solenoid{m_module, PneumaticsModuleType::CTREPCM, channel};
|
||||
}
|
||||
|
||||
@@ -95,7 +95,14 @@ class Compressor : public wpi::Sendable,
|
||||
*
|
||||
* @return The current through the compressor, in amps
|
||||
*/
|
||||
double GetCurrent() const;
|
||||
units::ampere_t GetCurrent() const;
|
||||
|
||||
/**
|
||||
* Query the analog input voltage (on channel 0) (if supported).
|
||||
*
|
||||
* @return The analog input voltage, in volts
|
||||
*/
|
||||
units::volt_t GetAnalogVoltage() const;
|
||||
|
||||
/**
|
||||
* Disable the compressor.
|
||||
@@ -115,7 +122,8 @@ class Compressor : public wpi::Sendable,
|
||||
* @param minAnalogVoltage The minimum voltage to enable compressor
|
||||
* @param maxAnalogVoltage The maximum voltage to disable compressor
|
||||
*/
|
||||
void EnableAnalog(double minAnalogVoltage, double maxAnalogVoltage);
|
||||
void EnableAnalog(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage);
|
||||
|
||||
/**
|
||||
* Enable compressor closed loop control using hybrid input.
|
||||
@@ -125,7 +133,8 @@ class Compressor : public wpi::Sendable,
|
||||
* @param minAnalogVoltage The minimum voltage to enable compressor
|
||||
* @param maxAnalogVoltage The maximum voltage to disable compressor
|
||||
*/
|
||||
void EnableHybrid(double minAnalogVoltage, double maxAnalogVoltage);
|
||||
void EnableHybrid(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage);
|
||||
|
||||
CompressorConfigType GetConfigType() const;
|
||||
|
||||
|
||||
@@ -26,17 +26,17 @@ class PneumaticHub : public PneumaticsBase {
|
||||
|
||||
void EnableCompressorDigital() override;
|
||||
|
||||
void EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) override;
|
||||
void EnableCompressorAnalog(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) override;
|
||||
|
||||
void EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) override;
|
||||
void EnableCompressorHybrid(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) override;
|
||||
|
||||
CompressorConfigType GetCompressorConfigType() const override;
|
||||
|
||||
bool GetPressureSwitch() const override;
|
||||
|
||||
double GetCompressorCurrent() const override;
|
||||
units::ampere_t GetCompressorCurrent() const override;
|
||||
|
||||
void SetSolenoids(int mask, int values) override;
|
||||
|
||||
@@ -65,6 +65,68 @@ class PneumaticHub : public PneumaticsBase {
|
||||
int reverseChannel) override;
|
||||
Compressor MakeCompressor() override;
|
||||
|
||||
struct Version {
|
||||
uint32_t FirmwareMajor;
|
||||
uint32_t FirmwareMinor;
|
||||
uint32_t FirmwareFix;
|
||||
uint32_t HardwareMinor;
|
||||
uint32_t HardwareMajor;
|
||||
uint32_t UniqueId;
|
||||
};
|
||||
|
||||
Version GetVersion() const;
|
||||
|
||||
struct Faults {
|
||||
uint32_t Channel0Fault : 1;
|
||||
uint32_t Channel1Fault : 1;
|
||||
uint32_t Channel2Fault : 1;
|
||||
uint32_t Channel3Fault : 1;
|
||||
uint32_t Channel4Fault : 1;
|
||||
uint32_t Channel5Fault : 1;
|
||||
uint32_t Channel6Fault : 1;
|
||||
uint32_t Channel7Fault : 1;
|
||||
uint32_t Channel8Fault : 1;
|
||||
uint32_t Channel9Fault : 1;
|
||||
uint32_t Channel10Fault : 1;
|
||||
uint32_t Channel11Fault : 1;
|
||||
uint32_t Channel12Fault : 1;
|
||||
uint32_t Channel13Fault : 1;
|
||||
uint32_t Channel14Fault : 1;
|
||||
uint32_t Channel15Fault : 1;
|
||||
uint32_t CompressorOverCurrent : 1;
|
||||
uint32_t CompressorOpen : 1;
|
||||
uint32_t SolenoidOverCurrent : 1;
|
||||
uint32_t Brownout : 1;
|
||||
uint32_t CanWarning : 1;
|
||||
uint32_t HardwareFault : 1;
|
||||
};
|
||||
|
||||
Faults GetFaults() const;
|
||||
|
||||
struct StickyFaults {
|
||||
uint32_t CompressorOverCurrent : 1;
|
||||
uint32_t CompressorOpen : 1;
|
||||
uint32_t SolenoidOverCurrent : 1;
|
||||
uint32_t Brownout : 1;
|
||||
uint32_t CanWarning : 1;
|
||||
uint32_t CanBusOff : 1;
|
||||
uint32_t HasReset : 1;
|
||||
};
|
||||
|
||||
StickyFaults GetStickyFaults() const;
|
||||
|
||||
void ClearStickyFaults();
|
||||
|
||||
units::volt_t GetInputVoltage() const;
|
||||
|
||||
units::volt_t Get5VRegulatedVoltage() const;
|
||||
|
||||
units::ampere_t GetSolenoidsTotalCurrent() const;
|
||||
|
||||
units::volt_t GetSolenoidsVoltage() const;
|
||||
|
||||
units::volt_t GetAnalogVoltage(int channel) const override;
|
||||
|
||||
private:
|
||||
class DataStore;
|
||||
friend class DataStore;
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <units/current.h>
|
||||
#include <units/time.h>
|
||||
#include <units/voltage.h>
|
||||
|
||||
#include "frc/CompressorConfigType.h"
|
||||
#include "frc/PneumaticsModuleType.h"
|
||||
@@ -23,17 +25,17 @@ class PneumaticsBase {
|
||||
|
||||
virtual bool GetPressureSwitch() const = 0;
|
||||
|
||||
virtual double GetCompressorCurrent() const = 0;
|
||||
virtual units::ampere_t GetCompressorCurrent() const = 0;
|
||||
|
||||
virtual void DisableCompressor() = 0;
|
||||
|
||||
virtual void EnableCompressorDigital() = 0;
|
||||
|
||||
virtual void EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) = 0;
|
||||
virtual void EnableCompressorAnalog(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) = 0;
|
||||
|
||||
virtual void EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) = 0;
|
||||
virtual void EnableCompressorHybrid(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) = 0;
|
||||
|
||||
virtual CompressorConfigType GetCompressorConfigType() const = 0;
|
||||
|
||||
@@ -59,6 +61,8 @@ class PneumaticsBase {
|
||||
|
||||
virtual void UnreserveCompressor() = 0;
|
||||
|
||||
virtual units::volt_t GetAnalogVoltage(int channel) const = 0;
|
||||
|
||||
virtual Solenoid MakeSolenoid(int channel) = 0;
|
||||
virtual DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
|
||||
int reverseChannel) = 0;
|
||||
|
||||
@@ -26,17 +26,17 @@ class PneumaticsControlModule : public PneumaticsBase {
|
||||
|
||||
void EnableCompressorDigital() override;
|
||||
|
||||
void EnableCompressorAnalog(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) override;
|
||||
void EnableCompressorAnalog(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) override;
|
||||
|
||||
void EnableCompressorHybrid(double minAnalogVoltage,
|
||||
double maxAnalogVoltage) override;
|
||||
void EnableCompressorHybrid(units::volt_t minAnalogVoltage,
|
||||
units::volt_t maxAnalogVoltage) override;
|
||||
|
||||
CompressorConfigType GetCompressorConfigType() const override;
|
||||
|
||||
bool GetPressureSwitch() const override;
|
||||
|
||||
double GetCompressorCurrent() const override;
|
||||
units::ampere_t GetCompressorCurrent() const override;
|
||||
|
||||
bool GetCompressorCurrentTooHighFault() const;
|
||||
bool GetCompressorCurrentTooHighStickyFault() const;
|
||||
@@ -72,6 +72,8 @@ class PneumaticsControlModule : public PneumaticsBase {
|
||||
|
||||
void UnreserveCompressor() override;
|
||||
|
||||
units::volt_t GetAnalogVoltage(int channel) const override;
|
||||
|
||||
Solenoid MakeSolenoid(int channel) override;
|
||||
DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
|
||||
int reverseChannel) override;
|
||||
|
||||
@@ -143,7 +143,7 @@ TEST(CTREPCMSimTest, SetCompressorCurrent) {
|
||||
|
||||
sim.SetCompressorCurrent(35.04);
|
||||
EXPECT_EQ(35.04, sim.GetCompressorCurrent());
|
||||
EXPECT_EQ(35.04, pcm.GetCompressorCurrent());
|
||||
EXPECT_EQ(35.04_A, pcm.GetCompressorCurrent());
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_EQ(35.04, callback.GetLastValue());
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ TEST(REVPHSimTest, SetEnableAnalog) {
|
||||
ph.DisableCompressor();
|
||||
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Disabled);
|
||||
|
||||
ph.EnableCompressorAnalog(1, 2);
|
||||
ph.EnableCompressorAnalog(1_V, 2_V);
|
||||
EXPECT_EQ(sim.GetCompressorConfigType(),
|
||||
static_cast<int>(CompressorConfigType::Analog));
|
||||
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Analog);
|
||||
@@ -150,7 +150,7 @@ TEST(REVPHSimTest, SetEnableHybrid) {
|
||||
ph.DisableCompressor();
|
||||
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Disabled);
|
||||
|
||||
ph.EnableCompressorHybrid(1, 2);
|
||||
ph.EnableCompressorHybrid(1_V, 2_V);
|
||||
EXPECT_EQ(sim.GetCompressorConfigType(),
|
||||
static_cast<int>(CompressorConfigType::Hybrid));
|
||||
EXPECT_EQ(ph.GetCompressorConfigType(), CompressorConfigType::Hybrid);
|
||||
@@ -187,7 +187,7 @@ TEST(REVPHSimTest, SetCompressorCurrent) {
|
||||
|
||||
sim.SetCompressorCurrent(35.04);
|
||||
EXPECT_EQ(35.04, sim.GetCompressorCurrent());
|
||||
EXPECT_EQ(35.04, ph.GetCompressorCurrent());
|
||||
EXPECT_EQ(35.04_A, ph.GetCompressorCurrent());
|
||||
EXPECT_TRUE(callback.WasTriggered());
|
||||
EXPECT_EQ(35.04, callback.GetLastValue());
|
||||
}
|
||||
|
||||
@@ -117,6 +117,15 @@ public class Compressor implements Sendable, AutoCloseable {
|
||||
return m_module.getCompressorCurrent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the analog input voltage (on channel 0) (if supported).
|
||||
*
|
||||
* @return The analog input voltage, in volts
|
||||
*/
|
||||
public double getAnalogVoltage() {
|
||||
return m_module.getAnalogVoltage(0);
|
||||
}
|
||||
|
||||
/** Disable the compressor. */
|
||||
public void disable() {
|
||||
m_module.disableCompressor();
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.hal.PortsJNI;
|
||||
import edu.wpi.first.hal.REVPHFaults;
|
||||
import edu.wpi.first.hal.REVPHJNI;
|
||||
import edu.wpi.first.hal.REVPHStickyFaults;
|
||||
import edu.wpi.first.hal.REVPHVersion;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -16,6 +20,7 @@ public class PneumaticHub implements PneumaticsBase {
|
||||
private int m_refCount;
|
||||
private int m_reservedMask;
|
||||
private boolean m_compressorReserved;
|
||||
public int[] m_oneShotDurMs = new int[PortsJNI.getNumREVPHChannels()];
|
||||
private final Object m_reserveLock = new Object();
|
||||
|
||||
DataStore(int module) {
|
||||
@@ -123,14 +128,12 @@ public class PneumaticHub implements PneumaticsBase {
|
||||
|
||||
@Override
|
||||
public void fireOneShot(int index) {
|
||||
// TODO Combine APIs
|
||||
// REVPHJNI.fireOneShot(m_handle, index, durMs);
|
||||
REVPHJNI.fireOneShot(m_handle, index, m_dataStore.m_oneShotDurMs[index]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOneShotDuration(int index, int durMs) {
|
||||
// TODO Combine APIs
|
||||
// REVPHJNI.setOneShotDuration(m_handle, index, durMs);
|
||||
m_dataStore.m_oneShotDurMs[index] = durMs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,8 +195,8 @@ public class PneumaticHub implements PneumaticsBase {
|
||||
|
||||
@Override
|
||||
public int getSolenoidDisabledList() {
|
||||
// TODO Get this working
|
||||
return 0;
|
||||
int raw = REVPHJNI.getStickyFaultsNative(m_handle);
|
||||
return raw & 0xFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -215,4 +218,41 @@ public class PneumaticHub implements PneumaticsBase {
|
||||
public void enableCompressorHybrid(double minAnalogVoltage, double maxAnalogVoltage) {
|
||||
REVPHJNI.setClosedLoopControlHybrid(m_handle, minAnalogVoltage, maxAnalogVoltage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAnalogVoltage(int channel) {
|
||||
return REVPHJNI.getAnalogVoltage(m_handle, channel);
|
||||
}
|
||||
|
||||
void clearStickyFaults() {
|
||||
REVPHJNI.clearStickyFaults(m_handle);
|
||||
}
|
||||
|
||||
REVPHVersion getVersion() {
|
||||
return REVPHJNI.getVersion(m_handle);
|
||||
}
|
||||
|
||||
REVPHFaults getFaults() {
|
||||
return REVPHJNI.getFaults(m_handle);
|
||||
}
|
||||
|
||||
REVPHStickyFaults getStickyFaults() {
|
||||
return REVPHJNI.getStickyFaults(m_handle);
|
||||
}
|
||||
|
||||
double getInputVoltage() {
|
||||
return REVPHJNI.getInputVoltage(m_handle);
|
||||
}
|
||||
|
||||
double get5VRegulatedVoltage() {
|
||||
return REVPHJNI.get5VVoltage(m_handle);
|
||||
}
|
||||
|
||||
double getSolenoidsTotalCurrent() {
|
||||
return REVPHJNI.getSolenoidCurrent(m_handle);
|
||||
}
|
||||
|
||||
double getSolenoidsVoltage() {
|
||||
return REVPHJNI.getSolenoidVoltage(m_handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,8 @@ public interface PneumaticsBase extends AutoCloseable {
|
||||
|
||||
void enableCompressorHybrid(double minAnalogVoltage, double maxAnalogVoltage);
|
||||
|
||||
double getAnalogVoltage(int channel);
|
||||
|
||||
CompressorConfigType getCompressorConfigType();
|
||||
|
||||
/**
|
||||
|
||||
@@ -250,4 +250,9 @@ public class PneumaticsControlModule implements PneumaticsBase {
|
||||
? CompressorConfigType.Digital
|
||||
: CompressorConfigType.Disabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAnalogVoltage(int channel) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user