[wpilib] Use PH voltage to calc Analog pressure switch threshold (#5115)

The calculated trigger voltages were calculated with a hard coded 5v.
This introduces error when the 5V provided to the Analog pressure
sensor is not exactly 5v, as the pressure is a ratio of the analog
voltage and provided voltage.

This should improve
https://www.chiefdelphi.com/t/rev-pressure-sensor-enablecompressoranalog-not-reaching-configured-pressure/426868
where the 5v voltage was 4.92 volts, which introduces ~8 PSI of error.
This commit is contained in:
sciencewhiz
2023-02-19 23:13:22 -08:00
committed by GitHub
parent de65a135c3
commit dbbfe1aed2
2 changed files with 12 additions and 8 deletions

View File

@@ -162,8 +162,10 @@ void PneumaticHub::EnableCompressorAnalog(
maxPressure);
}
int32_t status = 0;
units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V);
units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V);
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);
@@ -187,8 +189,10 @@ void PneumaticHub::EnableCompressorHybrid(
maxPressure);
}
int32_t status = 0;
units::volt_t minAnalogVoltage = PSIToVolts(minPressure, 5_V);
units::volt_t maxAnalogVoltage = PSIToVolts(maxPressure, 5_V);
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);