From edf4ded4128fa2beaed7b2fa3fd405828defb682 Mon Sep 17 00:00:00 2001 From: Noah Andrews Date: Fri, 24 Feb 2023 21:55:50 -0600 Subject: [PATCH] [wpilib] PH: Revert to 5V rail being fixed 5V (#5122) --- wpilibc/src/main/native/cpp/PneumaticHub.cpp | 22 ++++++++++++------- .../edu/wpi/first/wpilibj/PneumaticHub.java | 16 ++++++++++---- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/wpilibc/src/main/native/cpp/PneumaticHub.cpp b/wpilibc/src/main/native/cpp/PneumaticHub.cpp index f8c798489e..34b1d81f3c 100644 --- a/wpilibc/src/main/native/cpp/PneumaticHub.cpp +++ b/wpilibc/src/main/native/cpp/PneumaticHub.cpp @@ -161,11 +161,14 @@ void PneumaticHub::EnableCompressorAnalog( "maxPressure must be between 0 and 120 PSI, got {}", maxPressure); } + + // 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. + units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V); + units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V); + int32_t status = 0; - units::volt_t minAnalogVoltage = - PSIToVolts(minPressure, Get5VRegulatedVoltage()); - units::volt_t maxAnalogVoltage = - PSIToVolts(maxPressure, Get5VRegulatedVoltage()); HAL_SetREVPHClosedLoopControlAnalog(m_handle, minAnalogVoltage.value(), maxAnalogVoltage.value(), &status); FRC_ReportError(status, "Module {}", m_module); @@ -188,11 +191,14 @@ void PneumaticHub::EnableCompressorHybrid( "maxPressure must be between 0 and 120 PSI, got {}", maxPressure); } + + // 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. + units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V); + units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V); + int32_t status = 0; - units::volt_t minAnalogVoltage = - PSIToVolts(minPressure, Get5VRegulatedVoltage()); - units::volt_t maxAnalogVoltage = - PSIToVolts(maxPressure, Get5VRegulatedVoltage()); HAL_SetREVPHClosedLoopControlHybrid(m_handle, minAnalogVoltage.value(), maxAnalogVoltage.value(), &status); FRC_ReportError(status, "Module {}", m_module); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java index 72b3b1b000..b7df47f0f3 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/PneumaticHub.java @@ -294,8 +294,12 @@ public class PneumaticHub implements PneumaticsBase { throw new IllegalArgumentException( "maxPressure must be between 0 and 120 PSI, got " + maxPressure); } - double minAnalogVoltage = psiToVolts(minPressure, get5VRegulatedVoltage()); - double maxAnalogVoltage = psiToVolts(maxPressure, get5VRegulatedVoltage()); + + // 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. + double minAnalogVoltage = psiToVolts(minPressure, 5); + double maxAnalogVoltage = psiToVolts(maxPressure, 5); REVPHJNI.setClosedLoopControlAnalog(m_handle, minAnalogVoltage, maxAnalogVoltage); } @@ -339,8 +343,12 @@ public class PneumaticHub implements PneumaticsBase { throw new IllegalArgumentException( "maxPressure must be between 0 and 120 PSI, got " + maxPressure); } - double minAnalogVoltage = psiToVolts(minPressure, get5VRegulatedVoltage()); - double maxAnalogVoltage = psiToVolts(maxPressure, get5VRegulatedVoltage()); + + // 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. + double minAnalogVoltage = psiToVolts(minPressure, 5); + double maxAnalogVoltage = psiToVolts(maxPressure, 5); REVPHJNI.setClosedLoopControlHybrid(m_handle, minAnalogVoltage, maxAnalogVoltage); }