[wpilib] Compressor: Add more Sendable data (#6687)

This commit is contained in:
Wispy
2024-06-03 09:47:17 -05:00
committed by GitHub
parent bdc42532ed
commit 5f8c842223
3 changed files with 22 additions and 1 deletions

View File

@@ -4,6 +4,8 @@
#include "frc/Compressor.h"
#include <frc/PneumaticHub.h>
#include <hal/FRCUsageReporting.h>
#include <hal/Ports.h>
#include <wpi/sendable/SendableBuilder.h>
@@ -14,7 +16,8 @@
using namespace frc;
Compressor::Compressor(int module, PneumaticsModuleType moduleType)
: m_module{PneumaticsBase::GetForType(module, moduleType)} {
: m_module{PneumaticsBase::GetForType(module, moduleType)},
m_moduleType{moduleType} {
if (!m_module->ReserveCompressor()) {
throw FRC_MakeError(err::ResourceAlreadyAllocated, "{}", module);
}
@@ -82,4 +85,14 @@ void Compressor::InitSendable(wpi::SendableBuilder& builder) {
"Enabled", [this] { return IsEnabled(); }, nullptr);
builder.AddBooleanProperty(
"Pressure switch", [this] { return GetPressureSwitchValue(); }, nullptr);
builder.AddDoubleProperty(
"Current (A)", [this] { return GetCurrent().value(); }, nullptr);
// These are not supported by the CTRE PCM
if (m_moduleType == PneumaticsModuleType::REVPH) {
builder.AddDoubleProperty(
"Analog Voltage", [this] { return GetAnalogVoltage().value(); },
nullptr);
builder.AddDoubleProperty(
"Pressure (PSI)", [this] { return GetPressure().value(); }, nullptr);
}
}

View File

@@ -175,6 +175,7 @@ class Compressor : public wpi::Sendable,
private:
std::shared_ptr<PneumaticsBase> m_module;
PneumaticsModuleType m_moduleType;
};
} // namespace frc

View File

@@ -24,6 +24,7 @@ import edu.wpi.first.util.sendable.SendableRegistry;
*/
public class Compressor implements Sendable, AutoCloseable {
private PneumaticsBase m_module;
private PneumaticsModuleType m_moduleType;
/**
* Constructs a compressor for a specified module and type.
@@ -34,6 +35,7 @@ public class Compressor implements Sendable, AutoCloseable {
@SuppressWarnings("this-escape")
public Compressor(int module, PneumaticsModuleType moduleType) {
m_module = PneumaticsBase.getForType(module, moduleType);
m_moduleType = moduleType;
if (!m_module.reserveCompressor()) {
m_module.close();
@@ -194,5 +196,10 @@ public class Compressor implements Sendable, AutoCloseable {
builder.setSmartDashboardType("Compressor");
builder.addBooleanProperty("Enabled", this::isEnabled, null);
builder.addBooleanProperty("Pressure switch", this::getPressureSwitchValue, null);
builder.addDoubleProperty("Current (A)", this::getCurrent, null);
if (m_moduleType == PneumaticsModuleType.REVPH) { // These are not supported by the CTRE PCM
builder.addDoubleProperty("Analog Voltage", this::getAnalogVoltage, null);
builder.addDoubleProperty("Pressure (PSI)", this::getPressure, null);
}
}
}