2014-06-09 11:12:44 -04:00
|
|
|
/*
|
|
|
|
|
* Compressor.cpp
|
|
|
|
|
*/
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
#include "Compressor.h"
|
|
|
|
|
#include "WPIErrors.h"
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-09 11:12:44 -04:00
|
|
|
* Constructor
|
|
|
|
|
*
|
2014-12-29 14:09:37 -05:00
|
|
|
* @param module The PCM ID to use (0-62)
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-24 01:06:29 -07:00
|
|
|
Compressor::Compressor(uint8_t pcmID) {
|
|
|
|
|
m_pcm_pointer = initializeCompressor(pcmID);
|
|
|
|
|
SetClosedLoopControl(true);
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Starts closed-loop control. Note that closed loop control is enabled by
|
|
|
|
|
* default.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Compressor::Start() { SetClosedLoopControl(true); }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04:00
|
|
|
* Stops closed-loop control. Note that closed loop control is enabled by
|
|
|
|
|
* default.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void Compressor::Stop() { SetClosedLoopControl(false); }
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
2014-12-29 14:09:37 -05:00
|
|
|
* Check if compressor output is active
|
2014-06-09 11:12:44 -04:00
|
|
|
* @return true if the compressor is on
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::Enabled() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getCompressor(m_pcm_pointer, &status);
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-12-29 14:09:37 -05:00
|
|
|
* Check if the pressure switch is triggered
|
2014-06-09 11:12:44 -04:00
|
|
|
* @return true if pressure is low
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetPressureSwitchValue() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getPressureSwitch(m_pcm_pointer, &status);
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-12-29 14:09:37 -05:00
|
|
|
* Query how much current the compressor is drawing
|
2014-06-09 11:12:44 -04:00
|
|
|
* @return The current through the compressor, in amps
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
float Compressor::GetCompressorCurrent() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
float value;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getCompressorCurrent(m_pcm_pointer, &status);
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-09 11:12:44 -04:00
|
|
|
* Enables or disables automatically turning the compressor on when the
|
|
|
|
|
* pressure is low.
|
2015-06-25 15:07:55 -04:00
|
|
|
* @param on Set to true to enable closed loop control of the compressor. False
|
|
|
|
|
* to disable.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
void Compressor::SetClosedLoopControl(bool on) {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
setClosedLoopControl(m_pcm_pointer, on, &status);
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-09 11:12:44 -04:00
|
|
|
* Returns true if the compressor will automatically turn on when the
|
|
|
|
|
* pressure is low.
|
2015-06-25 15:07:55 -04:00
|
|
|
* @return True if closed loop control of the compressor is enabled. False if
|
|
|
|
|
* disabled.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetClosedLoopControl() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getClosedLoopControl(m_pcm_pointer, &status);
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-12-26 19:40:39 -05:00
|
|
|
/**
|
2014-12-29 14:09:37 -05:00
|
|
|
* Query if the compressor output has been disabled due to high current draw.
|
2015-06-25 15:07:55 -04:00
|
|
|
* @return true if PCM is in fault state : Compressor Drive is
|
|
|
|
|
* disabled due to compressor current being too high.
|
2014-12-26 19:40:39 -05:00
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorCurrentTooHighFault() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getCompressorCurrentTooHighFault(m_pcm_pointer, &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04: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.
|
2014-12-26 19:40:39 -05:00
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getCompressorCurrentTooHighStickyFault(m_pcm_pointer, &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
2015-06-25 15:07:55 -04: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.
|
2014-12-26 19:40:39 -05:00
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorShortedStickyFault() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getCompressorShortedStickyFault(m_pcm_pointer, &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
2014-12-29 14:09:37 -05:00
|
|
|
* Query if the compressor output has been disabled due to a short circuit.
|
2015-06-25 15:07:55 -04:00
|
|
|
* @return true if PCM is in fault state : Compressor output
|
|
|
|
|
* appears to be shorted.
|
2014-12-26 19:40:39 -05:00
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorShortedFault() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getCompressorShortedFault(m_pcm_pointer, &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
2014-12-29 14:09:37 -05:00
|
|
|
* Query if the compressor output does not appear to be wired (sticky).
|
2015-06-25 15:07:55 -04:00
|
|
|
* 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
|
2014-12-26 19:40:39 -05:00
|
|
|
* not drawing enough current.
|
|
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorNotConnectedStickyFault() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getCompressorNotConnectedStickyFault(m_pcm_pointer, &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
2014-12-29 14:09:37 -05:00
|
|
|
* Query if the compressor output does not appear to be wired.
|
2015-06-25 15:07:55 -04:00
|
|
|
* @return true if PCM is in fault state : Compressor does not
|
|
|
|
|
* appear to be wired, i.e. compressor is
|
2014-12-26 19:40:39 -05:00
|
|
|
* not drawing enough current.
|
|
|
|
|
*/
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorNotConnectedFault() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
value = getCompressorNotConnectedFault(m_pcm_pointer, &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Clear ALL sticky faults inside PCM that Compressor is wired to.
|
|
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* 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.
|
2014-12-26 19:40:39 -05:00
|
|
|
*
|
|
|
|
|
* If no sticky faults are set then this call will have no effect.
|
|
|
|
|
*/
|
|
|
|
|
void Compressor::ClearAllPCMStickyFaults() {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
clearAllPCMStickyFaults(m_pcm_pointer, &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
if (status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
void Compressor::UpdateTable() {
|
2015-06-25 15:07:55 -04:00
|
|
|
if (m_table) {
|
|
|
|
|
m_table->PutBoolean("Enabled", Enabled());
|
|
|
|
|
m_table->PutBoolean("Pressure switch", GetPressureSwitchValue());
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void Compressor::StartLiveWindowMode() {}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void Compressor::StopLiveWindowMode() {}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
std::string Compressor::GetSmartDashboardType() const { return "Compressor"; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
void Compressor::InitTable(std::shared_ptr<ITable> subTable) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table = subTable;
|
|
|
|
|
UpdateTable();
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<ITable> Compressor::GetTable() const { return m_table; }
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
void Compressor::ValueChanged(std::shared_ptr<ITable> source, const std::string& key,
|
2015-06-25 15:07:55 -04:00
|
|
|
EntryValue value, bool isNew) {
|
|
|
|
|
if (value.b)
|
|
|
|
|
Start();
|
|
|
|
|
else
|
|
|
|
|
Stop();
|
2014-06-09 11:12:44 -04:00
|
|
|
}
|