2014-06-13 17:45:10 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
|
2014-06-13 17:45:10 -04:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2014-06-13 17:45:10 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-05-25 22:40:15 -07:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/Types.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/ErrorBase.h"
|
|
|
|
|
#include "frc/SensorUtil.h"
|
|
|
|
|
#include "frc/smartdashboard/SendableBase.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
2017-08-23 21:58:21 -07:00
|
|
|
* Class for operating a compressor connected to a %PCM (Pneumatic Control
|
2017-11-16 00:33:51 -08:00
|
|
|
* Module).
|
|
|
|
|
*
|
|
|
|
|
* The PCM will automatically run in closed loop mode by default whenever a
|
|
|
|
|
* Solenoid object is created. For most cases, a Compressor object does not need
|
|
|
|
|
* to be instantiated or used in a robot program. This class is only required in
|
|
|
|
|
* cases where the robot program needs a more detailed status of the compressor
|
|
|
|
|
* or to enable/disable closed loop control.
|
2017-08-23 21:58:21 -07:00
|
|
|
*
|
|
|
|
|
* Note: you cannot operate the compressor directly from this class as doing so
|
|
|
|
|
* would circumvent the safety provided by using the pressure switch and closed
|
|
|
|
|
* loop control. You can only turn off closed loop control, thereby stopping
|
|
|
|
|
* the compressor from operating.
|
2014-05-02 17:54:01 -04:00
|
|
|
*/
|
2017-12-04 23:28:33 -08:00
|
|
|
class Compressor : public ErrorBase, public SendableBase {
|
2015-06-25 15:07:55 -04:00
|
|
|
public:
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Constructor. The default PCM ID is 0.
|
|
|
|
|
*
|
|
|
|
|
* @param module The PCM ID to use (0-62)
|
|
|
|
|
*/
|
2018-05-23 20:22:30 -07:00
|
|
|
explicit Compressor(int pcmID = SensorUtil::GetDefaultSolenoidModule());
|
2018-05-31 20:47:15 -07:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
~Compressor() override = default;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2018-09-24 00:08:25 -07:00
|
|
|
Compressor(Compressor&&) = default;
|
|
|
|
|
Compressor& operator=(Compressor&&) = default;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Starts closed-loop control. Note that closed loop control is enabled by
|
|
|
|
|
* default.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Start();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Stops closed-loop control. Note that closed loop control is enabled by
|
|
|
|
|
* default.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Stop();
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if compressor output is active.
|
|
|
|
|
*
|
|
|
|
|
* @return true if the compressor is on
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool Enabled() const;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Check if the pressure switch is triggered.
|
|
|
|
|
*
|
|
|
|
|
* @return true if pressure is low
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetPressureSwitchValue() const;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Query how much current the compressor is drawing.
|
|
|
|
|
*
|
|
|
|
|
* @return The current through the compressor, in amps
|
|
|
|
|
*/
|
2016-11-20 07:25:03 -08:00
|
|
|
double GetCompressorCurrent() const;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Enables or disables automatically turning the compressor on when the
|
|
|
|
|
* pressure is low.
|
|
|
|
|
*
|
|
|
|
|
* @param on Set to true to enable closed loop control of the compressor.
|
|
|
|
|
* False to disable.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SetClosedLoopControl(bool on);
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the compressor will automatically turn on when the
|
|
|
|
|
* pressure is low.
|
|
|
|
|
*
|
|
|
|
|
* @return True if closed loop control of the compressor is enabled. False if
|
|
|
|
|
* disabled.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetClosedLoopControl() const;
|
|
|
|
|
|
2018-05-31 20:47:15 -07:00
|
|
|
/**
|
|
|
|
|
* Query if the compressor output has been disabled due to high current draw.
|
|
|
|
|
*
|
|
|
|
|
* @return true if PCM is in fault state : Compressor Drive is
|
|
|
|
|
* disabled due to compressor current being too high.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetCompressorCurrentTooHighFault() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query if the compressor output has been disabled due to high current draw
|
|
|
|
|
* (sticky).
|
|
|
|
|
*
|
|
|
|
|
* A sticky fault will not clear on device reboot, it must be cleared through
|
|
|
|
|
* code or the webdash.
|
|
|
|
|
*
|
|
|
|
|
* @return true if PCM sticky fault is set : Compressor Drive is
|
|
|
|
|
* disabled due to compressor current being too high.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetCompressorCurrentTooHighStickyFault() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query if the compressor output has been disabled due to a short circuit
|
|
|
|
|
* (sticky).
|
|
|
|
|
*
|
|
|
|
|
* A sticky fault will not clear on device reboot, it must be cleared through
|
|
|
|
|
* code or the webdash.
|
|
|
|
|
*
|
|
|
|
|
* @return true if PCM sticky fault is set : Compressor output
|
|
|
|
|
* appears to be shorted.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetCompressorShortedStickyFault() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query if the compressor output has been disabled due to a short circuit.
|
|
|
|
|
*
|
|
|
|
|
* @return true if PCM is in fault state : Compressor output
|
|
|
|
|
* appears to be shorted.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetCompressorShortedFault() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query if the compressor output does not appear to be wired (sticky).
|
|
|
|
|
*
|
|
|
|
|
* A sticky fault will not clear on device reboot, it must be cleared through
|
|
|
|
|
* code or the webdash.
|
|
|
|
|
*
|
|
|
|
|
* @return true if PCM sticky fault is set : Compressor does not
|
|
|
|
|
* appear to be wired, i.e. compressor is not drawing enough current.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetCompressorNotConnectedStickyFault() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Query if the compressor output does not appear to be wired.
|
|
|
|
|
*
|
|
|
|
|
* @return true if PCM is in fault state : Compressor does not
|
|
|
|
|
* appear to be wired, i.e. compressor is not drawing enough current.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
bool GetCompressorNotConnectedFault() const;
|
2018-05-31 20:47:15 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear ALL sticky faults inside PCM that Compressor is wired to.
|
|
|
|
|
*
|
|
|
|
|
* If a sticky fault is set, then it will be persistently cleared. Compressor
|
|
|
|
|
* drive maybe momentarily disable while flags are being cleared. Care should
|
|
|
|
|
* be taken to not call this too frequently, otherwise normal compressor
|
|
|
|
|
* functionality may be prevented.
|
|
|
|
|
*
|
|
|
|
|
* If no sticky faults are set then this call will have no effect.
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void ClearAllPCMStickyFaults();
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
void InitSendable(SendableBuilder& builder) override;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
protected:
|
2018-09-24 00:08:25 -07:00
|
|
|
HAL_CompressorHandle m_compressorHandle = HAL_kInvalidHandle;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void SetCompressor(bool on);
|
2016-09-06 00:01:45 -07:00
|
|
|
int m_module;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|