[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:
Thad House
2021-08-04 20:31:17 -07:00
committed by GitHub
parent 2014115bca
commit 1ac73a247e
50 changed files with 1612 additions and 1177 deletions

View File

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

View File

@@ -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);
}

View File

@@ -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);
}

View 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);
}

View File

@@ -14,26 +14,25 @@ namespace frc {
* Class for getting voltage, current, temperature, power and energy from the
* CAN PDP.
*/
class PowerDistributionPanel
: public wpi::Sendable,
public wpi::SendableHelper<PowerDistributionPanel> {
class PowerDistribution : public wpi::Sendable,
public wpi::SendableHelper<PowerDistribution> {
public:
/**
* Constructs a PowerDistributionPanel.
* Constructs a PowerDistribution.
*
* Uses the default CAN ID (0).
*/
PowerDistributionPanel();
PowerDistribution();
/**
* Constructs a PowerDistributionPanel.
* Constructs a PowerDistribution.
*
* @param module The CAN ID of the PDP
*/
explicit PowerDistributionPanel(int module);
explicit PowerDistribution(int module);
PowerDistributionPanel(PowerDistributionPanel&&) = default;
PowerDistributionPanel& operator=(PowerDistributionPanel&&) = default;
PowerDistribution(PowerDistribution&&) = default;
PowerDistribution& operator=(PowerDistribution&&) = default;
/**
* Query the input voltage of the PDP.
@@ -80,7 +79,7 @@ class PowerDistributionPanel
/**
* Reset the total energy drawn from the PDP.
*
* @see PowerDistributionPanel#GetTotalEnergy
* @see PowerDistribution#GetTotalEnergy
*/
void ResetTotalEnergy();

View File

@@ -160,8 +160,8 @@ enum class BuiltInWidgets {
*/
kVoltageView,
/**
* Displays a PowerDistributionPanel. <br>Supported types: <ul> <li>
* PowerDistributionPanel</li>
* Displays a PowerDistribution. <br>Supported types: <ul> <li>
* PowerDistribution</li>
* </ul>
* <br>Custom properties:
* <table>
@@ -170,7 +170,7 @@ enum class BuiltInWidgets {
* <td>Whether or not to display the voltage and current draw</td></tr>
* </table>
*/
kPowerDistributionPanel,
kPowerDistribution,
/**
* Displays a SendableChooser with a dropdown combo box with a list of
* options.

View File

@@ -10,31 +10,31 @@
namespace frc {
class PowerDistributionPanel;
class PowerDistribution;
namespace sim {
/**
* Class to control a simulated Power Distribution Panel (PDP).
* Class to control a simulated Power Distribution Panel (PowerDistribution).
*/
class PDPSim {
class PowerDistributionSim {
public:
/**
* Constructs from a PDP module number (CAN ID).
* Constructs from a PowerDistribution module number (CAN ID).
*
* @param module module number
*/
explicit PDPSim(int module = 0);
explicit PowerDistributionSim(int module = 0);
/**
* Constructs from a PowerDistributionPanel object.
* Constructs from a PowerDistribution object.
*
* @param pdp PowerDistributionPanel to simulate
* @param pdp PowerDistribution to simulate
*/
explicit PDPSim(const PowerDistributionPanel& pdp);
explicit PowerDistributionSim(const PowerDistribution& pdp);
/**
* Register a callback to be run when the PDP is initialized.
* Register a callback to be run when the PowerDistribution is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
@@ -44,21 +44,22 @@ class PDPSim {
NotifyCallback callback, bool initialNotify);
/**
* Check whether the PDP has been initialized.
* Check whether the PowerDistribution has been initialized.
*
* @return true if initialized
*/
bool GetInitialized() const;
/**
* Define whether the PDP has been initialized.
* Define whether the PowerDistribution has been initialized.
*
* @param initialized whether this object is initialized
*/
void SetInitialized(bool initialized);
/**
* Register a callback to be run whenever the PDP temperature changes.
* Register a callback to be run whenever the PowerDistribution temperature
* changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
@@ -68,21 +69,22 @@ class PDPSim {
NotifyCallback callback, bool initialNotify);
/**
* Check the temperature of the PDP.
* Check the temperature of the PowerDistribution.
*
* @return the PDP temperature
* @return the PowerDistribution temperature
*/
double GetTemperature() const;
/**
* Define the PDP temperature.
* Define the PowerDistribution temperature.
*
* @param temperature the new PDP temperature
* @param temperature the new PowerDistribution temperature
*/
void SetTemperature(double temperature);
/**
* Register a callback to be run whenever the PDP voltage changes.
* Register a callback to be run whenever the PowerDistribution voltage
* changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
@@ -92,16 +94,16 @@ class PDPSim {
NotifyCallback callback, bool initialNotify);
/**
* Check the PDP voltage.
* Check the PowerDistribution voltage.
*
* @return the PDP voltage.
* @return the PowerDistribution voltage.
*/
double GetVoltage() const;
/**
* Set the PDP voltage.
* Set the PowerDistribution voltage.
*
* @param voltage the new PDP voltage
* @param voltage the new PowerDistribution voltage
*/
void SetVoltage(double voltage);
@@ -118,7 +120,7 @@ class PDPSim {
int channel, NotifyCallback callback, bool initialNotify);
/**
* Read the current in one of the PDP channels.
* Read the current in one of the PowerDistribution channels.
*
* @param channel the channel to check
* @return the current in the given channel
@@ -134,23 +136,25 @@ class PDPSim {
void SetCurrent(int channel, double current);
/**
* Read the current of all of the PDP channels.
* Read the current of all of the PowerDistribution channels.
*
* @param currents output array; set to the current in each channel. The
* array must be big enough to hold all the PDP channels
* array must be big enough to hold all the PowerDistribution
* channels
*/
void GetAllCurrents(double* currents) const;
/**
* Change the current in all of the PDP channels.
* Change the current in all of the PowerDistribution channels.
*
* @param currents array containing the current values for each channel. The
* array must be big enough to hold all the PDP channels
* array must be big enough to hold all the PowerDistribution
* channels
*/
void SetAllCurrents(const double* currents);
/**
* Reset all PDP simulation data.
* Reset all PowerDistribution simulation data.
*/
void ResetData();