2016-07-10 08:33:27 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-06-27 20:39:00 -07:00
|
|
|
/* Copyright (c) 2014-2020 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
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/Compressor.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/Compressor.h>
|
2019-11-08 22:53:20 -08:00
|
|
|
#include <hal/FRCUsageReporting.h>
|
2018-07-20 00:03:45 -07:00
|
|
|
#include <hal/Ports.h>
|
|
|
|
|
#include <hal/Solenoid.h>
|
2017-08-27 00:11:52 -07:00
|
|
|
|
2018-07-20 00:03:45 -07:00
|
|
|
#include "frc/WPIErrors.h"
|
|
|
|
|
#include "frc/smartdashboard/SendableBuilder.h"
|
2019-09-14 15:22:54 -05:00
|
|
|
#include "frc/smartdashboard/SendableRegistry.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
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) {
|
2019-11-08 22:53:20 -08:00
|
|
|
wpi_setHALErrorWithRange(status, 0, HAL_GetNumPCMModules(), pcmID);
|
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
|
|
|
|
2019-10-29 21:34:10 -07:00
|
|
|
HAL_Report(HALUsageReporting::kResourceType_Compressor, pcmID + 1);
|
2019-09-14 15:22:54 -05:00
|
|
|
SendableRegistry::GetInstance().AddLW(this, "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");
|
2020-06-27 20:39:00 -07:00
|
|
|
builder.AddBooleanProperty(
|
|
|
|
|
"Enabled", [=]() { return Enabled(); },
|
|
|
|
|
[=](bool value) {
|
|
|
|
|
if (value)
|
|
|
|
|
Start();
|
|
|
|
|
else
|
|
|
|
|
Stop();
|
|
|
|
|
});
|
2017-12-04 23:28:33 -08:00
|
|
|
builder.AddBooleanProperty(
|
|
|
|
|
"Pressure switch", [=]() { return GetPressureSwitchValue(); }, nullptr);
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|