mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
[wpilib] Fix PowerDistribution.GetAllCurrents() (#6025)
This commit is contained in:
@@ -64,6 +64,13 @@ PowerDistribution::~PowerDistribution() {
|
||||
}
|
||||
}
|
||||
|
||||
int PowerDistribution::GetNumChannels() const {
|
||||
int32_t status = 0;
|
||||
int32_t size = HAL_GetPowerDistributionNumChannels(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return size;
|
||||
}
|
||||
|
||||
double PowerDistribution::GetVoltage() const {
|
||||
int32_t status = 0;
|
||||
double voltage = HAL_GetPowerDistributionVoltage(m_handle, &status);
|
||||
@@ -87,6 +94,17 @@ double PowerDistribution::GetCurrent(int channel) const {
|
||||
return current;
|
||||
}
|
||||
|
||||
std::vector<double> PowerDistribution::GetAllCurrents() const {
|
||||
int32_t status = 0;
|
||||
int32_t size = GetNumChannels();
|
||||
std::vector<double> currents(size);
|
||||
|
||||
HAL_GetPowerDistributionAllChannelCurrents(m_handle, currents.data(), size,
|
||||
&status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
return currents;
|
||||
}
|
||||
|
||||
double PowerDistribution::GetTotalCurrent() const {
|
||||
int32_t status = 0;
|
||||
double current = HAL_GetPowerDistributionTotalCurrent(m_handle, &status);
|
||||
@@ -300,9 +318,7 @@ PowerDistribution::StickyFaults PowerDistribution::GetStickyFaults() const {
|
||||
|
||||
void PowerDistribution::InitSendable(wpi::SendableBuilder& builder) {
|
||||
builder.SetSmartDashboardType("PowerDistribution");
|
||||
int32_t status = 0;
|
||||
int numChannels = HAL_GetPowerDistributionNumChannels(m_handle, &status);
|
||||
FRC_ReportError(status, "Module {}", m_module);
|
||||
int numChannels = GetNumChannels();
|
||||
// Use manual reads to avoid printing errors
|
||||
for (int i = 0; i < numChannels; ++i) {
|
||||
builder.AddDoubleProperty(
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <hal/Types.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
@@ -50,6 +52,13 @@ class PowerDistribution : public wpi::Sendable,
|
||||
PowerDistribution(PowerDistribution&&) = default;
|
||||
PowerDistribution& operator=(PowerDistribution&&) = default;
|
||||
|
||||
/**
|
||||
* Gets the number of channels for this power distribution object.
|
||||
*
|
||||
* @return Number of output channels (16 for PDP, 24 for PDH).
|
||||
*/
|
||||
int GetNumChannels() const;
|
||||
|
||||
/**
|
||||
* Query the input voltage of the PDP/PDH.
|
||||
*
|
||||
@@ -75,6 +84,13 @@ class PowerDistribution : public wpi::Sendable,
|
||||
*/
|
||||
double GetCurrent(int channel) const;
|
||||
|
||||
/**
|
||||
* Query all currents of the PDP.
|
||||
*
|
||||
* @return The current of each channel in Amperes
|
||||
*/
|
||||
std::vector<double> GetAllCurrents() const;
|
||||
|
||||
/**
|
||||
* Query the total current of all monitored PDP/PDH channels.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user