mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal] Rename PowerDistributionPanel to PowerDistribution (#3466)
Makes HAL more generic for the PDP, to enable the Rev PDH in the future.
This commit is contained in:
@@ -2,99 +2,101 @@
|
||||
// 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.
|
||||
|
||||
#include "frc/PowerDistributionPanel.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/PDP.h>
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/PowerDistribution.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
#include "frc/Errors.h"
|
||||
#include "frc/PowerDistribution.h"
|
||||
#include "frc/SensorUtil.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
PowerDistributionPanel::PowerDistributionPanel() : PowerDistributionPanel(0) {}
|
||||
PowerDistribution::PowerDistribution() : PowerDistribution(0) {}
|
||||
|
||||
PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) {
|
||||
PowerDistribution::PowerDistribution(int module) : m_module(module) {
|
||||
int32_t status = 0;
|
||||
m_handle = HAL_InitializePDP(module, &status);
|
||||
m_handle = HAL_InitializePowerDistribution(
|
||||
module, HAL_PowerDistributionType::HAL_PowerDistributionType_kAutomatic,
|
||||
&status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", module);
|
||||
|
||||
HAL_Report(HALUsageReporting::kResourceType_PDP, module + 1);
|
||||
wpi::SendableRegistry::AddLW(this, "PowerDistributionPanel", module);
|
||||
wpi::SendableRegistry::AddLW(this, "PowerDistribution", module);
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetVoltage() const {
|
||||
double PowerDistribution::GetVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetPDPVoltage(m_handle, &status);
|
||||
double voltage = HAL_GetPowerDistributionVoltage(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTemperature() const {
|
||||
double PowerDistribution::GetTemperature() const {
|
||||
int32_t status = 0;
|
||||
double temperature = HAL_GetPDPTemperature(m_handle, &status);
|
||||
double temperature = HAL_GetPowerDistributionTemperature(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return temperature;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetCurrent(int channel) const {
|
||||
double PowerDistribution::GetCurrent(int channel) const {
|
||||
int32_t status = 0;
|
||||
|
||||
if (!SensorUtil::CheckPDPChannel(channel)) {
|
||||
if (!HAL_CheckPowerDistributionChannel(m_handle, channel)) {
|
||||
FRC_ReportError(err::ChannelIndexOutOfRange, "Module {} Channel {}",
|
||||
m_module, channel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
double current = HAL_GetPDPChannelCurrent(m_handle, channel, &status);
|
||||
double current =
|
||||
HAL_GetPowerDistributionChannelCurrent(m_handle, channel, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_module, channel);
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTotalCurrent() const {
|
||||
double PowerDistribution::GetTotalCurrent() const {
|
||||
int32_t status = 0;
|
||||
double current = HAL_GetPDPTotalCurrent(m_handle, &status);
|
||||
double current = HAL_GetPowerDistributionTotalCurrent(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return current;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTotalPower() const {
|
||||
double PowerDistribution::GetTotalPower() const {
|
||||
int32_t status = 0;
|
||||
double power = HAL_GetPDPTotalPower(m_handle, &status);
|
||||
double power = HAL_GetPowerDistributionTotalPower(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return power;
|
||||
}
|
||||
|
||||
double PowerDistributionPanel::GetTotalEnergy() const {
|
||||
double PowerDistribution::GetTotalEnergy() const {
|
||||
int32_t status = 0;
|
||||
double energy = HAL_GetPDPTotalEnergy(m_handle, &status);
|
||||
double energy = HAL_GetPowerDistributionTotalEnergy(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
return energy;
|
||||
}
|
||||
|
||||
void PowerDistributionPanel::ResetTotalEnergy() {
|
||||
void PowerDistribution::ResetTotalEnergy() {
|
||||
int32_t status = 0;
|
||||
HAL_ResetPDPTotalEnergy(m_handle, &status);
|
||||
HAL_ResetPowerDistributionTotalEnergy(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
void PowerDistributionPanel::ClearStickyFaults() {
|
||||
void PowerDistribution::ClearStickyFaults() {
|
||||
int32_t status = 0;
|
||||
HAL_ClearPDPStickyFaults(m_handle, &status);
|
||||
HAL_ClearPowerDistributionStickyFaults(m_handle, &status);
|
||||
FRC_CheckErrorStatus(status, "Module {}", m_module);
|
||||
}
|
||||
|
||||
int PowerDistributionPanel::GetModule() const {
|
||||
int PowerDistribution::GetModule() const {
|
||||
return m_module;
|
||||
}
|
||||
|
||||
void PowerDistributionPanel::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("PowerDistributionPanel");
|
||||
void PowerDistribution::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("PowerDistribution");
|
||||
for (int i = 0; i < SensorUtil::kPDPChannels; ++i) {
|
||||
builder.AddDoubleProperty(
|
||||
fmt::format("Chan{}", i), [=] { return GetCurrent(i); }, nullptr);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <hal/AnalogInput.h>
|
||||
#include <hal/AnalogOutput.h>
|
||||
#include <hal/DIO.h>
|
||||
#include <hal/PDP.h>
|
||||
#include <hal/PWM.h>
|
||||
#include <hal/Ports.h>
|
||||
#include <hal/Relay.h>
|
||||
@@ -46,11 +45,3 @@ bool SensorUtil::CheckAnalogInputChannel(int channel) {
|
||||
bool SensorUtil::CheckAnalogOutputChannel(int channel) {
|
||||
return HAL_CheckAnalogOutputChannel(channel);
|
||||
}
|
||||
|
||||
bool SensorUtil::CheckPDPChannel(int channel) {
|
||||
return HAL_CheckPDPChannel(channel);
|
||||
}
|
||||
|
||||
bool SensorUtil::CheckPDPModule(int module) {
|
||||
return HAL_CheckPDPModule(module);
|
||||
}
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "frc/simulation/PDPSim.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/PDPData.h>
|
||||
|
||||
#include "frc/PowerDistributionPanel.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
PDPSim::PDPSim(int module) : m_index{module} {}
|
||||
|
||||
PDPSim::PDPSim(const PowerDistributionPanel& pdp) : m_index{pdp.GetModule()} {}
|
||||
|
||||
std::unique_ptr<CallbackStore> PDPSim::RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPDPInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterPDPInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PDPSim::GetInitialized() const {
|
||||
return HALSIM_GetPDPInitialized(m_index);
|
||||
}
|
||||
|
||||
void PDPSim::SetInitialized(bool initialized) {
|
||||
HALSIM_SetPDPInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PDPSim::RegisterTemperatureCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPDPTemperatureCallback);
|
||||
store->SetUid(HALSIM_RegisterPDPTemperatureCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double PDPSim::GetTemperature() const {
|
||||
return HALSIM_GetPDPTemperature(m_index);
|
||||
}
|
||||
|
||||
void PDPSim::SetTemperature(double temperature) {
|
||||
HALSIM_SetPDPTemperature(m_index, temperature);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PDPSim::RegisterVoltageCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPDPVoltageCallback);
|
||||
store->SetUid(HALSIM_RegisterPDPVoltageCallback(m_index, &CallbackStoreThunk,
|
||||
store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double PDPSim::GetVoltage() const {
|
||||
return HALSIM_GetPDPVoltage(m_index);
|
||||
}
|
||||
|
||||
void PDPSim::SetVoltage(double voltage) {
|
||||
HALSIM_SetPDPVoltage(m_index, voltage);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PDPSim::RegisterCurrentCallback(
|
||||
int channel, NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, channel, -1, callback, &HALSIM_CancelPDPCurrentCallback);
|
||||
store->SetUid(HALSIM_RegisterPDPCurrentCallback(
|
||||
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double PDPSim::GetCurrent(int channel) const {
|
||||
return HALSIM_GetPDPCurrent(m_index, channel);
|
||||
}
|
||||
|
||||
void PDPSim::SetCurrent(int channel, double current) {
|
||||
HALSIM_SetPDPCurrent(m_index, channel, current);
|
||||
}
|
||||
|
||||
void PDPSim::GetAllCurrents(double* currents) const {
|
||||
HALSIM_GetPDPAllCurrents(m_index, currents);
|
||||
}
|
||||
|
||||
void PDPSim::SetAllCurrents(const double* currents) {
|
||||
HALSIM_SetPDPAllCurrents(m_index, currents);
|
||||
}
|
||||
|
||||
void PDPSim::ResetData() {
|
||||
HALSIM_ResetPDPData(m_index);
|
||||
}
|
||||
105
wpilibc/src/main/native/cpp/simulation/PowerDistributionSim.cpp
Normal file
105
wpilibc/src/main/native/cpp/simulation/PowerDistributionSim.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
// 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.
|
||||
|
||||
#include "frc/simulation/PowerDistributionSim.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <hal/simulation/PowerDistributionData.h>
|
||||
|
||||
#include "frc/PowerDistribution.h"
|
||||
|
||||
using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
PowerDistributionSim::PowerDistributionSim(int module) : m_index{module} {}
|
||||
|
||||
PowerDistributionSim::PowerDistributionSim(const PowerDistribution& pdp)
|
||||
: m_index{pdp.GetModule()} {}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
PowerDistributionSim::RegisterInitializedCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback,
|
||||
&HALSIM_CancelPowerDistributionInitializedCallback);
|
||||
store->SetUid(HALSIM_RegisterPowerDistributionInitializedCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
bool PowerDistributionSim::GetInitialized() const {
|
||||
return HALSIM_GetPowerDistributionInitialized(m_index);
|
||||
}
|
||||
|
||||
void PowerDistributionSim::SetInitialized(bool initialized) {
|
||||
HALSIM_SetPowerDistributionInitialized(m_index, initialized);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore>
|
||||
PowerDistributionSim::RegisterTemperatureCallback(NotifyCallback callback,
|
||||
bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback,
|
||||
&HALSIM_CancelPowerDistributionTemperatureCallback);
|
||||
store->SetUid(HALSIM_RegisterPowerDistributionTemperatureCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double PowerDistributionSim::GetTemperature() const {
|
||||
return HALSIM_GetPowerDistributionTemperature(m_index);
|
||||
}
|
||||
|
||||
void PowerDistributionSim::SetTemperature(double temperature) {
|
||||
HALSIM_SetPowerDistributionTemperature(m_index, temperature);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PowerDistributionSim::RegisterVoltageCallback(
|
||||
NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, -1, callback, &HALSIM_CancelPowerDistributionVoltageCallback);
|
||||
store->SetUid(HALSIM_RegisterPowerDistributionVoltageCallback(
|
||||
m_index, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double PowerDistributionSim::GetVoltage() const {
|
||||
return HALSIM_GetPowerDistributionVoltage(m_index);
|
||||
}
|
||||
|
||||
void PowerDistributionSim::SetVoltage(double voltage) {
|
||||
HALSIM_SetPowerDistributionVoltage(m_index, voltage);
|
||||
}
|
||||
|
||||
std::unique_ptr<CallbackStore> PowerDistributionSim::RegisterCurrentCallback(
|
||||
int channel, NotifyCallback callback, bool initialNotify) {
|
||||
auto store = std::make_unique<CallbackStore>(
|
||||
m_index, channel, -1, callback,
|
||||
&HALSIM_CancelPowerDistributionCurrentCallback);
|
||||
store->SetUid(HALSIM_RegisterPowerDistributionCurrentCallback(
|
||||
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
|
||||
return store;
|
||||
}
|
||||
|
||||
double PowerDistributionSim::GetCurrent(int channel) const {
|
||||
return HALSIM_GetPowerDistributionCurrent(m_index, channel);
|
||||
}
|
||||
|
||||
void PowerDistributionSim::SetCurrent(int channel, double current) {
|
||||
HALSIM_SetPowerDistributionCurrent(m_index, channel, current);
|
||||
}
|
||||
|
||||
void PowerDistributionSim::GetAllCurrents(double* currents) const {
|
||||
HALSIM_GetPowerDistributionAllCurrents(m_index, currents);
|
||||
}
|
||||
|
||||
void PowerDistributionSim::SetAllCurrents(const double* currents) {
|
||||
HALSIM_SetPowerDistributionAllCurrents(m_index, currents);
|
||||
}
|
||||
|
||||
void PowerDistributionSim::ResetData() {
|
||||
HALSIM_ResetPowerDistributionData(m_index);
|
||||
}
|
||||
Reference in New Issue
Block a user