[wpilib] Add/update documentation to PneumaticBase and subclasses (NFC) (#4881)

Co-authored-by: Starlight220 <53231611+Starlight220@users.noreply.github.com>
This commit is contained in:
Ryan Blue
2023-01-02 13:23:59 -05:00
committed by GitHub
parent 9872e676d8
commit 83f1860047
8 changed files with 722 additions and 47 deletions

View File

@@ -79,31 +79,39 @@ class Compressor : public wpi::Sendable,
bool IsEnabled() const;
/**
* Check if the pressure switch is triggered.
* Returns the state of the pressure switch.
*
* @return true if pressure is low
* @return True if pressure switch indicates that the system is not full,
* otherwise false.
*/
bool GetPressureSwitchValue() const;
/**
* Query how much current the compressor is drawing.
* Get the current drawn by the compressor.
*
* @return The current through the compressor, in amps
* @return Current drawn by the compressor.
*/
units::ampere_t GetCurrent() const;
/**
* Query the analog input voltage (on channel 0) (if supported).
* If supported by the device, returns the analog input voltage (on channel
* 0).
*
* @return The analog input voltage, in volts
* This function is only supported by the REV PH. On CTRE PCM, this will
* return 0.
*
* @return The analog input voltage, in volts.
*/
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.
* If supported by the device, returns the pressure read by the analog
* pressure sensor (on channel 0).
*
* @return The analog sensor pressure, in PSI
* This function is only supported by the REV PH with the REV Analog Pressure
* Sensor. On CTRE PCM, this will return 0.
*
* @return The pressure read by the analog pressure sensor.
*/
units::pounds_per_square_inch_t GetPressure() const;
@@ -113,34 +121,68 @@ class Compressor : public wpi::Sendable,
void Disable();
/**
* Enable compressor closed loop control using digital input.
* Enables the compressor in digital mode using the digital pressure switch.
* The compressor will turn on when the pressure switch indicates that the
* system is not full, and will turn off when the pressure switch indicates
* that the system is full.
*/
void EnableDigital();
/**
* Enable compressor closed loop control using analog input. Note this is only
* for use with the REV Analog Pressure Sensor.
* If supported by the device, enables the compressor in analog mode. This
* mode uses an analog pressure sensor connected to analog channel 0 to cycle
* the compressor. The compressor will turn on when the pressure drops below
* {@code minPressure} and will turn off when the pressure reaches {@code
* maxPressure}. This mode is only supported by the REV PH with the REV Analog
* Pressure Sensor connected to analog channel 0.
*
* <p>On CTRE PCM, this will enable digital control.
* On CTRE PCM, this will enable digital control.
*
* @param minPressure The minimum pressure in PSI to enable compressor
* @param maxPressure The maximum pressure in PSI to disable compressor
* @param minPressure The minimum pressure. The compressor will turn on when
* the pressure drops below this value.
* @param maxPressure The maximum pressure. The compressor will turn off when
* the pressure reaches this value.
*/
void EnableAnalog(units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure);
/**
* Enable compressor closed loop control using hybrid input. Note this is only
* for use with the REV Analog Pressure Sensor.
* If supported by the device, enables the compressor in hybrid mode. This
* mode uses both a digital pressure switch and an analog pressure sensor
* connected to analog channel 0 to cycle the compressor. This mode is only
* supported by the REV PH with the REV Analog Pressure Sensor connected to
* analog channel 0.
*
* The compressor will turn on when \a both:
*
* - The digital pressure switch indicates the system is not full AND
* - The analog pressure sensor indicates that the pressure in the system
* is below the specified minimum pressure.
*
* The compressor will turn off when \a either:
*
* - The digital pressure switch is disconnected or indicates that the system
* is full OR
* - The pressure detected by the analog sensor is greater than the specified
* maximum pressure.
*
* On CTRE PCM, this will enable digital control.
*
* @param minPressure The minimum pressure in PSI to enable compressor
* @param maxPressure The maximum pressure in PSI to disable compressor
* @param minPressure The minimum pressure. The compressor will turn on
* when the pressure drops below this value and the pressure switch indicates
* that the system is not full.
* @param maxPressure The maximum pressure. The compressor will turn
* off when the pressure reaches this value or the pressure switch is
* disconnected or indicates that the system is full.
*/
void EnableHybrid(units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure);
/**
* Returns the active compressor configuration.
*
* @return The active compressor configuration.
*/
CompressorConfigType GetConfigType() const;
void InitSendable(wpi::SendableBuilder& builder) override;

View File

@@ -13,23 +13,72 @@
#include "PneumaticsBase.h"
namespace frc {
/** Module class for controlling a REV Robotics Pneumatic Hub. */
class PneumaticHub : public PneumaticsBase {
public:
/** Constructs a PneumaticHub with the default ID (1). */
PneumaticHub();
/**
* Constructs a PneumaticHub.
*
* @param module module number to construct
*/
explicit PneumaticHub(int module);
~PneumaticHub() override = default;
bool GetCompressor() const override;
/**
* Disables the compressor. The compressor will not turn on until
* EnableCompressorDigital(), EnableCompressorAnalog(), or
* EnableCompressorHybrid() are called.
*/
void DisableCompressor() override;
void EnableCompressorDigital() override;
/**
* Enables the compressor in analog mode. This mode uses an analog pressure
* sensor connected to analog channel 0 to cycle the compressor. The
* compressor will turn on when the pressure drops below {@code minPressure}
* and will turn off when the pressure reaches {@code maxPressure}.
*
* @param minPressure The minimum pressure. The compressor will turn on when
* the pressure drops below this value.
* @param maxPressure The maximum pressure. The compressor will turn off when
* the pressure reaches this value.
*/
void EnableCompressorAnalog(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
/**
* Enables the compressor in hybrid mode. This mode uses both a digital
* pressure switch and an analog pressure sensor connected to analog channel 0
* to cycle the compressor.
*
* The compressor will turn on when \a both:
*
* - The digital pressure switch indicates the system is not full AND
* - The analog pressure sensor indicates that the pressure in the system is
* below the specified minimum pressure.
*
* The compressor will turn off when \a either:
*
* - The digital pressure switch is disconnected or indicates that the system
* is full OR
* - The pressure detected by the analog sensor is greater than the specified
* maximum pressure.
*
* @param minPressure The minimum pressure. The compressor will turn on when
* the pressure drops below this value and the pressure switch indicates that
* the system is not full.
* @param maxPressure The maximum pressure. The compressor will turn off when
* the pressure reaches this value or the pressure switch is disconnected or
* indicates that the system is full.
*/
void EnableCompressorHybrid(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
@@ -76,6 +125,11 @@ class PneumaticHub : public PneumaticsBase {
uint32_t UniqueId;
};
/**
* Returns the hardware and firmware versions of this device.
*
* @return The hardware and firmware versions.
*/
Version GetVersion() const;
struct Faults {
@@ -103,6 +157,11 @@ class PneumaticHub : public PneumaticsBase {
uint32_t HardwareFault : 1;
};
/**
* Returns the faults currently active on this device.
*
* @return The faults.
*/
Faults GetFaults() const;
struct StickyFaults {
@@ -115,20 +174,60 @@ class PneumaticHub : public PneumaticsBase {
uint32_t HasReset : 1;
};
/**
* Returns the sticky faults currently active on this device.
*
* @return The sticky faults.
*/
StickyFaults GetStickyFaults() const;
/** Clears the sticky faults. */
void ClearStickyFaults();
/**
* Returns the current input voltage for this device.
*
* @return The input voltage.
*/
units::volt_t GetInputVoltage() const;
/**
* Returns the current voltage of the regulated 5v supply.
*
* @return The current voltage of the 5v supply.
*/
units::volt_t Get5VRegulatedVoltage() const;
/**
* Returns the total current drawn by all solenoids.
*
* @return Total current drawn by all solenoids.
*/
units::ampere_t GetSolenoidsTotalCurrent() const;
/**
* Returns the current voltage of the solenoid power supply.
*
* @return The current voltage of the solenoid power supply.
*/
units::volt_t GetSolenoidsVoltage() const;
/**
* Returns the raw voltage of the specified analog input channel.
*
* @param channel The analog input channel to read voltage from.
* @return The voltage of the specified analog input channel.
*/
units::volt_t GetAnalogVoltage(int channel) const override;
/**
* Returns the pressure read by an analog pressure sensor on the specified
* analog input channel.
*
* @param channel The analog input channel to read pressure from.
* @return The pressure read by an analog pressure sensor on the specified
* analog input channel.
*/
units::pounds_per_square_inch_t GetPressure(int channel) const override;
private:

View File

@@ -22,50 +22,194 @@ class PneumaticsBase {
public:
virtual ~PneumaticsBase() = default;
/**
* Returns whether the compressor is active or not.
*
* @return True if the compressor is on - otherwise false.
*/
virtual bool GetCompressor() const = 0;
/**
* Returns the state of the pressure switch.
*
* @return True if pressure switch indicates that the system is full,
* otherwise false.
*/
virtual bool GetPressureSwitch() const = 0;
/**
* Returns the current drawn by the compressor.
*
* @return The current drawn by the compressor.
*/
virtual units::ampere_t GetCompressorCurrent() const = 0;
/** Disables the compressor. */
virtual void DisableCompressor() = 0;
/**
* Enables the compressor in digital mode using the digital pressure switch.
* The compressor will turn on when the pressure switch indicates that the
* system is not full, and will turn off when the pressure switch indicates
* that the system is full.
*/
virtual void EnableCompressorDigital() = 0;
/**
* If supported by the device, enables the compressor in analog mode. This
* mode uses an analog pressure sensor connected to analog channel 0 to cycle
* the compressor. The compressor will turn on when the pressure drops below
* {@code minPressure} and will turn off when the pressure reaches {@code
* maxPressure}. This mode is only supported by the REV PH with the REV Analog
* Pressure Sensor connected to analog channel 0.
*
* On CTRE PCM, this will enable digital control.
*
* @param minPressure The minimum pressure. The compressor will turn on
* when the pressure drops below this value.
* @param maxPressure The maximum pressure. The compressor will turn
* off when the pressure reaches this value.
*/
virtual void EnableCompressorAnalog(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) = 0;
/**
* If supported by the device, enables the compressor in hybrid mode. This
* mode uses both a digital pressure switch and an analog pressure sensor
* connected to analog channel 0 to cycle the compressor. This mode is only
* supported by the REV PH with the REV Analog Pressure Sensor connected to
* analog channel 0.
*
* The compressor will turn on when \a both:
*
* - The digital pressure switch indicates the system is not full AND
* - The analog pressure sensor indicates that the pressure in the system
* is below the specified minimum pressure.
*
* The compressor will turn off when \a either:
*
* - The digital pressure switch is disconnected or indicates that the system
* is full OR
* - The pressure detected by the analog sensor is greater than the specified
* maximum pressure.
*
* On CTRE PCM, this will enable digital control.
*
* @param minPressure The minimum pressure. The compressor will turn on
* when the pressure drops below this value and the pressure switch indicates
* that the system is not full.
* @param maxPressure The maximum pressure. The compressor will turn
* off when the pressure reaches this value or the pressure switch is
* disconnected or indicates that the system is full.
*/
virtual void EnableCompressorHybrid(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) = 0;
/**
* Returns the active compressor configuration.
*
* @return The active compressor configuration.
*/
virtual CompressorConfigType GetCompressorConfigType() const = 0;
/**
* Sets solenoids on a pneumatics module.
*
* @param mask mask
* @param values values
*/
virtual void SetSolenoids(int mask, int values) = 0;
/**
* Gets a bitmask of solenoid values.
*
* @return values
*/
virtual int GetSolenoids() const = 0;
/**
* Get module number for this module.
*
* @return module number
*/
virtual int GetModuleNumber() const = 0;
/**
* Get a bitmask of disabled solenoids.
*
* @return bitmask of disabled solenoids
*/
virtual int GetSolenoidDisabledList() const = 0;
/**
* Fire a single solenoid shot.
*
* @param index solenoid index
*/
virtual void FireOneShot(int index) = 0;
/**
* Set the duration for a single solenoid shot.
*
* @param index solenoid index
* @param duration shot duration
*/
virtual void SetOneShotDuration(int index, units::second_t duration) = 0;
/**
* Check if a solenoid channel is valid.
*
* @param channel Channel to check
* @return True if channel exists
*/
virtual bool CheckSolenoidChannel(int channel) const = 0;
/**
* Check to see if the masked solenoids can be reserved, and if not reserve
* them.
*
* @param mask The bitmask of solenoids to reserve
* @return 0 if successful; mask of solenoids that couldn't be allocated
* otherwise
*/
virtual int CheckAndReserveSolenoids(int mask) = 0;
/**
* Unreserve the masked solenoids.
*
* @param mask The bitmask of solenoids to unreserve
*/
virtual void UnreserveSolenoids(int mask) = 0;
virtual bool ReserveCompressor() = 0;
virtual void UnreserveCompressor() = 0;
/**
* If supported by the device, returns the raw voltage of the specified analog
* input channel.
*
* This function is only supported by the REV PH. On CTRE PCM, this will
* return 0.
*
* @param channel The analog input channel to read voltage from.
* @return The voltage of the specified analog input channel.
*/
virtual units::volt_t GetAnalogVoltage(int channel) const = 0;
/**
* If supported by the device, returns the pressure read by an analog
* pressure sensor on the specified analog input channel.
*
* This function is only supported by the REV PH. On CTRE PCM, this will
* return 0.
*
* @param channel The analog input channel to read pressure from.
* @return The pressure read by an analog pressure sensor on the
* specified analog input channel.
*/
virtual units::pounds_per_square_inch_t GetPressure(int channel) const = 0;
virtual Solenoid MakeSolenoid(int channel) = 0;
@@ -73,8 +217,22 @@ class PneumaticsBase {
int reverseChannel) = 0;
virtual Compressor MakeCompressor() = 0;
/**
* For internal use to get a module for a specific type.
*
* @param module module number
* @param moduleType module type
* @return module
*/
static std::shared_ptr<PneumaticsBase> GetForType(
int module, PneumaticsModuleType moduleType);
/**
* For internal use to get the default for a specific type.
*
* @param moduleType module type
* @return module default
*/
static int GetDefaultForType(PneumaticsModuleType moduleType);
};
} // namespace frc

View File

@@ -13,23 +13,52 @@
#include "PneumaticsBase.h"
namespace frc {
/** Module class for controlling a Cross The Road Electronics Pneumatics Control
* Module. */
class PneumaticsControlModule : public PneumaticsBase {
public:
/** Constructs a PneumaticsControlModule with the default ID (0). */
PneumaticsControlModule();
/**
* Constructs a PneumaticsControlModule.
*
* @param module module number to construct
*/
explicit PneumaticsControlModule(int module);
~PneumaticsControlModule() override = default;
bool GetCompressor() const override;
/**
* Disables the compressor. The compressor will not turn on until
* EnableCompressorDigital() is called.
*/
void DisableCompressor() override;
void EnableCompressorDigital() override;
/**
* Enables the compressor in digital mode. Analog mode is unsupported by the
* CTRE PCM.
*
* @param minPressure Unsupported.
* @param maxPressure Unsupported.
* @see EnableCompressorDigital()
*/
void EnableCompressorAnalog(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
/**
* Enables the compressor in digital mode. Hybrid mode is unsupported by the
* CTRE PCM.
*
* @param minPressure Unsupported.
* @param maxPressure Unsupported.
* @see EnableCompressorDigital()
*/
void EnableCompressorHybrid(
units::pounds_per_square_inch_t minPressure,
units::pounds_per_square_inch_t maxPressure) override;
@@ -40,16 +69,67 @@ class PneumaticsControlModule : public PneumaticsBase {
units::ampere_t GetCompressorCurrent() const override;
/**
* Return whether the compressor current is currently too high.
*
* @return True if the compressor current is too high, otherwise false.
* @see GetCompressorCurrentTooHighStickyFault()
*/
bool GetCompressorCurrentTooHighFault() const;
/**
* Returns whether the compressor current has been too high since sticky
* faults were last cleared. This fault is persistent and can be cleared by
* ClearAllStickyFaults()
*
* @return True if the compressor current has been too high since sticky
* faults were last cleared.
* @see GetCompressorCurrentTooHighFault()
*/
bool GetCompressorCurrentTooHighStickyFault() const;
/**
* Returns whether the compressor is currently shorted.
*
* @return True if the compressor is currently shorted, otherwise false.
* @see GetCompressorShortedStickyFault()
*/
bool GetCompressorShortedFault() const;
/**
* Returns whether the compressor has been shorted since sticky faults were
* last cleared. This fault is persistent and can be cleared by
* ClearAllStickyFaults()
*
* @return True if the compressor has been shorted since sticky faults were
* last cleared, otherwise false.
* @see GetCompressorShortedFault()
*/
bool GetCompressorShortedStickyFault() const;
/**
* Returns whether the compressor is currently disconnected.
*
* @return True if compressor is currently disconnected, otherwise false.
* @see GetCompressorNotConnectedStickyFault()
*/
bool GetCompressorNotConnectedFault() const;
/**
* Returns whether the compressor has been disconnected since sticky faults
* were last cleared. This fault is persistent and can be cleared by
* ClearAllStickyFaults()}
*
* @return True if the compressor has been disconnected since sticky faults
* were last cleared, otherwise false.
* @see GetCompressorNotConnectedFault()
*/
bool GetCompressorNotConnectedStickyFault() const;
bool GetSolenoidVoltageFault() const;
bool GetSolenoidVoltageStickyFault() const;
/** Clears all sticky faults on this device. */
void ClearAllStickyFaults();
void SetSolenoids(int mask, int values) override;
@@ -74,8 +154,20 @@ class PneumaticsControlModule : public PneumaticsBase {
void UnreserveCompressor() override;
/**
* Unsupported by the CTRE PCM.
*
* @param channel Unsupported.
* @return 0
*/
units::volt_t GetAnalogVoltage(int channel) const override;
/**
* Unsupported by the CTRE PCM.
*
* @param channel Unsupported.
* @return 0
*/
units::pounds_per_square_inch_t GetPressure(int channel) const override;
Solenoid MakeSolenoid(int channel) override;