2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-08-23 22:06:13 -07:00
|
|
|
/* Copyright (c) 2008-2017 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05: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. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "SolenoidBase.h"
|
|
|
|
|
|
2017-08-27 00:11:52 -07:00
|
|
|
#include <HAL/HAL.h>
|
|
|
|
|
#include <HAL/Solenoid.h>
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
2014-12-29 14:09:37 -05:00
|
|
|
* @param moduleNumber The CAN PCM ID.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2016-09-06 00:01:45 -07:00
|
|
|
SolenoidBase::SolenoidBase(int moduleNumber) : m_moduleNumber(moduleNumber) {}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read all 8 solenoids as a single byte
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
2017-05-08 21:55:11 -07:00
|
|
|
* @param module the module to read from
|
2013-12-15 18:30:16 -05:00
|
|
|
* @return The current value of all 8 solenoids on the module.
|
|
|
|
|
*/
|
2017-05-08 21:55:11 -07:00
|
|
|
int SolenoidBase::GetAll(int module) {
|
2016-09-06 00:01:45 -07:00
|
|
|
int value = 0;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2017-05-08 21:55:11 -07:00
|
|
|
value = HAL_GetAllSolenoids(module, &status);
|
|
|
|
|
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
2015-06-25 15:07:55 -04:00
|
|
|
return value;
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2017-05-08 21:55:11 -07:00
|
|
|
/**
|
|
|
|
|
* Read all 8 solenoids as a single byte
|
|
|
|
|
*
|
|
|
|
|
* @return The current value of all 8 solenoids on the module.
|
|
|
|
|
*/
|
|
|
|
|
int SolenoidBase::GetAll() const {
|
|
|
|
|
return SolenoidBase::GetAll(m_moduleNumber);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-26 19:40:39 -05:00
|
|
|
/**
|
|
|
|
|
* Reads complete solenoid blacklist for all 8 solenoids as a single byte.
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
2016-05-20 17:30:37 -07:00
|
|
|
* If a solenoid is shorted, it is added to the blacklist and
|
|
|
|
|
* disabled until power cycle, or until faults are cleared.
|
|
|
|
|
* @see ClearAllPCMStickyFaults()
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
2017-05-08 21:55:11 -07:00
|
|
|
* @param module the module to read from
|
2014-12-26 19:40:39 -05:00
|
|
|
* @return The solenoid blacklist of all 8 solenoids on the module.
|
|
|
|
|
*/
|
2017-05-08 21:55:11 -07:00
|
|
|
int SolenoidBase::GetPCMSolenoidBlackList(int module) {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2017-05-08 21:55:11 -07:00
|
|
|
return HAL_GetPCMSolenoidBlackList(module, &status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reads complete solenoid blacklist for all 8 solenoids as a single byte.
|
|
|
|
|
*
|
|
|
|
|
* If a solenoid is shorted, it is added to the blacklist and
|
|
|
|
|
* disabled until power cycle, or until faults are cleared.
|
|
|
|
|
* @see ClearAllPCMStickyFaults()
|
|
|
|
|
*
|
|
|
|
|
* @return The solenoid blacklist of all 8 solenoids on the module.
|
|
|
|
|
*/
|
|
|
|
|
int SolenoidBase::GetPCMSolenoidBlackList() const {
|
|
|
|
|
return SolenoidBase::GetPCMSolenoidBlackList(m_moduleNumber);
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2014-12-26 19:40:39 -05:00
|
|
|
/**
|
2017-05-08 21:55:11 -07:00
|
|
|
* @param module the module to read from
|
2016-05-20 17:30:37 -07:00
|
|
|
* @return true if PCM sticky fault is set : The common highside solenoid
|
|
|
|
|
* voltage rail is too low, most likely a solenoid channel is shorted.
|
2014-12-26 19:40:39 -05:00
|
|
|
*/
|
2017-05-08 21:55:11 -07:00
|
|
|
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module) {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2017-05-08 21:55:11 -07:00
|
|
|
return HAL_GetPCMSolenoidVoltageStickyFault(module, &status);
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2014-12-26 19:40:39 -05:00
|
|
|
/**
|
2017-05-08 21:55:11 -07:00
|
|
|
* @return true if PCM sticky fault is set : The common highside solenoid
|
|
|
|
|
* voltage rail is too low, most likely a solenoid channel is shorted.
|
|
|
|
|
*/
|
|
|
|
|
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault() const {
|
|
|
|
|
return SolenoidBase::GetPCMSolenoidVoltageStickyFault(m_moduleNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param module the module to read from
|
2016-05-20 17:30:37 -07:00
|
|
|
* @return true if PCM is in fault state : The common highside solenoid voltage
|
|
|
|
|
* rail is too low, most likely a solenoid channel is shorted.
|
2014-12-26 19:40:39 -05:00
|
|
|
*/
|
2017-05-08 21:55:11 -07:00
|
|
|
bool SolenoidBase::GetPCMSolenoidVoltageFault(int module) {
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2017-05-08 21:55:11 -07:00
|
|
|
return HAL_GetPCMSolenoidVoltageFault(module, &status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return true if PCM is in fault state : The common highside solenoid voltage
|
|
|
|
|
* rail is too low, most likely a solenoid channel is shorted.
|
|
|
|
|
*/
|
|
|
|
|
bool SolenoidBase::GetPCMSolenoidVoltageFault() const {
|
|
|
|
|
return SolenoidBase::GetPCMSolenoidVoltageFault(m_moduleNumber);
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
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
|
2016-05-20 17:30:37 -07:00
|
|
|
* 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.
|
2017-05-08 21:55:11 -07:00
|
|
|
*
|
|
|
|
|
* @param module the module to read from
|
2014-12-26 19:40:39 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SolenoidBase::ClearAllPCMStickyFaults(int module) {
|
|
|
|
|
int32_t status = 0;
|
2017-05-08 21:55:11 -07:00
|
|
|
return HAL_ClearAllPCMStickyFaults(module, &status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 SolenoidBase::ClearAllPCMStickyFaults() {
|
|
|
|
|
SolenoidBase::ClearAllPCMStickyFaults(m_moduleNumber);
|
2014-12-26 19:40:39 -05:00
|
|
|
}
|