mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[hal] [wpilib] Add initial support for the REV PDH (#3503)
This commit is contained in:
@@ -58,14 +58,20 @@ int32_t HAL_GetNumRelayHeaders(void) {
|
||||
int32_t HAL_GetNumCTREPCMModules(void) {
|
||||
return kNumCTREPCMModules;
|
||||
}
|
||||
int32_t HAL_GetNumSolenoidChannels(void) {
|
||||
int32_t HAL_GetNumCTRESolenoidChannels(void) {
|
||||
return kNumCTRESolenoidChannels;
|
||||
}
|
||||
int32_t HAL_GetNumPDPModules(void) {
|
||||
return kNumPDPModules;
|
||||
int32_t HAL_GetNumCTREPDPModules(void) {
|
||||
return kNumCTREPDPModules;
|
||||
}
|
||||
int32_t HAL_GetNumPDPChannels(void) {
|
||||
return kNumPDPChannels;
|
||||
int32_t HAL_GetNumCTREPDPChannels(void) {
|
||||
return kNumCTREPDPChannels;
|
||||
}
|
||||
int32_t HAL_GetNumREVPDHModules(void) {
|
||||
return kNumREVPDHModules;
|
||||
}
|
||||
int32_t HAL_GetNumREVPDHChannels(void) {
|
||||
return kNumREVPDHChannels;
|
||||
}
|
||||
int32_t HAL_GetNumDutyCycles(void) {
|
||||
return kNumDutyCycles;
|
||||
|
||||
@@ -23,8 +23,10 @@ constexpr int32_t kNumRelayChannels = 8;
|
||||
constexpr int32_t kNumRelayHeaders = kNumRelayChannels / 2;
|
||||
constexpr int32_t kNumCTREPCMModules = 63;
|
||||
constexpr int32_t kNumCTRESolenoidChannels = 8;
|
||||
constexpr int32_t kNumPDPModules = 63;
|
||||
constexpr int32_t kNumPDPChannels = 16;
|
||||
constexpr int32_t kNumCTREPDPModules = 63;
|
||||
constexpr int32_t kNumCTREPDPChannels = 16;
|
||||
constexpr int32_t kNumREVPDHModules = 63;
|
||||
constexpr int32_t kNumREVPDHChannels = 24;
|
||||
constexpr int32_t kNumDutyCycles = 8;
|
||||
constexpr int32_t kNumAddressableLEDs = 1;
|
||||
} // namespace hal
|
||||
|
||||
@@ -28,7 +28,8 @@ void InitializePowerDistribution() {}
|
||||
|
||||
extern "C" {
|
||||
HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
|
||||
int32_t module, HAL_PowerDistributionType type, int32_t* status) {
|
||||
int32_t module, HAL_PowerDistributionType type,
|
||||
const char* allocationLocation, int32_t* status) {
|
||||
if (!HAL_CheckPowerDistributionModule(module, type)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
hal::SetLastError(status, fmt::format("Invalid pdp module {}", module));
|
||||
@@ -46,14 +47,32 @@ HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
|
||||
return handle;
|
||||
}
|
||||
|
||||
int32_t HAL_GetPowerDistributionModuleNumber(HAL_PowerDistributionHandle handle,
|
||||
int32_t* status) {
|
||||
auto module = hal::can::GetCANModuleFromHandle(handle, status);
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
HAL_Bool HAL_CheckPowerDistributionModule(int32_t module,
|
||||
HAL_PowerDistributionType type) {
|
||||
return module < kNumPDPModules && module >= 0;
|
||||
if (type == HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE) {
|
||||
return module < kNumCTREPDPModules && module >= 0;
|
||||
} else {
|
||||
return module < kNumREVPDHModules && module >= 1;
|
||||
}
|
||||
}
|
||||
|
||||
HAL_Bool HAL_CheckPowerDistributionChannel(HAL_PowerDistributionHandle handle,
|
||||
int32_t channel) {
|
||||
return channel < kNumPDPChannels && channel >= 0;
|
||||
// TODO make this grab from the handle directly
|
||||
if (false) {
|
||||
return channel < kNumCTREPDPChannels && channel >= 0;
|
||||
} else {
|
||||
return channel < kNumREVPDHChannels && channel >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
HAL_PowerDistributionType HAL_GetPowerDistributionType(
|
||||
@@ -61,6 +80,16 @@ HAL_PowerDistributionType HAL_GetPowerDistributionType(
|
||||
return HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE;
|
||||
}
|
||||
|
||||
int32_t HAL_GetPowerDistributionNumChannels(HAL_PowerDistributionHandle handle,
|
||||
int32_t* status) {
|
||||
// TODO make this grab from the handle directly
|
||||
if (false) {
|
||||
return kNumCTREPDPChannels;
|
||||
} else {
|
||||
return kNumREVPDHChannels;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CleanPowerDistribution(HAL_PowerDistributionHandle handle) {
|
||||
HAL_CleanCAN(handle);
|
||||
}
|
||||
@@ -98,7 +127,8 @@ void HAL_GetPowerDistributionAllChannelCurrents(
|
||||
}
|
||||
|
||||
auto& data = SimPowerDistributionData[module];
|
||||
for (int i = 0; i < kNumPDPChannels; i++) {
|
||||
int toCopy = (std::min)(currentsLength, kNumPDSimChannels);
|
||||
for (int i = 0; i < toCopy; i++) {
|
||||
currents[i] = data.current[i];
|
||||
}
|
||||
}
|
||||
@@ -118,4 +148,11 @@ void HAL_ResetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle,
|
||||
int32_t* status) {}
|
||||
void HAL_ClearPowerDistributionStickyFaults(HAL_PowerDistributionHandle handle,
|
||||
int32_t* status) {}
|
||||
void HAL_SetPowerDistributionSwitchableChannel(
|
||||
HAL_PowerDistributionHandle handle, HAL_Bool state, int32_t* status) {}
|
||||
|
||||
HAL_Bool HAL_GetPowerDistributionSwitchableChannel(
|
||||
HAL_PowerDistributionHandle handle, int32_t* status) {
|
||||
return false;
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
@@ -9,7 +9,7 @@ using namespace hal;
|
||||
|
||||
namespace hal::init {
|
||||
void InitializePowerDistributionData() {
|
||||
static PowerDistributionData spd[kNumPDPChannels];
|
||||
static PowerDistributionData spd[kNumPDSimModules];
|
||||
::hal::SimPowerDistributionData = spd;
|
||||
}
|
||||
} // namespace hal::init
|
||||
@@ -19,7 +19,7 @@ void PowerDistributionData::ResetData() {
|
||||
initialized.Reset(false);
|
||||
temperature.Reset(0.0);
|
||||
voltage.Reset(12.0);
|
||||
for (int i = 0; i < kNumPDPChannels; i++) {
|
||||
for (int i = 0; i < kNumPDSimChannels; i++) {
|
||||
current[i].Reset(0.0);
|
||||
}
|
||||
}
|
||||
@@ -39,17 +39,21 @@ DEFINE_CAPI(double, Voltage, voltage)
|
||||
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(double, HALSIM, PowerDistributionCurrent,
|
||||
SimPowerDistributionData, current)
|
||||
|
||||
void HALSIM_GetPowerDistributionAllCurrents(int32_t index, double* currents) {
|
||||
void HALSIM_GetPowerDistributionAllCurrents(int32_t index, double* currents,
|
||||
int length) {
|
||||
auto& data = SimPowerDistributionData[index].current;
|
||||
for (int i = 0; i < kNumPDPChannels; i++) {
|
||||
int toCopy = (std::min)(length, kNumPDSimChannels);
|
||||
for (int i = 0; i < toCopy; i++) {
|
||||
currents[i] = data[i];
|
||||
}
|
||||
}
|
||||
|
||||
void HALSIM_SetPowerDistributionAllCurrents(int32_t index,
|
||||
const double* currents) {
|
||||
const double* currents,
|
||||
int length) {
|
||||
auto& data = SimPowerDistributionData[index].current;
|
||||
for (int i = 0; i < kNumPDPChannels; i++) {
|
||||
int toCopy = (std::min)(length, kNumPDSimChannels);
|
||||
for (int i = 0; i < toCopy; i++) {
|
||||
data[i] = currents[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
#include "hal/simulation/SimDataValue.h"
|
||||
|
||||
namespace hal {
|
||||
constexpr int32_t kNumPDSimModules = hal::kNumREVPDHModules;
|
||||
constexpr int32_t kNumPDSimChannels = hal::kNumREVPDHChannels;
|
||||
|
||||
class PowerDistributionData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(Temperature)
|
||||
@@ -25,7 +28,7 @@ class PowerDistributionData {
|
||||
SimDataValue<double, HAL_MakeDouble, GetTemperatureName> temperature{0.0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetVoltageName> voltage{12.0};
|
||||
SimDataValue<double, HAL_MakeDouble, GetCurrentName, GetCurrentDefault>
|
||||
current[kNumPDPChannels];
|
||||
current[kNumPDSimChannels];
|
||||
|
||||
virtual void ResetData();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user