[wpilib] Use PSI for compressor config and sensor reading (#3847)

This adds the REV Analog Pressure Sensor PSI to volt (and vice versa) conversion to allow setting the compressor config in PSI and getting the sensor reading in PSI. Also adds input validation for pressure values at the higher level.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Jan-Felix Abellera
2021-12-31 22:04:56 -07:00
committed by GitHub
parent f401ea9aae
commit 7c09f44898
12 changed files with 208 additions and 52 deletions

View File

@@ -104,6 +104,14 @@ class Compressor : public wpi::Sendable,
*/
units::volt_t GetAnalogVoltage() const;
/**
* Query the analog sensor pressure (on channel 0) (if supported). Note this
* is only for use with the REV Analog Pressure Sensor.
*
* @return The analog sensor pressure, in PSI
*/
units::pounds_per_square_inch_t GetPressure() const;
/**
* Disable the compressor.
*/
@@ -115,26 +123,28 @@ class Compressor : public wpi::Sendable,
void EnableDigital();
/**
* Enable compressor closed loop control using analog input.
* Enable compressor closed loop control using analog input. Note this is only
* for use with the REV Analog Pressure Sensor.
*
* <p>On CTRE PCM, this will enable digital control.
*
* @param minAnalogVoltage The minimum voltage to enable compressor
* @param maxAnalogVoltage The maximum voltage to disable compressor
* @param minPressure The minimum pressure in PSI to enable compressor
* @param maxPressure The maximum pressure in PSI to disable compressor
*/
void EnableAnalog(units::volt_t minAnalogVoltage,
units::volt_t maxAnalogVoltage);
void EnableAnalog(units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure);
/**
* Enable compressor closed loop control using hybrid input.
* Enable compressor closed loop control using hybrid input. Note this is only
* for use with the REV Analog Pressure Sensor.
*
* On CTRE PCM, this will enable digital control.
*
* @param minAnalogVoltage The minimum voltage to enable compressor
* @param maxAnalogVoltage The maximum voltage to disable compressor
* @param minPressure The minimum pressure in PSI to enable compressor
* @param maxPressure The maximum pressure in PSI to disable compressor
*/
void EnableHybrid(units::volt_t minAnalogVoltage,
units::volt_t maxAnalogVoltage);
void EnableHybrid(units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure);
CompressorConfigType GetConfigType() const;

View File

@@ -26,11 +26,13 @@ class PneumaticHub : public PneumaticsBase {
void EnableCompressorDigital() override;
void EnableCompressorAnalog(units::volt_t minAnalogVoltage,
units::volt_t maxAnalogVoltage) override;
void EnableCompressorAnalog(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
void EnableCompressorHybrid(units::volt_t minAnalogVoltage,
units::volt_t maxAnalogVoltage) override;
void EnableCompressorHybrid(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
CompressorConfigType GetCompressorConfigType() const override;
@@ -127,6 +129,8 @@ class PneumaticHub : public PneumaticsBase {
units::volt_t GetAnalogVoltage(int channel) const override;
units::pounds_per_square_inch_t GetPressure(int channel) const override;
private:
class DataStore;
friend class DataStore;

View File

@@ -7,6 +7,7 @@
#include <memory>
#include <units/current.h>
#include <units/pressure.h>
#include <units/time.h>
#include <units/voltage.h>
@@ -31,11 +32,13 @@ class PneumaticsBase {
virtual void EnableCompressorDigital() = 0;
virtual void EnableCompressorAnalog(units::volt_t minAnalogVoltage,
units::volt_t maxAnalogVoltage) = 0;
virtual void EnableCompressorAnalog(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) = 0;
virtual void EnableCompressorHybrid(units::volt_t minAnalogVoltage,
units::volt_t maxAnalogVoltage) = 0;
virtual void EnableCompressorHybrid(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) = 0;
virtual CompressorConfigType GetCompressorConfigType() const = 0;
@@ -63,6 +66,8 @@ class PneumaticsBase {
virtual units::volt_t GetAnalogVoltage(int channel) const = 0;
virtual units::pounds_per_square_inch_t GetPressure(int channel) const = 0;
virtual Solenoid MakeSolenoid(int channel) = 0;
virtual DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
int reverseChannel) = 0;

View File

@@ -26,11 +26,13 @@ class PneumaticsControlModule : public PneumaticsBase {
void EnableCompressorDigital() override;
void EnableCompressorAnalog(units::volt_t minAnalogVoltage,
units::volt_t maxAnalogVoltage) override;
void EnableCompressorAnalog(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
void EnableCompressorHybrid(units::volt_t minAnalogVoltage,
units::volt_t maxAnalogVoltage) override;
void EnableCompressorHybrid(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
CompressorConfigType GetCompressorConfigType() const override;
@@ -74,6 +76,8 @@ class PneumaticsControlModule : public PneumaticsBase {
units::volt_t GetAnalogVoltage(int channel) const override;
units::pounds_per_square_inch_t GetPressure(int channel) const override;
Solenoid MakeSolenoid(int channel) override;
DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
int reverseChannel) override;