2021-10-10 20:04:50 -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/PneumaticHub.hpp"
|
2021-10-10 20:04:50 -07:00
|
|
|
|
2022-04-30 00:07:37 -07:00
|
|
|
#include <array>
|
2024-09-20 17:43:39 -07:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
2022-04-30 00:07:37 -07:00
|
|
|
|
2022-02-01 22:27:43 -06:00
|
|
|
#include <fmt/format.h>
|
2025-11-07 19:57:55 -05:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/hal/Ports.h"
|
|
|
|
|
#include "wpi/hal/REVPH.h"
|
|
|
|
|
#include "wpi/hal/UsageReporting.h"
|
|
|
|
|
#include "wpi/hardware/pneumatic/Compressor.hpp"
|
|
|
|
|
#include "wpi/hardware/pneumatic/DoubleSolenoid.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/hardware/pneumatic/Solenoid.hpp"
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/opmode/RobotBase.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/system/Errors.hpp"
|
|
|
|
|
#include "wpi/util/NullDeleter.hpp"
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/util/SensorUtil.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/StackTrace.hpp"
|
2021-10-10 20:04:50 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi;
|
2021-10-10 20:04:50 -07:00
|
|
|
|
2021-12-31 22:04:56 -07:00
|
|
|
/** Converts volts to PSI per the REV Analog Pressure Sensor datasheet. */
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::pounds_per_square_inch_t VoltsToPSI(wpi::units::volt_t sensorVoltage,
|
|
|
|
|
wpi::units::volt_t supplyVoltage) {
|
|
|
|
|
return wpi::units::pounds_per_square_inch_t{
|
2023-12-03 16:21:32 -08:00
|
|
|
250 * (sensorVoltage.value() / supplyVoltage.value()) - 25};
|
2021-12-31 22:04:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Converts PSI to volts per the REV Analog Pressure Sensor datasheet. */
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::volt_t PSIToVolts(wpi::units::pounds_per_square_inch_t pressure,
|
|
|
|
|
wpi::units::volt_t supplyVoltage) {
|
|
|
|
|
return wpi::units::volt_t{supplyVoltage.value() *
|
2023-12-03 16:21:32 -08:00
|
|
|
(0.004 * pressure.value() + 0.1)};
|
2021-12-31 22:04:56 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::mutex PneumaticHub::m_handleLock;
|
|
|
|
|
std::unique_ptr<wpi::util::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>
|
2025-02-25 19:07:01 -08:00
|
|
|
PneumaticHub::m_handleMaps = nullptr;
|
2021-10-10 20:04:50 -07:00
|
|
|
|
|
|
|
|
// Always called under lock, so we can avoid the double lock from the magic
|
|
|
|
|
// static
|
2025-02-25 19:07:01 -08:00
|
|
|
std::weak_ptr<PneumaticHub::DataStore>& PneumaticHub::GetDataStore(int busId,
|
|
|
|
|
int module) {
|
|
|
|
|
int32_t numBuses = HAL_GetNumCanBuses();
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_AssertMessage(busId >= 0 && busId < numBuses,
|
2025-02-25 19:07:01 -08:00
|
|
|
"Bus {} out of range. Must be [0-{}).", busId, numBuses);
|
|
|
|
|
if (!m_handleMaps) {
|
|
|
|
|
m_handleMaps = std::make_unique<
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>(numBuses);
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
2025-02-25 19:07:01 -08:00
|
|
|
return m_handleMaps[busId][module];
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
class PneumaticHub::DataStore {
|
2021-10-10 20:04:50 -07:00
|
|
|
public:
|
2025-02-25 19:07:01 -08:00
|
|
|
explicit DataStore(int busId, int module, const char* stackTrace) {
|
2021-10-10 20:04:50 -07:00
|
|
|
int32_t status = 0;
|
2025-02-25 19:07:01 -08:00
|
|
|
HAL_REVPHHandle handle =
|
|
|
|
|
HAL_InitializeREVPH(busId, module, stackTrace, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_CheckErrorStatus(status, "Module {}", module);
|
2025-02-25 19:07:01 -08:00
|
|
|
m_moduleObject = PneumaticHub{busId, handle, module};
|
2021-10-10 20:04:50 -07:00
|
|
|
m_moduleObject.m_dataStore =
|
2025-11-07 20:00:05 -05:00
|
|
|
std::shared_ptr<DataStore>{this, wpi::util::NullDeleter<DataStore>()};
|
2022-01-03 13:09:30 -06:00
|
|
|
|
|
|
|
|
auto version = m_moduleObject.GetVersion();
|
2022-02-01 22:27:43 -06:00
|
|
|
|
|
|
|
|
// Check PH firmware version
|
2022-01-03 13:09:30 -06:00
|
|
|
if (version.FirmwareMajor > 0 && version.FirmwareMajor < 22) {
|
2025-11-07 20:00:43 -05:00
|
|
|
throw WPILIB_MakeError(
|
2022-01-03 13:09:30 -06:00
|
|
|
err::AssertionFailure,
|
|
|
|
|
"The Pneumatic Hub has firmware version {}.{}.{}, and must be "
|
|
|
|
|
"updated to version 2022.0.0 or later using the REV Hardware Client",
|
|
|
|
|
version.FirmwareMajor, version.FirmwareMinor, version.FirmwareFix);
|
|
|
|
|
}
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~DataStore() noexcept { HAL_FreeREVPH(m_moduleObject.m_handle); }
|
|
|
|
|
|
|
|
|
|
DataStore(DataStore&&) = delete;
|
|
|
|
|
DataStore& operator=(DataStore&&) = delete;
|
|
|
|
|
|
|
|
|
|
private:
|
2021-10-29 00:00:31 -07:00
|
|
|
friend class PneumaticHub;
|
2021-10-10 20:04:50 -07:00
|
|
|
uint32_t m_reservedMask{0};
|
|
|
|
|
bool m_compressorReserved{false};
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::mutex m_reservedLock;
|
2025-02-25 19:07:01 -08:00
|
|
|
PneumaticHub m_moduleObject{0, HAL_kInvalidHandle, 0};
|
2025-11-07 20:00:05 -05:00
|
|
|
std::array<wpi::units::millisecond_t, 16> m_oneShotDurMs{0_ms};
|
2021-10-10 20:04:50 -07:00
|
|
|
};
|
|
|
|
|
|
2025-02-25 19:07:01 -08:00
|
|
|
PneumaticHub::PneumaticHub(int busId)
|
|
|
|
|
: PneumaticHub{busId, SensorUtil::GetDefaultREVPHModule()} {}
|
2021-10-10 20:04:50 -07:00
|
|
|
|
2025-02-25 19:07:01 -08:00
|
|
|
PneumaticHub::PneumaticHub(int busId, int module) {
|
2025-11-07 20:00:05 -05:00
|
|
|
std::string stackTrace = wpi::util::GetStackTrace(1);
|
2021-10-10 20:04:50 -07:00
|
|
|
std::scoped_lock lock(m_handleLock);
|
2025-02-25 19:07:01 -08:00
|
|
|
auto& res = GetDataStore(busId, module);
|
2021-10-10 20:04:50 -07:00
|
|
|
m_dataStore = res.lock();
|
|
|
|
|
if (!m_dataStore) {
|
2025-02-25 19:07:01 -08:00
|
|
|
m_dataStore =
|
|
|
|
|
std::make_shared<DataStore>(busId, module, stackTrace.c_str());
|
2021-10-10 20:04:50 -07:00
|
|
|
res = m_dataStore;
|
|
|
|
|
}
|
|
|
|
|
m_handle = m_dataStore->m_moduleObject.m_handle;
|
|
|
|
|
m_module = module;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-25 19:07:01 -08:00
|
|
|
PneumaticHub::PneumaticHub(int /* busId */, HAL_REVPHHandle handle, int module)
|
2021-10-10 20:04:50 -07:00
|
|
|
: m_handle{handle}, m_module{module} {}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
bool PneumaticHub::GetCompressor() const {
|
2021-10-10 20:04:50 -07:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto result = HAL_GetREVPHCompressor(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-10-10 20:04:50 -07:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
void PneumaticHub::DisableCompressor() {
|
2021-10-10 20:04:50 -07:00
|
|
|
int32_t status = 0;
|
2021-11-23 20:32:02 -08:00
|
|
|
HAL_SetREVPHClosedLoopControlDisabled(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
void PneumaticHub::EnableCompressorDigital() {
|
2021-10-10 20:04:50 -07:00
|
|
|
int32_t status = 0;
|
2021-11-23 20:32:02 -08:00
|
|
|
HAL_SetREVPHClosedLoopControlDigital(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-11-23 20:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
2021-12-31 22:04:56 -07:00
|
|
|
void PneumaticHub::EnableCompressorAnalog(
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::pounds_per_square_inch_t minPressure,
|
|
|
|
|
wpi::units::pounds_per_square_inch_t maxPressure) {
|
2021-12-31 22:04:56 -07:00
|
|
|
if (minPressure >= maxPressure) {
|
2025-11-07 20:00:43 -05:00
|
|
|
throw WPILIB_MakeError(err::InvalidParameter,
|
2024-08-17 10:44:34 -04:00
|
|
|
"maxPressure must be greater than minPressure");
|
2021-12-31 22:04:56 -07:00
|
|
|
}
|
|
|
|
|
if (minPressure < 0_psi || minPressure > 120_psi) {
|
2025-11-07 20:00:43 -05:00
|
|
|
throw WPILIB_MakeError(err::ParameterOutOfRange,
|
2021-12-31 22:04:56 -07:00
|
|
|
"minPressure must be between 0 and 120 PSI, got {}",
|
|
|
|
|
minPressure);
|
|
|
|
|
}
|
|
|
|
|
if (maxPressure < 0_psi || maxPressure > 120_psi) {
|
2025-11-07 20:00:43 -05:00
|
|
|
throw WPILIB_MakeError(err::ParameterOutOfRange,
|
2021-12-31 22:04:56 -07:00
|
|
|
"maxPressure must be between 0 and 120 PSI, got {}",
|
|
|
|
|
maxPressure);
|
|
|
|
|
}
|
2023-02-24 21:55:50 -06:00
|
|
|
|
|
|
|
|
// Send the voltage as it would be if the 5V rail was at exactly 5V.
|
|
|
|
|
// The firmware will compensate for the real 5V rail voltage, which
|
|
|
|
|
// can fluctuate somewhat over time.
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V);
|
|
|
|
|
wpi::units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V);
|
2023-02-24 21:55:50 -06:00
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
int32_t status = 0;
|
2021-12-19 13:41:35 -08:00
|
|
|
HAL_SetREVPHClosedLoopControlAnalog(m_handle, minAnalogVoltage.value(),
|
|
|
|
|
maxAnalogVoltage.value(), &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-11-23 20:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
2021-12-31 22:04:56 -07:00
|
|
|
void PneumaticHub::EnableCompressorHybrid(
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::pounds_per_square_inch_t minPressure,
|
|
|
|
|
wpi::units::pounds_per_square_inch_t maxPressure) {
|
2021-12-31 22:04:56 -07:00
|
|
|
if (minPressure >= maxPressure) {
|
2025-11-07 20:00:43 -05:00
|
|
|
throw WPILIB_MakeError(err::InvalidParameter,
|
2024-08-17 10:44:34 -04:00
|
|
|
"maxPressure must be greater than minPressure");
|
2021-12-31 22:04:56 -07:00
|
|
|
}
|
|
|
|
|
if (minPressure < 0_psi || minPressure > 120_psi) {
|
2025-11-07 20:00:43 -05:00
|
|
|
throw WPILIB_MakeError(err::ParameterOutOfRange,
|
2021-12-31 22:04:56 -07:00
|
|
|
"minPressure must be between 0 and 120 PSI, got {}",
|
|
|
|
|
minPressure);
|
|
|
|
|
}
|
|
|
|
|
if (maxPressure < 0_psi || maxPressure > 120_psi) {
|
2025-11-07 20:00:43 -05:00
|
|
|
throw WPILIB_MakeError(err::ParameterOutOfRange,
|
2021-12-31 22:04:56 -07:00
|
|
|
"maxPressure must be between 0 and 120 PSI, got {}",
|
|
|
|
|
maxPressure);
|
|
|
|
|
}
|
2023-02-24 21:55:50 -06:00
|
|
|
|
|
|
|
|
// Send the voltage as it would be if the 5V rail was at exactly 5V.
|
|
|
|
|
// The firmware will compensate for the real 5V rail voltage, which
|
|
|
|
|
// can fluctuate somewhat over time.
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V);
|
|
|
|
|
wpi::units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V);
|
2023-02-24 21:55:50 -06:00
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
int32_t status = 0;
|
2021-12-19 13:41:35 -08:00
|
|
|
HAL_SetREVPHClosedLoopControlHybrid(m_handle, minAnalogVoltage.value(),
|
|
|
|
|
maxAnalogVoltage.value(), &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-11-23 20:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CompressorConfigType PneumaticHub::GetCompressorConfigType() const {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
auto result = HAL_GetREVPHCompressorConfig(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-11-23 20:32:02 -08:00
|
|
|
return static_cast<CompressorConfigType>(result);
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
bool PneumaticHub::GetPressureSwitch() const {
|
2021-10-10 20:04:50 -07:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto result = HAL_GetREVPHPressureSwitch(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-10-10 20:04:50 -07:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::ampere_t PneumaticHub::GetCompressorCurrent() const {
|
2021-10-10 20:04:50 -07:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto result = HAL_GetREVPHCompressorCurrent(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2025-11-07 20:00:05 -05:00
|
|
|
return wpi::units::ampere_t{result};
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
void PneumaticHub::SetSolenoids(int mask, int values) {
|
2021-10-10 20:04:50 -07:00
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_SetREVPHSolenoids(m_handle, mask, values, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
int PneumaticHub::GetSolenoids() const {
|
2021-10-10 20:04:50 -07:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto result = HAL_GetREVPHSolenoids(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-10-10 20:04:50 -07:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
int PneumaticHub::GetModuleNumber() const {
|
2021-10-10 20:04:50 -07:00
|
|
|
return m_module;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
int PneumaticHub::GetSolenoidDisabledList() const {
|
2021-12-19 13:41:35 -08:00
|
|
|
int32_t status = 0;
|
2024-07-29 10:59:49 -04:00
|
|
|
auto result = HAL_GetREVPHSolenoidDisabledList(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2024-07-29 10:59:49 -04:00
|
|
|
return result;
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
void PneumaticHub::FireOneShot(int index) {
|
2021-12-19 13:41:35 -08:00
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_FireREVPHOneShot(m_handle, index,
|
|
|
|
|
m_dataStore->m_oneShotDurMs[index].value(), &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
void PneumaticHub::SetOneShotDuration(int index, wpi::units::second_t duration) {
|
2021-12-19 13:41:35 -08:00
|
|
|
m_dataStore->m_oneShotDurMs[index] = duration;
|
2021-10-10 20:04:50 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
bool PneumaticHub::CheckSolenoidChannel(int channel) const {
|
2021-10-10 20:04:50 -07:00
|
|
|
return HAL_CheckREVPHSolenoidChannel(channel);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
int PneumaticHub::CheckAndReserveSolenoids(int mask) {
|
2021-10-10 20:04:50 -07:00
|
|
|
std::scoped_lock lock{m_dataStore->m_reservedLock};
|
|
|
|
|
uint32_t uMask = static_cast<uint32_t>(mask);
|
|
|
|
|
if ((m_dataStore->m_reservedMask & uMask) != 0) {
|
|
|
|
|
return m_dataStore->m_reservedMask & uMask;
|
|
|
|
|
}
|
|
|
|
|
m_dataStore->m_reservedMask |= uMask;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
void PneumaticHub::UnreserveSolenoids(int mask) {
|
2021-10-10 20:04:50 -07:00
|
|
|
std::scoped_lock lock{m_dataStore->m_reservedLock};
|
|
|
|
|
m_dataStore->m_reservedMask &= ~(static_cast<uint32_t>(mask));
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
bool PneumaticHub::ReserveCompressor() {
|
2021-10-10 20:04:50 -07:00
|
|
|
std::scoped_lock lock{m_dataStore->m_reservedLock};
|
|
|
|
|
if (m_dataStore->m_compressorReserved) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
m_dataStore->m_compressorReserved = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
void PneumaticHub::UnreserveCompressor() {
|
2021-10-10 20:04:50 -07:00
|
|
|
std::scoped_lock lock{m_dataStore->m_reservedLock};
|
|
|
|
|
m_dataStore->m_compressorReserved = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 13:41:35 -08:00
|
|
|
PneumaticHub::Version PneumaticHub::GetVersion() const {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_REVPHVersion halVersions;
|
|
|
|
|
std::memset(&halVersions, 0, sizeof(halVersions));
|
|
|
|
|
HAL_GetREVPHVersion(m_handle, &halVersions, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-12-19 13:41:35 -08:00
|
|
|
PneumaticHub::Version versions;
|
|
|
|
|
static_assert(sizeof(halVersions) == sizeof(versions));
|
|
|
|
|
static_assert(std::is_standard_layout_v<decltype(versions)>);
|
|
|
|
|
static_assert(std::is_trivial_v<decltype(versions)>);
|
|
|
|
|
std::memcpy(&versions, &halVersions, sizeof(versions));
|
|
|
|
|
return versions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PneumaticHub::Faults PneumaticHub::GetFaults() const {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_REVPHFaults halFaults;
|
|
|
|
|
std::memset(&halFaults, 0, sizeof(halFaults));
|
|
|
|
|
HAL_GetREVPHFaults(m_handle, &halFaults, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-12-19 13:41:35 -08:00
|
|
|
PneumaticHub::Faults faults;
|
|
|
|
|
static_assert(sizeof(halFaults) == sizeof(faults));
|
|
|
|
|
static_assert(std::is_standard_layout_v<decltype(faults)>);
|
|
|
|
|
static_assert(std::is_trivial_v<decltype(faults)>);
|
|
|
|
|
std::memcpy(&faults, &halFaults, sizeof(faults));
|
|
|
|
|
return faults;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PneumaticHub::StickyFaults PneumaticHub::GetStickyFaults() const {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_REVPHStickyFaults halStickyFaults;
|
|
|
|
|
std::memset(&halStickyFaults, 0, sizeof(halStickyFaults));
|
|
|
|
|
HAL_GetREVPHStickyFaults(m_handle, &halStickyFaults, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-12-19 13:41:35 -08:00
|
|
|
PneumaticHub::StickyFaults stickyFaults;
|
|
|
|
|
static_assert(sizeof(halStickyFaults) == sizeof(stickyFaults));
|
|
|
|
|
static_assert(std::is_standard_layout_v<decltype(stickyFaults)>);
|
|
|
|
|
static_assert(std::is_trivial_v<decltype(stickyFaults)>);
|
|
|
|
|
std::memcpy(&stickyFaults, &halStickyFaults, sizeof(stickyFaults));
|
|
|
|
|
return stickyFaults;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-23 12:14:13 -08:00
|
|
|
bool PneumaticHub::Faults::GetChannelFault(int channel) const {
|
|
|
|
|
switch (channel) {
|
|
|
|
|
case 0:
|
|
|
|
|
return Channel0Fault != 0;
|
|
|
|
|
case 1:
|
|
|
|
|
return Channel1Fault != 0;
|
|
|
|
|
case 2:
|
|
|
|
|
return Channel2Fault != 0;
|
|
|
|
|
case 3:
|
|
|
|
|
return Channel3Fault != 0;
|
|
|
|
|
case 4:
|
|
|
|
|
return Channel4Fault != 0;
|
|
|
|
|
case 5:
|
|
|
|
|
return Channel5Fault != 0;
|
|
|
|
|
case 6:
|
|
|
|
|
return Channel6Fault != 0;
|
|
|
|
|
case 7:
|
|
|
|
|
return Channel7Fault != 0;
|
|
|
|
|
case 8:
|
|
|
|
|
return Channel8Fault != 0;
|
|
|
|
|
case 9:
|
|
|
|
|
return Channel9Fault != 0;
|
|
|
|
|
case 10:
|
|
|
|
|
return Channel10Fault != 0;
|
|
|
|
|
case 11:
|
|
|
|
|
return Channel11Fault != 0;
|
|
|
|
|
case 12:
|
|
|
|
|
return Channel12Fault != 0;
|
|
|
|
|
case 13:
|
|
|
|
|
return Channel13Fault != 0;
|
|
|
|
|
case 14:
|
|
|
|
|
return Channel14Fault != 0;
|
|
|
|
|
case 15:
|
|
|
|
|
return Channel15Fault != 0;
|
|
|
|
|
default:
|
2025-11-07 20:00:43 -05:00
|
|
|
throw WPILIB_MakeError(err::ChannelIndexOutOfRange,
|
2023-12-23 12:14:13 -08:00
|
|
|
"Pneumatics fault channel out of bounds!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 13:41:35 -08:00
|
|
|
void PneumaticHub::ClearStickyFaults() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
HAL_ClearREVPHStickyFaults(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-12-19 13:41:35 -08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::volt_t PneumaticHub::GetInputVoltage() const {
|
2021-12-19 13:41:35 -08:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto voltage = HAL_GetREVPHVoltage(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2025-11-07 20:00:05 -05:00
|
|
|
return wpi::units::volt_t{voltage};
|
2021-12-19 13:41:35 -08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::volt_t PneumaticHub::Get5VRegulatedVoltage() const {
|
2021-12-19 13:41:35 -08:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto voltage = HAL_GetREVPH5VVoltage(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2025-11-07 20:00:05 -05:00
|
|
|
return wpi::units::volt_t{voltage};
|
2021-12-19 13:41:35 -08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::ampere_t PneumaticHub::GetSolenoidsTotalCurrent() const {
|
2021-12-19 13:41:35 -08:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto current = HAL_GetREVPHSolenoidCurrent(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2025-11-07 20:00:05 -05:00
|
|
|
return wpi::units::ampere_t{current};
|
2021-12-19 13:41:35 -08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::volt_t PneumaticHub::GetSolenoidsVoltage() const {
|
2021-12-19 13:41:35 -08:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto voltage = HAL_GetREVPHSolenoidVoltage(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2025-11-07 20:00:05 -05:00
|
|
|
return wpi::units::volt_t{voltage};
|
2021-12-19 13:41:35 -08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::volt_t PneumaticHub::GetAnalogVoltage(int channel) const {
|
2021-12-19 13:41:35 -08:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto voltage = HAL_GetREVPHAnalogVoltage(m_handle, channel, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2025-11-07 20:00:05 -05:00
|
|
|
return wpi::units::volt_t{voltage};
|
2021-12-19 13:41:35 -08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::units::pounds_per_square_inch_t PneumaticHub::GetPressure(int channel) const {
|
2021-12-31 22:04:56 -07:00
|
|
|
int32_t status = 0;
|
|
|
|
|
auto sensorVoltage = HAL_GetREVPHAnalogVoltage(m_handle, channel, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2021-12-31 22:04:56 -07:00
|
|
|
auto supplyVoltage = HAL_GetREVPH5VVoltage(m_handle, &status);
|
2025-11-07 20:00:43 -05:00
|
|
|
WPILIB_ReportError(status, "Module {}", m_module);
|
2025-11-07 20:00:05 -05:00
|
|
|
return VoltsToPSI(wpi::units::volt_t{sensorVoltage}, wpi::units::volt_t{supplyVoltage});
|
2021-12-31 22:04:56 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
Solenoid PneumaticHub::MakeSolenoid(int channel) {
|
2021-10-10 20:04:50 -07:00
|
|
|
return Solenoid{m_module, PneumaticsModuleType::REVPH, channel};
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
DoubleSolenoid PneumaticHub::MakeDoubleSolenoid(int forwardChannel,
|
|
|
|
|
int reverseChannel) {
|
2021-10-10 20:04:50 -07:00
|
|
|
return DoubleSolenoid{m_module, PneumaticsModuleType::REVPH, forwardChannel,
|
|
|
|
|
reverseChannel};
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:00:31 -07:00
|
|
|
Compressor PneumaticHub::MakeCompressor() {
|
2021-10-10 20:04:50 -07:00
|
|
|
return Compressor{m_module, PneumaticsModuleType::REVPH};
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 12:37:23 -08:00
|
|
|
void PneumaticHub::ReportUsage(std::string_view device, std::string_view data) {
|
|
|
|
|
HAL_ReportUsage(fmt::format("PH[{}]/{}", m_module, device), data);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-25 19:07:01 -08:00
|
|
|
std::shared_ptr<PneumaticsBase> PneumaticHub::GetForModule(int busId,
|
|
|
|
|
int module) {
|
2025-11-07 20:00:05 -05:00
|
|
|
std::string stackTrace = wpi::util::GetStackTrace(1);
|
2021-10-10 20:04:50 -07:00
|
|
|
std::scoped_lock lock(m_handleLock);
|
2025-02-25 19:07:01 -08:00
|
|
|
auto& res = GetDataStore(busId, module);
|
2021-10-10 20:04:50 -07:00
|
|
|
std::shared_ptr<DataStore> dataStore = res.lock();
|
|
|
|
|
if (!dataStore) {
|
2025-02-25 19:07:01 -08:00
|
|
|
dataStore = std::make_shared<DataStore>(busId, module, stackTrace.c_str());
|
2021-10-10 20:04:50 -07:00
|
|
|
res = dataStore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::shared_ptr<PneumaticsBase>{dataStore, &dataStore->m_moduleObject};
|
|
|
|
|
}
|