2021-09-16 18:50:27 -07:00
|
|
|
// 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.
|
|
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/hardware/pneumatic/Compressor.hpp"
|
2021-09-16 18:50:27 -07:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/hal/Ports.h"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/hardware/pneumatic/PneumaticHub.hpp"
|
|
|
|
|
#include "wpi/system/Errors.hpp"
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/util/sendable/SendableBuilder.hpp"
|
|
|
|
|
#include "wpi/util/sendable/SendableRegistry.hpp"
|
2021-09-16 18:50:27 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi;
|
2021-09-16 18:50:27 -07:00
|
|
|
|
2025-02-25 19:07:01 -08:00
|
|
|
Compressor::Compressor(int busId, int module, PneumaticsModuleType moduleType)
|
|
|
|
|
: m_module{PneumaticsBase::GetForType(busId, module, moduleType)},
|
2024-06-03 09:47:17 -05:00
|
|
|
m_moduleType{moduleType} {
|
2021-09-16 18:50:27 -07:00
|
|
|
if (!m_module->ReserveCompressor()) {
|
|
|
|
|
throw FRC_MakeError(err::ResourceAlreadyAllocated, "{}", module);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
m_module->EnableCompressorDigital();
|
2021-09-16 18:50:27 -07:00
|
|
|
|
2025-02-07 12:37:23 -08:00
|
|
|
m_module->ReportUsage("Compressor", "");
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::SendableRegistry::Add(this, "Compressor", module);
|
2021-09-16 18:50:27 -07:00
|
|
|
}
|
|
|
|
|
|
2025-02-25 19:07:01 -08:00
|
|
|
Compressor::Compressor(int busId, PneumaticsModuleType moduleType)
|
|
|
|
|
: Compressor{busId, PneumaticsBase::GetDefaultForType(moduleType),
|
|
|
|
|
moduleType} {}
|
2021-09-16 18:50:27 -07:00
|
|
|
|
|
|
|
|
Compressor::~Compressor() {
|
2022-03-01 11:10:45 -08:00
|
|
|
if (m_module) {
|
|
|
|
|
m_module->UnreserveCompressor();
|
|
|
|
|
}
|
2021-09-16 18:50:27 -07:00
|
|
|
}
|
|
|
|
|
|
2022-04-08 21:31:08 -07:00
|
|
|
bool Compressor::IsEnabled() const {
|
2021-09-16 18:50:27 -07:00
|
|
|
return m_module->GetCompressor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Compressor::GetPressureSwitchValue() const {
|
|
|
|
|
return m_module->GetPressureSwitch();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::ampere_t Compressor::GetCurrent() const {
|
2021-09-16 18:50:27 -07:00
|
|
|
return m_module->GetCompressorCurrent();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::volt_t Compressor::GetAnalogVoltage() const {
|
2021-12-19 13:41:35 -08:00
|
|
|
return m_module->GetAnalogVoltage(0);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::pounds_per_square_inch_t Compressor::GetPressure() const {
|
2021-12-31 22:04:56 -07:00
|
|
|
return m_module->GetPressure(0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
void Compressor::Disable() {
|
|
|
|
|
m_module->DisableCompressor();
|
2021-09-16 18:50:27 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
void Compressor::EnableDigital() {
|
|
|
|
|
m_module->EnableCompressorDigital();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
void Compressor::EnableAnalog(wpi::units::pounds_per_square_inch_t minPressure,
|
|
|
|
|
wpi::units::pounds_per_square_inch_t maxPressure) {
|
2021-12-31 22:04:56 -07:00
|
|
|
m_module->EnableCompressorAnalog(minPressure, maxPressure);
|
2021-11-23 20:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
void Compressor::EnableHybrid(wpi::units::pounds_per_square_inch_t minPressure,
|
|
|
|
|
wpi::units::pounds_per_square_inch_t maxPressure) {
|
2021-12-31 22:04:56 -07:00
|
|
|
m_module->EnableCompressorHybrid(minPressure, maxPressure);
|
2021-11-23 20:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CompressorConfigType Compressor::GetConfigType() const {
|
|
|
|
|
return m_module->GetCompressorConfigType();
|
2021-09-16 18:50:27 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
void Compressor::InitSendable(wpi::util::SendableBuilder& builder) {
|
2021-09-16 18:50:27 -07:00
|
|
|
builder.SetSmartDashboardType("Compressor");
|
|
|
|
|
builder.AddBooleanProperty(
|
2022-10-15 16:33:14 -07:00
|
|
|
"Enabled", [this] { return IsEnabled(); }, nullptr);
|
2021-09-16 18:50:27 -07:00
|
|
|
builder.AddBooleanProperty(
|
2022-10-15 16:33:14 -07:00
|
|
|
"Pressure switch", [this] { return GetPressureSwitchValue(); }, nullptr);
|
2024-06-03 09:47:17 -05:00
|
|
|
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);
|
|
|
|
|
}
|
2021-09-16 18:50:27 -07:00
|
|
|
}
|