mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal] [wpilib] Add initial support for the REV PDH (#3503)
This commit is contained in:
@@ -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