2016-07-10 08:33:27 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2018-01-02 09:20:21 -08:00
|
|
|
/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
|
2016-07-10 08:33:27 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* 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 "Compressor.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2017-08-27 00:11:52 -07:00
|
|
|
#include <HAL/Compressor.h>
|
|
|
|
|
#include <HAL/HAL.h>
|
|
|
|
|
#include <HAL/Ports.h>
|
|
|
|
|
#include <HAL/Solenoid.h>
|
|
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
#include "SmartDashboard/SendableBuilder.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "WPIErrors.h"
|
|
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2016-09-06 00:01:45 -07:00
|
|
|
Compressor::Compressor(int pcmID) : m_module(pcmID) {
|
2016-07-02 08:22:44 -07:00
|
|
|
int32_t status = 0;
|
2016-07-09 01:12:37 -07:00
|
|
|
m_compressorHandle = HAL_InitializeCompressor(m_module, &status);
|
2016-07-02 08:22:44 -07:00
|
|
|
if (status != 0) {
|
2016-07-13 20:29:28 -07:00
|
|
|
wpi_setErrorWithContextRange(status, 0, HAL_GetNumPCMModules(), pcmID,
|
|
|
|
|
HAL_GetErrorMessage(status));
|
2016-07-02 08:22:44 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2015-06-24 01:06:29 -07:00
|
|
|
SetClosedLoopControl(true);
|
2017-09-19 21:17:27 -07:00
|
|
|
|
|
|
|
|
HAL_Report(HALUsageReporting::kResourceType_Compressor, pcmID);
|
2017-12-04 23:28:33 -08:00
|
|
|
SetName("Compressor", pcmID);
|
2017-09-02 00:17:43 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-02 08:22:44 -07:00
|
|
|
void Compressor::Start() {
|
|
|
|
|
if (StatusIsFatal()) return;
|
|
|
|
|
SetClosedLoopControl(true);
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-07-02 08:22:44 -07:00
|
|
|
void Compressor::Stop() {
|
|
|
|
|
if (StatusIsFatal()) return;
|
|
|
|
|
SetClosedLoopControl(false);
|
|
|
|
|
}
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::Enabled() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
value = HAL_GetCompressor(m_compressorHandle, &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
|
|
|
}
|
|
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetPressureSwitchValue() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2016-07-09 01:12:37 -07:00
|
|
|
value = HAL_GetCompressorPressureSwitch(m_compressorHandle, &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
|
|
|
}
|
|
|
|
|
|
2016-11-20 07:25:03 -08:00
|
|
|
double Compressor::GetCompressorCurrent() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return 0;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2016-11-20 07:25:03 -08:00
|
|
|
double value;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
value = HAL_GetCompressorCurrent(m_compressorHandle, &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
|
|
|
void Compressor::SetClosedLoopControl(bool on) {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2016-07-09 01:12:37 -07:00
|
|
|
HAL_SetCompressorClosedLoopControl(m_compressorHandle, 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
|
|
|
}
|
|
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetClosedLoopControl() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-06-09 11:12:44 -04:00
|
|
|
|
2016-07-09 01:12:37 -07:00
|
|
|
value = HAL_GetCompressorClosedLoopControl(m_compressorHandle, &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
|
|
|
}
|
|
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorCurrentTooHighFault() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
value = HAL_GetCompressorCurrentTooHighFault(m_compressorHandle, &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
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
value =
|
|
|
|
|
HAL_GetCompressorCurrentTooHighStickyFault(m_compressorHandle, &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
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorShortedStickyFault() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
value = HAL_GetCompressorShortedStickyFault(m_compressorHandle, &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
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorShortedFault() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
value = HAL_GetCompressorShortedFault(m_compressorHandle, &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
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorNotConnectedStickyFault() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
value = HAL_GetCompressorNotConnectedStickyFault(m_compressorHandle, &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
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
bool Compressor::GetCompressorNotConnectedFault() const {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return false;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
|
|
|
|
bool value;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2016-07-09 00:24:26 -07:00
|
|
|
value = HAL_GetCompressorNotConnectedFault(m_compressorHandle, &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
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2014-12-26 19:40:39 -05:00
|
|
|
void Compressor::ClearAllPCMStickyFaults() {
|
2016-07-02 08:22:44 -07:00
|
|
|
if (StatusIsFatal()) return;
|
2015-06-25 15:07:55 -04:00
|
|
|
int32_t status = 0;
|
2014-12-26 19:40:39 -05:00
|
|
|
|
2016-07-09 01:12:37 -07:00
|
|
|
HAL_ClearAllPCMStickyFaults(m_module, &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
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
|
2017-12-04 23:28:33 -08:00
|
|
|
void Compressor::InitSendable(SendableBuilder& builder) {
|
|
|
|
|
builder.SetSmartDashboardType("Compressor");
|
|
|
|
|
builder.AddBooleanProperty("Enabled", [=]() { return Enabled(); },
|
|
|
|
|
[=](bool value) {
|
|
|
|
|
if (value)
|
|
|
|
|
Start();
|
|
|
|
|
else
|
|
|
|
|
Stop();
|
|
|
|
|
});
|
|
|
|
|
builder.AddBooleanProperty(
|
|
|
|
|
"Pressure switch", [=]() { return GetPressureSwitchValue(); }, nullptr);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|