Files
allwpilib/wpilibc/wpilibC++Devices/src/Compressor.cpp

277 lines
6.4 KiB
C++
Raw Normal View History

/*
* Compressor.cpp
*/
#include "Compressor.h"
#include "WPIErrors.h"
/**
* Constructor
*
* @param module The PCM ID to use (0-62)
*/
Compressor::Compressor(uint8_t pcmID) {
m_pcm_pointer = initializeCompressor(pcmID);
SetClosedLoopControl(true);
}
/**
* Starts closed-loop control. Note that closed loop control is enabled by
* default.
*/
void Compressor::Start() { SetClosedLoopControl(true); }
/**
* Stops closed-loop control. Note that closed loop control is enabled by
* default.
*/
void Compressor::Stop() { SetClosedLoopControl(false); }
/**
* Check if compressor output is active
* @return true if the compressor is on
*/
bool Compressor::Enabled() const {
int32_t status = 0;
bool value;
value = getCompressor(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* Check if the pressure switch is triggered
* @return true if pressure is low
*/
bool Compressor::GetPressureSwitchValue() const {
int32_t status = 0;
bool value;
value = getPressureSwitch(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* Query how much current the compressor is drawing
* @return The current through the compressor, in amps
*/
float Compressor::GetCompressorCurrent() const {
int32_t status = 0;
float value;
value = getCompressorCurrent(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* Enables or disables automatically turning the compressor on when the
* pressure is low.
* @param on Set to true to enable closed loop control of the compressor. False
* to disable.
*/
void Compressor::SetClosedLoopControl(bool on) {
int32_t status = 0;
setClosedLoopControl(m_pcm_pointer, on, &status);
if (status) {
wpi_setWPIError(Timeout);
}
}
/**
* Returns true if the compressor will automatically turn on when the
* pressure is low.
* @return True if closed loop control of the compressor is enabled. False if
* disabled.
*/
bool Compressor::GetClosedLoopControl() const {
int32_t status = 0;
bool value;
value = getClosedLoopControl(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* Query if the compressor output has been disabled due to high current draw.
* @return true if PCM is in fault state : Compressor Drive is
* disabled due to compressor current being too high.
*/
bool Compressor::GetCompressorCurrentTooHighFault() const {
int32_t status = 0;
bool value;
value = getCompressorCurrentTooHighFault(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* 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.
*/
bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
int32_t status = 0;
bool value;
value = getCompressorCurrentTooHighStickyFault(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* 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.
*/
bool Compressor::GetCompressorShortedStickyFault() const {
int32_t status = 0;
bool value;
value = getCompressorShortedStickyFault(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* Query if the compressor output has been disabled due to a short circuit.
* @return true if PCM is in fault state : Compressor output
* appears to be shorted.
*/
bool Compressor::GetCompressorShortedFault() const {
int32_t status = 0;
bool value;
value = getCompressorShortedFault(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* Query if the compressor output does not appear to be wired (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 does not
* appear to be wired, i.e. compressor is
* not drawing enough current.
*/
bool Compressor::GetCompressorNotConnectedStickyFault() const {
int32_t status = 0;
bool value;
value = getCompressorNotConnectedStickyFault(m_pcm_pointer, &status);
if (status) {
wpi_setWPIError(Timeout);
}
return value;
}
/**
* Query if the compressor output does not appear to be wired.
* @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() const {
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);
}
}
void Compressor::UpdateTable() {
if (m_table) {
m_table->PutBoolean("Enabled", Enabled());
m_table->PutBoolean("Pressure switch", GetPressureSwitchValue());
}
}
void Compressor::StartLiveWindowMode() {}
void Compressor::StopLiveWindowMode() {}
std::string Compressor::GetSmartDashboardType() const { return "Compressor"; }
artf4154: Get rid of raw pointers in C++. This deals with the majority of the user-facing code in wpilibC++Devices and a substantial portion of it in wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests are untouched except where it is necessary to make them work with the rest of the libraries. There is still a lot to do in the following areas: -The HAL (which we may not want to touch at all). -The I2C, Serial, and SPI interfaces in wpilibC++Devices, which I haven't gotten around to doing yet. -Most wpilibC++Devices classes have void* pointers for interacting with the HAL. -InterruptableSensorBase passes a void *params for the interrupt handler. -I haven't converted all the const char* to std::strings. -There are plenty of other cases of raw pointers still existing. -This doesn't fall directly under raw pointer stuff, but move syntax and rvalue references could be introduced in many places. -I haven't touched vision code. -The Resource classes conflict (one is in the hal, the other in wpilibC++). Someone should figure out a more permanent fix (eg, just renaming them), then doing what I did (making a new namespace for one of them, essentially the same as renaming it). A few other things: -I created a NullDeleter class which is marked as deprecated. What this does is it can be passed as the deleter to a std::shared_ptr so that when you are converting raw pointers to shared_ptrs the shared_ptr doesn't do any deletion if someone else owns the raw pointer. This should only be used in making old raw pointer UIs. -I had to alter the build.gradle so that it did not emit errors when deprecated functions called deprecated functions. Unfortunately, gradle doesn't appear to be actually printing out gcc warnigns for some reason. The best way I have found to fix this is to patch the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff) so that a deprecated function calling a deprecated function is fine but a non-deprecated function calling a deprecated function will throw a warning (which we then elevate with -Werror). I believe that clang deals with this properly, although I have not tried it myself. Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
void Compressor::InitTable(::std::shared_ptr<ITable> subTable) {
m_table = subTable;
UpdateTable();
}
artf4154: Get rid of raw pointers in C++. This deals with the majority of the user-facing code in wpilibC++Devices and a substantial portion of it in wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests are untouched except where it is necessary to make them work with the rest of the libraries. There is still a lot to do in the following areas: -The HAL (which we may not want to touch at all). -The I2C, Serial, and SPI interfaces in wpilibC++Devices, which I haven't gotten around to doing yet. -Most wpilibC++Devices classes have void* pointers for interacting with the HAL. -InterruptableSensorBase passes a void *params for the interrupt handler. -I haven't converted all the const char* to std::strings. -There are plenty of other cases of raw pointers still existing. -This doesn't fall directly under raw pointer stuff, but move syntax and rvalue references could be introduced in many places. -I haven't touched vision code. -The Resource classes conflict (one is in the hal, the other in wpilibC++). Someone should figure out a more permanent fix (eg, just renaming them), then doing what I did (making a new namespace for one of them, essentially the same as renaming it). A few other things: -I created a NullDeleter class which is marked as deprecated. What this does is it can be passed as the deleter to a std::shared_ptr so that when you are converting raw pointers to shared_ptrs the shared_ptr doesn't do any deletion if someone else owns the raw pointer. This should only be used in making old raw pointer UIs. -I had to alter the build.gradle so that it did not emit errors when deprecated functions called deprecated functions. Unfortunately, gradle doesn't appear to be actually printing out gcc warnigns for some reason. The best way I have found to fix this is to patch the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff) so that a deprecated function calling a deprecated function is fine but a non-deprecated function calling a deprecated function will throw a warning (which we then elevate with -Werror). I believe that clang deals with this properly, although I have not tried it myself. Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
::std::shared_ptr<ITable> Compressor::GetTable() const { return m_table; }
artf4154: Get rid of raw pointers in C++. This deals with the majority of the user-facing code in wpilibC++Devices and a substantial portion of it in wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests are untouched except where it is necessary to make them work with the rest of the libraries. There is still a lot to do in the following areas: -The HAL (which we may not want to touch at all). -The I2C, Serial, and SPI interfaces in wpilibC++Devices, which I haven't gotten around to doing yet. -Most wpilibC++Devices classes have void* pointers for interacting with the HAL. -InterruptableSensorBase passes a void *params for the interrupt handler. -I haven't converted all the const char* to std::strings. -There are plenty of other cases of raw pointers still existing. -This doesn't fall directly under raw pointer stuff, but move syntax and rvalue references could be introduced in many places. -I haven't touched vision code. -The Resource classes conflict (one is in the hal, the other in wpilibC++). Someone should figure out a more permanent fix (eg, just renaming them), then doing what I did (making a new namespace for one of them, essentially the same as renaming it). A few other things: -I created a NullDeleter class which is marked as deprecated. What this does is it can be passed as the deleter to a std::shared_ptr so that when you are converting raw pointers to shared_ptrs the shared_ptr doesn't do any deletion if someone else owns the raw pointer. This should only be used in making old raw pointer UIs. -I had to alter the build.gradle so that it did not emit errors when deprecated functions called deprecated functions. Unfortunately, gradle doesn't appear to be actually printing out gcc warnigns for some reason. The best way I have found to fix this is to patch the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff) so that a deprecated function calling a deprecated function is fine but a non-deprecated function calling a deprecated function will throw a warning (which we then elevate with -Werror). I believe that clang deals with this properly, although I have not tried it myself. Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
2015-06-30 15:01:20 -04:00
void Compressor::ValueChanged(::std::shared_ptr<ITable> source, const std::string& key,
EntryValue value, bool isNew) {
if (value.b)
Start();
else
Stop();
}