mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Support for the CAN pneumatics module in C++ and Java
Change-Id: I2ccb1d13d1c5da00a99329c761b75a6c2b3ea56d
This commit is contained in:
176
wpilibc/lib/PCMCompressor.cpp
Normal file
176
wpilibc/lib/PCMCompressor.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* PCMCompressor.cpp
|
||||
*/
|
||||
|
||||
#include "PCMCompressor.h"
|
||||
#include "WPIErrors.h"
|
||||
|
||||
void PCMCompressor::InitCompressor(uint8_t module) {
|
||||
m_table = 0;
|
||||
m_pcm_pointer = initializeCompressor(module);
|
||||
|
||||
SetClosedLoopControl(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Uses the default solenoid module number
|
||||
*/
|
||||
PCMCompressor::PCMCompressor() {
|
||||
InitCompressor(GetDefaultSolenoidModule());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param module The module number to use (1 or 2)
|
||||
*/
|
||||
PCMCompressor::PCMCompressor(uint8_t module) {
|
||||
InitCompressor(module);
|
||||
}
|
||||
|
||||
PCMCompressor::~PCMCompressor() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the compressor and disables automatic closed-loop control
|
||||
*/
|
||||
void PCMCompressor::Start() {
|
||||
SetClosedLoopControl(false);
|
||||
SetCompressor(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the compressor and disables automatic closed-loop control
|
||||
*/
|
||||
void PCMCompressor::Stop() {
|
||||
SetClosedLoopControl(false);
|
||||
SetCompressor(false);
|
||||
}
|
||||
|
||||
void PCMCompressor::SetCompressor(bool on) {
|
||||
int32_t status = 0;
|
||||
|
||||
setCompressor(m_pcm_pointer, on, &status);
|
||||
|
||||
if(status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if the compressor is on
|
||||
*/
|
||||
bool PCMCompressor::Enabled() {
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = getCompressor(m_pcm_pointer, &status);
|
||||
|
||||
if(status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if pressure is low
|
||||
*/
|
||||
bool PCMCompressor::GetPressureSwitchValue() {
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = getPressureSwitch(m_pcm_pointer, &status);
|
||||
|
||||
if(status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The current through the compressor, in amps
|
||||
*/
|
||||
float PCMCompressor::GetCompressorCurrent() {
|
||||
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.
|
||||
*/
|
||||
void PCMCompressor::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.
|
||||
*/
|
||||
bool PCMCompressor::GetClosedLoopControl() {
|
||||
int32_t status = 0;
|
||||
bool value;
|
||||
|
||||
value = getClosedLoopControl(m_pcm_pointer, &status);
|
||||
|
||||
if(status) {
|
||||
wpi_setWPIError(Timeout);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void PCMCompressor::UpdateTable() {
|
||||
if(m_table) {
|
||||
m_table->PutBoolean("Enabled", Enabled());
|
||||
m_table->PutBoolean("Pressure switch", GetPressureSwitchValue());
|
||||
}
|
||||
}
|
||||
|
||||
void PCMCompressor::StartLiveWindowMode() {
|
||||
}
|
||||
|
||||
void PCMCompressor::StopLiveWindowMode() {
|
||||
}
|
||||
|
||||
std::string PCMCompressor::GetSmartDashboardType() {
|
||||
return "PCMCompressor";
|
||||
}
|
||||
|
||||
void PCMCompressor::InitTable(ITable *subTable) {
|
||||
m_table = subTable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
ITable *PCMCompressor::GetTable() {
|
||||
return m_table;
|
||||
}
|
||||
|
||||
void PCMCompressor::ValueChanged(ITable* source, const std::string& key, EntryValue value, bool isNew) {
|
||||
if(value.b) Start();
|
||||
else Stop();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user