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.
|
|
|
|
|
|
|
|
|
|
#include "frc/Compressor.h"
|
|
|
|
|
|
2024-06-03 09:47:17 -05:00
|
|
|
#include <frc/PneumaticHub.h>
|
|
|
|
|
|
2021-09-16 18:50:27 -07:00
|
|
|
#include <hal/FRCUsageReporting.h>
|
|
|
|
|
#include <hal/Ports.h>
|
|
|
|
|
#include <wpi/sendable/SendableBuilder.h>
|
|
|
|
|
#include <wpi/sendable/SendableRegistry.h>
|
|
|
|
|
|
|
|
|
|
#include "frc/Errors.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc;
|
|
|
|
|
|
|
|
|
|
Compressor::Compressor(int module, PneumaticsModuleType moduleType)
|
2024-06-03 09:47:17 -05:00
|
|
|
: m_module{PneumaticsBase::GetForType(module, moduleType)},
|
|
|
|
|
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
|
|
|
|
|
|
|
|
HAL_Report(HALUsageReporting::kResourceType_Compressor, module + 1);
|
|
|
|
|
wpi::SendableRegistry::AddLW(this, "Compressor", module);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Compressor::Compressor(PneumaticsModuleType moduleType)
|
|
|
|
|
: Compressor{PneumaticsBase::GetDefaultForType(moduleType), moduleType} {}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 13:41:35 -08:00
|
|
|
units::ampere_t Compressor::GetCurrent() const {
|
2021-09-16 18:50:27 -07:00
|
|
|
return m_module->GetCompressorCurrent();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 13:41:35 -08:00
|
|
|
units::volt_t Compressor::GetAnalogVoltage() const {
|
|
|
|
|
return m_module->GetAnalogVoltage(0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 22:04:56 -07:00
|
|
|
units::pounds_per_square_inch_t Compressor::GetPressure() const {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 22:04:56 -07:00
|
|
|
void Compressor::EnableAnalog(units::pounds_per_square_inch_t minPressure,
|
|
|
|
|
units::pounds_per_square_inch_t maxPressure) {
|
|
|
|
|
m_module->EnableCompressorAnalog(minPressure, maxPressure);
|
2021-11-23 20:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
2021-12-31 22:04:56 -07:00
|
|
|
void Compressor::EnableHybrid(units::pounds_per_square_inch_t minPressure,
|
|
|
|
|
units::pounds_per_square_inch_t maxPressure) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compressor::InitSendable(wpi::SendableBuilder& builder) {
|
|
|
|
|
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
|
|
|
}
|