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-13 17:45:10 -04:00
|
|
|
void Compressor::InitCompressor(uint8_t pcmID) {
|
2014-06-09 11:12:44 -04:00
|
|
|
m_table = 0;
|
2014-06-13 17:45:10 -04:00
|
|
|
m_pcm_pointer = initializeCompressor(pcmID);
|
2014-06-09 11:12:44 -04:00
|
|
|
|
|
|
|
|
SetClosedLoopControl(true);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-09 11:12:44 -04:00
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* Uses the default solenoid module number
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
Compressor::Compressor() {
|
|
|
|
|
InitCompressor(GetDefaultSolenoidModule());
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-09 11:12:44 -04:00
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param module The module number to use (1 or 2)
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-13 17:45:10 -04:00
|
|
|
Compressor::Compressor(uint8_t pcmID) {
|
|
|
|
|
InitCompressor(pcmID);
|
2014-06-09 11:12:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Compressor::~Compressor() {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-12 12:43:03 -04:00
|
|
|
* Starts closed-loop control
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
void Compressor::Start() {
|
2014-06-12 12:43:03 -04:00
|
|
|
SetClosedLoopControl(true);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-12 12:43:03 -04:00
|
|
|
* Stops closed-loop control
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
void Compressor::Stop() {
|
|
|
|
|
SetClosedLoopControl(false);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
2014-06-09 11:12:44 -04:00
|
|
|
* @return true if the compressor is on
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
bool Compressor::Enabled() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getCompressor(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-09 11:12:44 -04:00
|
|
|
* @return true if pressure is low
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
bool Compressor::GetPressureSwitchValue() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getPressureSwitch(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
2014-06-09 11:12:44 -04:00
|
|
|
* @return The current through the compressor, in amps
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
float Compressor::GetCompressorCurrent() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
float value;
|
|
|
|
|
|
|
|
|
|
value = getCompressorCurrent(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-06-09 11:12:44 -04:00
|
|
|
|
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.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
void Compressor::SetClosedLoopControl(bool on) {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
|
|
|
|
|
setClosedLoopControl(m_pcm_pointer, on, &status);
|
|
|
|
|
|
|
|
|
|
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.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2014-06-09 11:12:44 -04:00
|
|
|
bool Compressor::GetClosedLoopControl() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getClosedLoopControl(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
2014-12-26 19:40:39 -05:00
|
|
|
/**
|
|
|
|
|
* @return true if PCM is in fault state : Compressor Drive is
|
|
|
|
|
* disabled due to compressor current being too high.
|
|
|
|
|
*/
|
|
|
|
|
bool Compressor::GetCompressorCurrentTooHighFault() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getCompressorCurrentTooHighFault(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return true if PCM sticky fault is set : Compressor Drive is
|
|
|
|
|
* disabled due to compressor current being too high.
|
|
|
|
|
*/
|
|
|
|
|
bool Compressor::GetCompressorCurrentTooHighStickyFault() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getCompressorCurrentTooHighStickyFault(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return true if PCM sticky fault is set : Compressor output
|
|
|
|
|
* appears to be shorted.
|
|
|
|
|
*/
|
|
|
|
|
bool Compressor::GetCompressorShortedStickyFault() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getCompressorShortedStickyFault(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return true if PCM is in fault state : Compressor output
|
|
|
|
|
* appears to be shorted.
|
|
|
|
|
*/
|
|
|
|
|
bool Compressor::GetCompressorShortedFault() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getCompressorShortedFault(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return true if PCM sticky fault is set : Compressor does not
|
|
|
|
|
* appear to be wired, i.e. compressor is
|
|
|
|
|
* not drawing enough current.
|
|
|
|
|
*/
|
|
|
|
|
bool Compressor::GetCompressorNotConnectedStickyFault() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getCompressorNotConnectedStickyFault(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @return true if PCM is in fault state : Compressor does not
|
|
|
|
|
* appear to be wired, i.e. compressor is
|
|
|
|
|
* not drawing enough current.
|
|
|
|
|
*/
|
|
|
|
|
bool Compressor::GetCompressorNotConnectedFault() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
|
|
|
|
|
|
|
|
|
value = getCompressorNotConnectedFault(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
void Compressor::ClearAllPCMStickyFaults() {
|
|
|
|
|
int32_t status = 0;
|
|
|
|
|
|
|
|
|
|
clearAllPCMStickyFaults(m_pcm_pointer, &status);
|
|
|
|
|
|
|
|
|
|
if(status) {
|
|
|
|
|
wpi_setWPIError(Timeout);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
void Compressor::UpdateTable() {
|
2014-06-09 11:12:44 -04:00
|
|
|
if(m_table) {
|
|
|
|
|
m_table->PutBoolean("Enabled", Enabled());
|
2013-12-15 18:30:16 -05:00
|
|
|
m_table->PutBoolean("Pressure switch", GetPressureSwitchValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compressor::StartLiveWindowMode() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compressor::StopLiveWindowMode() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Compressor::GetSmartDashboardType() {
|
|
|
|
|
return "Compressor";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Compressor::InitTable(ITable *subTable) {
|
|
|
|
|
m_table = subTable;
|
|
|
|
|
UpdateTable();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 11:12:44 -04:00
|
|
|
ITable *Compressor::GetTable() {
|
2013-12-15 18:30:16 -05:00
|
|
|
return m_table;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-09 11:12:44 -04:00
|
|
|
void Compressor::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) {
|
|
|
|
|
if(value.b) Start();
|
|
|
|
|
else Stop();
|
|
|
|
|
|
|
|
|
|
}
|