2021-06-05 22:36:39 -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.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-09-16 18:50:27 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2021-06-05 22:36:39 -07:00
|
|
|
#include <hal/Types.h>
|
2021-09-16 18:50:27 -07:00
|
|
|
#include <wpi/DenseMap.h>
|
2021-07-09 15:11:12 -07:00
|
|
|
#include <wpi/mutex.h>
|
2021-06-05 22:36:39 -07:00
|
|
|
|
|
|
|
|
#include "PneumaticsBase.h"
|
|
|
|
|
|
|
|
|
|
namespace frc {
|
2023-01-02 13:23:59 -05:00
|
|
|
/** Module class for controlling a Cross The Road Electronics Pneumatics Control
|
|
|
|
|
* Module. */
|
2021-09-16 18:50:27 -07:00
|
|
|
class PneumaticsControlModule : public PneumaticsBase {
|
2021-06-05 22:36:39 -07:00
|
|
|
public:
|
2023-01-02 13:23:59 -05:00
|
|
|
/** Constructs a PneumaticsControlModule with the default ID (0). */
|
2021-06-05 22:36:39 -07:00
|
|
|
PneumaticsControlModule();
|
2023-01-02 13:23:59 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructs a PneumaticsControlModule.
|
|
|
|
|
*
|
|
|
|
|
* @param module module number to construct
|
|
|
|
|
*/
|
2021-06-05 22:36:39 -07:00
|
|
|
explicit PneumaticsControlModule(int module);
|
|
|
|
|
|
2021-09-16 18:50:27 -07:00
|
|
|
~PneumaticsControlModule() override = default;
|
2021-06-05 22:36:39 -07:00
|
|
|
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetCompressor() const override;
|
2021-06-05 22:36:39 -07:00
|
|
|
|
2023-01-02 13:23:59 -05:00
|
|
|
/**
|
|
|
|
|
* Disables the compressor. The compressor will not turn on until
|
|
|
|
|
* EnableCompressorDigital() is called.
|
|
|
|
|
*/
|
2021-11-23 20:32:02 -08:00
|
|
|
void DisableCompressor() override;
|
2021-06-05 22:36:39 -07:00
|
|
|
|
2021-11-23 20:32:02 -08:00
|
|
|
void EnableCompressorDigital() override;
|
|
|
|
|
|
2023-01-02 13:23:59 -05:00
|
|
|
/**
|
|
|
|
|
* Enables the compressor in digital mode. Analog mode is unsupported by the
|
|
|
|
|
* CTRE PCM.
|
|
|
|
|
*
|
|
|
|
|
* @param minPressure Unsupported.
|
|
|
|
|
* @param maxPressure Unsupported.
|
|
|
|
|
* @see EnableCompressorDigital()
|
|
|
|
|
*/
|
2021-12-31 22:04:56 -07:00
|
|
|
void EnableCompressorAnalog(
|
|
|
|
|
units::pounds_per_square_inch_t minPressure,
|
|
|
|
|
units::pounds_per_square_inch_t maxPressure) override;
|
2021-11-23 20:32:02 -08:00
|
|
|
|
2023-01-02 13:23:59 -05:00
|
|
|
/**
|
|
|
|
|
* Enables the compressor in digital mode. Hybrid mode is unsupported by the
|
|
|
|
|
* CTRE PCM.
|
|
|
|
|
*
|
|
|
|
|
* @param minPressure Unsupported.
|
|
|
|
|
* @param maxPressure Unsupported.
|
|
|
|
|
* @see EnableCompressorDigital()
|
|
|
|
|
*/
|
2021-12-31 22:04:56 -07:00
|
|
|
void EnableCompressorHybrid(
|
|
|
|
|
units::pounds_per_square_inch_t minPressure,
|
|
|
|
|
units::pounds_per_square_inch_t maxPressure) override;
|
2021-11-23 20:32:02 -08:00
|
|
|
|
|
|
|
|
CompressorConfigType GetCompressorConfigType() const override;
|
2021-06-05 22:36:39 -07:00
|
|
|
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetPressureSwitch() const override;
|
2021-06-05 22:36:39 -07:00
|
|
|
|
2021-12-19 13:41:35 -08:00
|
|
|
units::ampere_t GetCompressorCurrent() const override;
|
2021-06-05 22:36:39 -07:00
|
|
|
|
2023-01-02 13:23:59 -05:00
|
|
|
/**
|
|
|
|
|
* Return whether the compressor current is currently too high.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the compressor current is too high, otherwise false.
|
|
|
|
|
* @see GetCompressorCurrentTooHighStickyFault()
|
|
|
|
|
*/
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetCompressorCurrentTooHighFault() const;
|
2023-01-02 13:23:59 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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()
|
|
|
|
|
*/
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetCompressorCurrentTooHighStickyFault() const;
|
2023-01-02 13:23:59 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the compressor is currently shorted.
|
|
|
|
|
*
|
|
|
|
|
* @return True if the compressor is currently shorted, otherwise false.
|
|
|
|
|
* @see GetCompressorShortedStickyFault()
|
|
|
|
|
*/
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetCompressorShortedFault() const;
|
2023-01-02 13:23:59 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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()
|
|
|
|
|
*/
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetCompressorShortedStickyFault() const;
|
2023-01-02 13:23:59 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the compressor is currently disconnected.
|
|
|
|
|
*
|
|
|
|
|
* @return True if compressor is currently disconnected, otherwise false.
|
|
|
|
|
* @see GetCompressorNotConnectedStickyFault()
|
|
|
|
|
*/
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetCompressorNotConnectedFault() const;
|
2023-01-02 13:23:59 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the compressor has been disconnected since sticky faults
|
|
|
|
|
* were last cleared. This fault is persistent and can be cleared by
|
2023-06-15 08:14:35 -07:00
|
|
|
* ClearAllStickyFaults()
|
2023-01-02 13:23:59 -05:00
|
|
|
*
|
|
|
|
|
* @return True if the compressor has been disconnected since sticky faults
|
|
|
|
|
* were last cleared, otherwise false.
|
|
|
|
|
* @see GetCompressorNotConnectedFault()
|
|
|
|
|
*/
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetCompressorNotConnectedStickyFault() const;
|
2021-06-05 22:36:39 -07:00
|
|
|
|
2023-06-15 08:14:35 -07:00
|
|
|
/**
|
|
|
|
|
* Returns whether the solenoid is currently reporting a voltage fault.
|
|
|
|
|
*
|
|
|
|
|
* @return True if solenoid is reporting a fault, otherwise false.
|
|
|
|
|
* @see GetSolenoidVoltageStickyFault()
|
|
|
|
|
*/
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetSolenoidVoltageFault() const;
|
2023-06-15 08:14:35 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the solenoid has reported a voltage fault since sticky
|
|
|
|
|
* faults were last cleared. This fault is persistent and can be cleared by
|
|
|
|
|
* ClearAllStickyFaults()
|
|
|
|
|
*
|
|
|
|
|
* @return True if solenoid is reporting a fault, otherwise false.
|
|
|
|
|
* @see GetSolenoidVoltageFault()
|
|
|
|
|
*/
|
2021-09-16 18:50:27 -07:00
|
|
|
bool GetSolenoidVoltageStickyFault() const;
|
2021-06-05 22:36:39 -07:00
|
|
|
|
2023-01-02 13:23:59 -05:00
|
|
|
/** Clears all sticky faults on this device. */
|
2021-06-05 22:36:39 -07:00
|
|
|
void ClearAllStickyFaults();
|
|
|
|
|
|
|
|
|
|
void SetSolenoids(int mask, int values) override;
|
|
|
|
|
|
|
|
|
|
int GetSolenoids() const override;
|
|
|
|
|
|
|
|
|
|
int GetModuleNumber() const override;
|
|
|
|
|
|
|
|
|
|
int GetSolenoidDisabledList() const override;
|
|
|
|
|
|
|
|
|
|
void FireOneShot(int index) override;
|
|
|
|
|
|
|
|
|
|
void SetOneShotDuration(int index, units::second_t duration) override;
|
|
|
|
|
|
|
|
|
|
bool CheckSolenoidChannel(int channel) const override;
|
|
|
|
|
|
2021-07-09 15:11:12 -07:00
|
|
|
int CheckAndReserveSolenoids(int mask) override;
|
|
|
|
|
|
|
|
|
|
void UnreserveSolenoids(int mask) override;
|
|
|
|
|
|
2021-09-16 18:50:27 -07:00
|
|
|
bool ReserveCompressor() override;
|
|
|
|
|
|
|
|
|
|
void UnreserveCompressor() override;
|
|
|
|
|
|
2023-01-02 13:23:59 -05:00
|
|
|
/**
|
|
|
|
|
* Unsupported by the CTRE PCM.
|
|
|
|
|
*
|
|
|
|
|
* @param channel Unsupported.
|
|
|
|
|
* @return 0
|
|
|
|
|
*/
|
2021-12-19 13:41:35 -08:00
|
|
|
units::volt_t GetAnalogVoltage(int channel) const override;
|
|
|
|
|
|
2023-01-02 13:23:59 -05:00
|
|
|
/**
|
|
|
|
|
* Unsupported by the CTRE PCM.
|
|
|
|
|
*
|
|
|
|
|
* @param channel Unsupported.
|
|
|
|
|
* @return 0
|
|
|
|
|
*/
|
2021-12-31 22:04:56 -07:00
|
|
|
units::pounds_per_square_inch_t GetPressure(int channel) const override;
|
|
|
|
|
|
2021-09-16 18:50:27 -07:00
|
|
|
Solenoid MakeSolenoid(int channel) override;
|
|
|
|
|
DoubleSolenoid MakeDoubleSolenoid(int forwardChannel,
|
|
|
|
|
int reverseChannel) override;
|
|
|
|
|
Compressor MakeCompressor() override;
|
2021-07-09 15:11:12 -07:00
|
|
|
|
2025-02-07 12:37:23 -08:00
|
|
|
void ReportUsage(std::string_view device, std::string_view data) override;
|
|
|
|
|
|
2021-06-05 22:36:39 -07:00
|
|
|
private:
|
2021-09-16 18:50:27 -07:00
|
|
|
class DataStore;
|
|
|
|
|
friend class DataStore;
|
|
|
|
|
friend class PneumaticsBase;
|
|
|
|
|
PneumaticsControlModule(HAL_CTREPCMHandle handle, int module);
|
|
|
|
|
|
|
|
|
|
static std::shared_ptr<PneumaticsBase> GetForModule(int module);
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<DataStore> m_dataStore;
|
|
|
|
|
HAL_CTREPCMHandle m_handle;
|
2021-06-05 22:36:39 -07:00
|
|
|
int m_module;
|
2021-09-16 18:50:27 -07:00
|
|
|
|
|
|
|
|
static wpi::mutex m_handleLock;
|
|
|
|
|
static std::unique_ptr<wpi::DenseMap<int, std::weak_ptr<DataStore>>>
|
|
|
|
|
m_handleMap;
|
|
|
|
|
static std::weak_ptr<DataStore>& GetDataStore(int module);
|
2021-06-05 22:36:39 -07:00
|
|
|
};
|
|
|
|
|
} // namespace frc
|