[hal] Add a unified PCM object (#3331)

This commit is contained in:
Thad House
2021-06-05 22:36:39 -07:00
committed by GitHub
parent dea841103d
commit 0e702eb799
103 changed files with 2643 additions and 5676 deletions

View File

@@ -1,134 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/Compressor.h"
#include <hal/Compressor.h>
#include <hal/FRCUsageReporting.h>
#include <hal/Ports.h>
#include <hal/Solenoid.h>
#include "frc/Errors.h"
#include "frc/smartdashboard/SendableBuilder.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
Compressor::Compressor(int pcmID) : m_module(pcmID) {
int32_t status = 0;
m_compressorHandle = HAL_InitializeCompressor(m_module, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
SetClosedLoopControl(true);
HAL_Report(HALUsageReporting::kResourceType_Compressor, pcmID + 1);
SendableRegistry::GetInstance().AddLW(this, "Compressor", pcmID);
}
void Compressor::Start() {
SetClosedLoopControl(true);
}
void Compressor::Stop() {
SetClosedLoopControl(false);
}
bool Compressor::Enabled() const {
int32_t status = 0;
bool value = HAL_GetCompressor(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
bool Compressor::GetPressureSwitchValue() const {
int32_t status = 0;
bool value = HAL_GetCompressorPressureSwitch(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
double Compressor::GetCompressorCurrent() const {
int32_t status = 0;
double value = HAL_GetCompressorCurrent(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
void Compressor::SetClosedLoopControl(bool on) {
int32_t status = 0;
HAL_SetCompressorClosedLoopControl(m_compressorHandle, on, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
}
bool Compressor::GetClosedLoopControl() const {
int32_t status = 0;
bool value = HAL_GetCompressorClosedLoopControl(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
bool Compressor::GetCompressorCurrentTooHighFault() const {
int32_t status = 0;
bool value =
HAL_GetCompressorCurrentTooHighFault(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
bool Compressor::GetCompressorCurrentTooHighStickyFault() const {
int32_t status = 0;
bool value =
HAL_GetCompressorCurrentTooHighStickyFault(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
bool Compressor::GetCompressorShortedStickyFault() const {
int32_t status = 0;
bool value = HAL_GetCompressorShortedStickyFault(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
bool Compressor::GetCompressorShortedFault() const {
int32_t status = 0;
bool value = HAL_GetCompressorShortedFault(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
bool Compressor::GetCompressorNotConnectedStickyFault() const {
int32_t status = 0;
bool value =
HAL_GetCompressorNotConnectedStickyFault(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
bool Compressor::GetCompressorNotConnectedFault() const {
int32_t status = 0;
bool value = HAL_GetCompressorNotConnectedFault(m_compressorHandle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return value;
}
void Compressor::ClearAllPCMStickyFaults() {
int32_t status = 0;
HAL_ClearAllPCMStickyFaults(m_module, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
}
int Compressor::GetModule() const {
return m_module;
}
void Compressor::InitSendable(SendableBuilder& builder) {
builder.SetSmartDashboardType("Compressor");
builder.AddBooleanProperty(
"Closed Loop Control", [=]() { return GetClosedLoopControl(); },
[=](bool value) { SetClosedLoopControl(value); });
builder.AddBooleanProperty(
"Enabled", [=] { return Enabled(); }, nullptr);
builder.AddBooleanProperty(
"Pressure switch", [=]() { return GetPressureSwitchValue(); }, nullptr);
}

View File

@@ -9,7 +9,7 @@
#include <hal/FRCUsageReporting.h>
#include <hal/HALBase.h>
#include <hal/Ports.h>
#include <hal/Solenoid.h>
#include <wpi/NullDeleter.h>
#include "frc/Errors.h"
#include "frc/SensorUtil.h"
@@ -18,107 +18,74 @@
using namespace frc;
DoubleSolenoid::DoubleSolenoid(int forwardChannel, int reverseChannel)
: DoubleSolenoid(SensorUtil::GetDefaultSolenoidModule(), forwardChannel,
reverseChannel) {}
DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
DoubleSolenoid::DoubleSolenoid(PneumaticsBase& module, int forwardChannel,
int reverseChannel)
: SolenoidBase(moduleNumber),
m_forwardChannel(forwardChannel),
m_reverseChannel(reverseChannel) {
if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) {
throw FRC_MakeError(err::ModuleIndexOutOfRange, "Module {}",
m_moduleNumber);
}
if (!SensorUtil::CheckSolenoidChannel(m_forwardChannel)) {
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
m_forwardChannel);
}
if (!SensorUtil::CheckSolenoidChannel(m_reverseChannel)) {
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
m_reverseChannel);
}
int32_t status = 0;
m_forwardHandle = HAL_InitializeSolenoidPort(
HAL_GetPortWithModule(moduleNumber, m_forwardChannel), &status);
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
m_forwardChannel);
: DoubleSolenoid{std::shared_ptr<PneumaticsBase>{
&module, wpi::NullDeleter<PneumaticsBase>()},
forwardChannel, reverseChannel} {}
m_reverseHandle = HAL_InitializeSolenoidPort(
HAL_GetPortWithModule(moduleNumber, m_reverseChannel), &status);
if (status != 0) {
// free forward solenoid
HAL_FreeSolenoidPort(m_forwardHandle);
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
m_reverseChannel);
return;
DoubleSolenoid::DoubleSolenoid(PneumaticsBase* module, int forwardChannel,
int reverseChannel)
: DoubleSolenoid{std::shared_ptr<PneumaticsBase>{
module, wpi::NullDeleter<PneumaticsBase>()},
forwardChannel, reverseChannel} {}
DoubleSolenoid::DoubleSolenoid(std::shared_ptr<PneumaticsBase> module,
int forwardChannel, int reverseChannel)
: m_module{std::move(module)} {
if (!m_module->CheckSolenoidChannel(forwardChannel)) {
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
forwardChannel);
}
if (!m_module->CheckSolenoidChannel(reverseChannel)) {
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
reverseChannel);
}
m_forwardMask = 1 << m_forwardChannel;
m_reverseMask = 1 << m_reverseChannel;
m_forwardChannel = forwardChannel;
m_reverseChannel = reverseChannel;
m_forwardMask = 1 << forwardChannel;
m_reverseMask = 1 << reverseChannel;
m_mask = m_forwardMask | m_reverseMask;
HAL_Report(HALUsageReporting::kResourceType_Solenoid, m_forwardChannel + 1,
m_moduleNumber + 1);
m_module->GetModuleNumber() + 1);
HAL_Report(HALUsageReporting::kResourceType_Solenoid, m_reverseChannel + 1,
m_moduleNumber + 1);
SendableRegistry::GetInstance().AddLW(this, "DoubleSolenoid", m_moduleNumber,
m_forwardChannel);
m_module->GetModuleNumber() + 1);
SendableRegistry::GetInstance().AddLW(
this, "DoubleSolenoid", m_module->GetModuleNumber(), m_forwardChannel);
}
DoubleSolenoid::~DoubleSolenoid() {
HAL_FreeSolenoidPort(m_forwardHandle);
HAL_FreeSolenoidPort(m_reverseHandle);
}
DoubleSolenoid::~DoubleSolenoid() {}
void DoubleSolenoid::Set(Value value) {
bool forward = false;
bool reverse = false;
int setValue = 0;
switch (value) {
case kOff:
forward = false;
reverse = false;
setValue = 0;
break;
case kForward:
forward = true;
reverse = false;
setValue = m_forwardMask;
break;
case kReverse:
forward = false;
reverse = true;
setValue = m_reverseMask;
break;
}
int fstatus = 0;
HAL_SetSolenoid(m_forwardHandle, forward, &fstatus);
int rstatus = 0;
HAL_SetSolenoid(m_reverseHandle, reverse, &rstatus);
FRC_CheckErrorStatus(fstatus, "Module {} Channel {}", m_moduleNumber,
m_forwardChannel);
FRC_CheckErrorStatus(rstatus, "Module {} Channel {}", m_moduleNumber,
m_reverseChannel);
m_module->SetSolenoids(m_mask, setValue);
}
DoubleSolenoid::Value DoubleSolenoid::Get() const {
int fstatus = 0;
int rstatus = 0;
bool valueForward = HAL_GetSolenoid(m_forwardHandle, &fstatus);
bool valueReverse = HAL_GetSolenoid(m_reverseHandle, &rstatus);
auto values = m_module->GetSolenoids();
FRC_CheckErrorStatus(fstatus, "Module {} Channel {}", m_moduleNumber,
m_forwardChannel);
FRC_CheckErrorStatus(rstatus, "Module {} Channel {}", m_moduleNumber,
m_reverseChannel);
if (valueForward) {
return kForward;
} else if (valueReverse) {
return kReverse;
if ((values & m_forwardMask) != 0) {
return Value::kForward;
} else if ((values & m_reverseMask) != 0) {
return Value::kReverse;
} else {
return kOff;
return Value::kOff;
}
}
@@ -140,14 +107,12 @@ int DoubleSolenoid::GetRevChannel() const {
return m_reverseChannel;
}
bool DoubleSolenoid::IsFwdSolenoidBlackListed() const {
int blackList = GetPCMSolenoidBlackList(m_moduleNumber);
return (blackList & m_forwardMask) != 0;
bool DoubleSolenoid::IsFwdSolenoidDisabled() const {
return (m_module->GetSolenoidDisabledList() & m_forwardMask) != 0;
}
bool DoubleSolenoid::IsRevSolenoidBlackListed() const {
int blackList = GetPCMSolenoidBlackList(m_moduleNumber);
return (blackList & m_reverseMask) != 0;
bool DoubleSolenoid::IsRevSolenoidDisabled() const {
return (m_module->GetSolenoidDisabledList() & m_reverseMask) != 0;
}
void DoubleSolenoid::InitSendable(SendableBuilder& builder) {

View File

@@ -0,0 +1,162 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/PneumaticsControlModule.h"
#include <hal/CTREPCM.h>
#include <wpi/StackTrace.h>
#include "frc/Errors.h"
#include "frc/SensorUtil.h"
using namespace frc;
PneumaticsControlModule::PneumaticsControlModule()
: PneumaticsControlModule{SensorUtil::GetDefaultCTREPCMModule()} {}
PneumaticsControlModule::PneumaticsControlModule(int module) {
int32_t status = 0;
std::string stackTrace = wpi::GetStackTrace(1);
m_handle = HAL_InitializeCTREPCM(module, stackTrace.c_str(), &status);
FRC_CheckErrorStatus(status, "Module {}", module);
m_module = module;
}
PneumaticsControlModule::~PneumaticsControlModule() {
HAL_FreeCTREPCM(m_handle);
}
bool PneumaticsControlModule::GetCompressor() {
int32_t status = 0;
auto result = HAL_GetCTREPCMCompressor(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
void PneumaticsControlModule::SetClosedLoopControl(bool enabled) {
int32_t status = 0;
HAL_SetCTREPCMClosedLoopControl(m_handle, enabled, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
}
bool PneumaticsControlModule::GetClosedLoopControl() {
int32_t status = 0;
auto result = HAL_GetCTREPCMClosedLoopControl(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetPressureSwitch() {
int32_t status = 0;
auto result = HAL_GetCTREPCMPressureSwitch(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
double PneumaticsControlModule::GetCompressorCurrent() {
int32_t status = 0;
auto result = HAL_GetCTREPCMCompressorCurrent(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetCompressorCurrentTooHighFault() {
int32_t status = 0;
auto result = HAL_GetCTREPCMCompressorCurrentTooHighFault(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetCompressorCurrentTooHighStickyFault() {
int32_t status = 0;
auto result =
HAL_GetCTREPCMCompressorCurrentTooHighStickyFault(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetCompressorShortedFault() {
int32_t status = 0;
auto result = HAL_GetCTREPCMCompressorShortedFault(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetCompressorShortedStickyFault() {
int32_t status = 0;
auto result = HAL_GetCTREPCMCompressorShortedStickyFault(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetCompressorNotConnectedFault() {
int32_t status = 0;
auto result = HAL_GetCTREPCMCompressorNotConnectedFault(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetCompressorNotConnectedStickyFault() {
int32_t status = 0;
auto result =
HAL_GetCTREPCMCompressorNotConnectedStickyFault(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetSolenoidVoltageFault() {
int32_t status = 0;
auto result = HAL_GetCTREPCMSolenoidVoltageFault(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
bool PneumaticsControlModule::GetSolenoidVoltageStickyFault() {
int32_t status = 0;
auto result = HAL_GetCTREPCMSolenoidVoltageStickyFault(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
void PneumaticsControlModule::ClearAllStickyFaults() {
int32_t status = 0;
HAL_ClearAllCTREPCMStickyFaults(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
}
void PneumaticsControlModule::SetSolenoids(int mask, int values) {
int32_t status = 0;
HAL_SetCTREPCMSolenoids(m_handle, mask, values, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
}
int PneumaticsControlModule::GetSolenoids() const {
int32_t status = 0;
auto result = HAL_GetCTREPCMSolenoids(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
int PneumaticsControlModule::GetModuleNumber() const {
return m_module;
}
int PneumaticsControlModule::GetSolenoidDisabledList() const {
int32_t status = 0;
auto result = HAL_GetCTREPCMSolenoidDisabledList(m_handle, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
return result;
}
void PneumaticsControlModule::FireOneShot(int index) {
int32_t status = 0;
HAL_FireCTREPCMOneShot(m_handle, index, &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
}
void PneumaticsControlModule::SetOneShotDuration(int index,
units::second_t duration) {
int32_t status = 0;
units::millisecond_t millis = duration;
HAL_SetCTREPCMOneShotDuration(m_handle, index, millis.to<int32_t>(), &status);
FRC_CheckErrorStatus(status, "Module {}", m_module);
}
bool PneumaticsControlModule::CheckSolenoidChannel(int channel) const {
return HAL_CheckCTREPCMSolenoidChannel(channel);
}

View File

@@ -11,7 +11,6 @@
#include <hal/PWM.h>
#include <hal/Ports.h>
#include <hal/Relay.h>
#include <hal/Solenoid.h>
using namespace frc;
@@ -19,19 +18,15 @@ const int SensorUtil::kDigitalChannels = HAL_GetNumDigitalChannels();
const int SensorUtil::kAnalogInputs = HAL_GetNumAnalogInputs();
const int SensorUtil::kAnalogOutputs = HAL_GetNumAnalogOutputs();
const int SensorUtil::kSolenoidChannels = HAL_GetNumSolenoidChannels();
const int SensorUtil::kSolenoidModules = HAL_GetNumPCMModules();
const int SensorUtil::kSolenoidModules = HAL_GetNumCTREPCMModules();
const int SensorUtil::kPwmChannels = HAL_GetNumPWMChannels();
const int SensorUtil::kRelayChannels = HAL_GetNumRelayHeaders();
const int SensorUtil::kPDPChannels = HAL_GetNumPDPChannels();
int SensorUtil::GetDefaultSolenoidModule() {
int SensorUtil::GetDefaultCTREPCMModule() {
return 0;
}
bool SensorUtil::CheckSolenoidModule(int moduleNumber) {
return HAL_CheckSolenoidModule(moduleNumber);
}
bool SensorUtil::CheckDigitalChannel(int channel) {
return HAL_CheckDIOChannel(channel);
}
@@ -52,10 +47,6 @@ bool SensorUtil::CheckAnalogOutputChannel(int channel) {
return HAL_CheckAnalogOutputChannel(channel);
}
bool SensorUtil::CheckSolenoidChannel(int channel) {
return HAL_CheckSolenoidChannel(channel);
}
bool SensorUtil::CheckPDPChannel(int channel) {
return HAL_CheckPDPChannel(channel);
}

View File

@@ -7,9 +7,7 @@
#include <utility>
#include <hal/FRCUsageReporting.h>
#include <hal/HALBase.h>
#include <hal/Ports.h>
#include <hal/Solenoid.h>
#include <wpi/NullDeleter.h>
#include "frc/Errors.h"
#include "frc/SensorUtil.h"
@@ -18,49 +16,40 @@
using namespace frc;
Solenoid::Solenoid(int channel)
: Solenoid(SensorUtil::GetDefaultSolenoidModule(), channel) {}
Solenoid::Solenoid(PneumaticsBase& module, int channel)
: Solenoid{std::shared_ptr<PneumaticsBase>{
&module, wpi::NullDeleter<PneumaticsBase>()},
channel} {}
Solenoid::Solenoid(int moduleNumber, int channel)
: SolenoidBase(moduleNumber), m_channel(channel) {
if (!SensorUtil::CheckSolenoidModule(m_moduleNumber)) {
throw FRC_MakeError(err::ModuleIndexOutOfRange, "Module {}",
m_moduleNumber);
}
if (!SensorUtil::CheckSolenoidChannel(m_channel)) {
Solenoid::Solenoid(PneumaticsBase* module, int channel)
: Solenoid{std::shared_ptr<PneumaticsBase>{
module, wpi::NullDeleter<PneumaticsBase>()},
channel} {}
Solenoid::Solenoid(std::shared_ptr<PneumaticsBase> module, int channel)
: m_module{std::move(module)} {
if (!m_module->CheckSolenoidChannel(m_channel)) {
throw FRC_MakeError(err::ChannelIndexOutOfRange, "Channel {}", m_channel);
}
int32_t status = 0;
m_solenoidHandle = HAL_InitializeSolenoidPort(
HAL_GetPortWithModule(moduleNumber, channel), &status);
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
m_channel);
m_channel = channel;
m_mask = 1 << channel;
HAL_Report(HALUsageReporting::kResourceType_Solenoid, m_channel + 1,
m_moduleNumber + 1);
SendableRegistry::GetInstance().AddLW(this, "Solenoid", m_moduleNumber,
m_channel);
m_module->GetModuleNumber() + 1);
SendableRegistry::GetInstance().AddLW(this, "Solenoid",
m_module->GetModuleNumber(), m_channel);
}
Solenoid::~Solenoid() {
HAL_FreeSolenoidPort(m_solenoidHandle);
}
Solenoid::~Solenoid() {}
void Solenoid::Set(bool on) {
int32_t status = 0;
HAL_SetSolenoid(m_solenoidHandle, on, &status);
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
m_channel);
int value = on ? (0xFFFF & m_mask) : 0;
m_module->SetSolenoids(m_mask, value);
}
bool Solenoid::Get() const {
int32_t status = 0;
bool value = HAL_GetSolenoid(m_solenoidHandle, &status);
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
m_channel);
return value;
int currentAll = m_module->GetSolenoids();
return (currentAll & m_mask) != 0;
}
void Solenoid::Toggle() {
@@ -71,24 +60,16 @@ int Solenoid::GetChannel() const {
return m_channel;
}
bool Solenoid::IsBlackListed() const {
int value = GetPCMSolenoidBlackList(m_moduleNumber) & (1 << m_channel);
return (value != 0);
bool Solenoid::IsDisabled() const {
return (m_module->GetSolenoidDisabledList() & m_mask) != 0;
}
void Solenoid::SetPulseDuration(units::second_t duration) {
int32_t status = 0;
HAL_SetOneShotDuration(m_solenoidHandle,
units::millisecond_t{duration}.to<int32_t>(), &status);
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
m_channel);
m_module->SetOneShotDuration(m_channel, duration);
}
void Solenoid::StartPulse() {
int32_t status = 0;
HAL_FireOneShot(m_solenoidHandle, &status);
FRC_CheckErrorStatus(status, "Module {} Channel {}", m_moduleNumber,
m_channel);
m_module->FireOneShot(m_channel);
}
void Solenoid::InitSendable(SendableBuilder& builder) {

View File

@@ -1,73 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/SolenoidBase.h"
#include <hal/FRCUsageReporting.h>
#include <hal/Solenoid.h>
#include "frc/Errors.h"
using namespace frc;
int SolenoidBase::GetAll(int module) {
int value = 0;
int32_t status = 0;
value = HAL_GetAllSolenoids(module, &status);
FRC_CheckErrorStatus(status, "Module {}", module);
return value;
}
int SolenoidBase::GetAll() const {
return SolenoidBase::GetAll(m_moduleNumber);
}
int SolenoidBase::GetPCMSolenoidBlackList(int module) {
int32_t status = 0;
int rv = HAL_GetPCMSolenoidBlackList(module, &status);
FRC_CheckErrorStatus(status, "Module {}", module);
return rv;
}
int SolenoidBase::GetPCMSolenoidBlackList() const {
return SolenoidBase::GetPCMSolenoidBlackList(m_moduleNumber);
}
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module) {
int32_t status = 0;
bool rv = HAL_GetPCMSolenoidVoltageStickyFault(module, &status);
FRC_CheckErrorStatus(status, "Module {}", module);
return rv;
}
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault() const {
return SolenoidBase::GetPCMSolenoidVoltageStickyFault(m_moduleNumber);
}
bool SolenoidBase::GetPCMSolenoidVoltageFault(int module) {
int32_t status = 0;
bool rv = HAL_GetPCMSolenoidVoltageFault(module, &status);
FRC_CheckErrorStatus(status, "Module {}", module);
return rv;
}
bool SolenoidBase::GetPCMSolenoidVoltageFault() const {
return SolenoidBase::GetPCMSolenoidVoltageFault(m_moduleNumber);
}
void SolenoidBase::ClearAllPCMStickyFaults(int module) {
int32_t status = 0;
HAL_ClearAllPCMStickyFaults(module, &status);
FRC_CheckErrorStatus(status, "Module {}", module);
}
void SolenoidBase::ClearAllPCMStickyFaults() {
SolenoidBase::ClearAllPCMStickyFaults(m_moduleNumber);
}
SolenoidBase::SolenoidBase(int moduleNumber) : m_moduleNumber(moduleNumber) {}
int SolenoidBase::GetModuleNumber() const {
return m_moduleNumber;
}

View File

@@ -0,0 +1,139 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/simulation/CTREPCMSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/CTREPCMData.h>
#include "frc/SensorUtil.h"
using namespace frc;
using namespace frc::sim;
CTREPCMSim::CTREPCMSim() : m_index{SensorUtil::GetDefaultCTREPCMModule()} {}
CTREPCMSim::CTREPCMSim(int module) : m_index{module} {}
CTREPCMSim::CTREPCMSim(const PneumaticsBase& pneumatics)
: m_index{pneumatics.GetModuleNumber()} {}
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelCTREPCMInitializedCallback);
store->SetUid(HALSIM_RegisterCTREPCMInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool CTREPCMSim::GetInitialized() const {
return HALSIM_GetCTREPCMInitialized(m_index);
}
void CTREPCMSim::SetInitialized(bool solenoidInitialized) {
HALSIM_SetCTREPCMInitialized(m_index, solenoidInitialized);
}
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterSolenoidOutputCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback,
&HALSIM_CancelCTREPCMSolenoidOutputCallback);
store->SetUid(HALSIM_RegisterCTREPCMSolenoidOutputCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool CTREPCMSim::GetSolenoidOutput(int channel) const {
return HALSIM_GetCTREPCMSolenoidOutput(m_index, channel);
}
void CTREPCMSim::SetSolenoidOutput(int channel, bool solenoidOutput) {
HALSIM_SetCTREPCMSolenoidOutput(m_index, channel, solenoidOutput);
}
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterCompressorOnCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelCTREPCMCompressorOnCallback);
store->SetUid(HALSIM_RegisterCTREPCMCompressorOnCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool CTREPCMSim::GetCompressorOn() const {
return HALSIM_GetCTREPCMCompressorOn(m_index);
}
void CTREPCMSim::SetCompressorOn(bool compressorOn) {
HALSIM_SetCTREPCMCompressorOn(m_index, compressorOn);
}
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterClosedLoopEnabledCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelCTREPCMClosedLoopEnabledCallback);
store->SetUid(HALSIM_RegisterCTREPCMClosedLoopEnabledCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool CTREPCMSim::GetClosedLoopEnabled() const {
return HALSIM_GetCTREPCMClosedLoopEnabled(m_index);
}
void CTREPCMSim::SetClosedLoopEnabled(bool closedLoopEnabled) {
HALSIM_SetCTREPCMClosedLoopEnabled(m_index, closedLoopEnabled);
}
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterPressureSwitchCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelCTREPCMPressureSwitchCallback);
store->SetUid(HALSIM_RegisterCTREPCMPressureSwitchCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool CTREPCMSim::GetPressureSwitch() const {
return HALSIM_GetCTREPCMPressureSwitch(m_index);
}
void CTREPCMSim::SetPressureSwitch(bool pressureSwitch) {
HALSIM_SetCTREPCMPressureSwitch(m_index, pressureSwitch);
}
std::unique_ptr<CallbackStore> CTREPCMSim::RegisterCompressorCurrentCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelCTREPCMCompressorCurrentCallback);
store->SetUid(HALSIM_RegisterCTREPCMCompressorCurrentCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double CTREPCMSim::GetCompressorCurrent() const {
return HALSIM_GetCTREPCMCompressorCurrent(m_index);
}
void CTREPCMSim::SetCompressorCurrent(double compressorCurrent) {
HALSIM_SetCTREPCMCompressorCurrent(m_index, compressorCurrent);
}
uint8_t CTREPCMSim::GetAllSolenoidOutputs() const {
uint8_t ret = 0;
HALSIM_GetCTREPCMAllSolenoids(m_index, &ret);
return ret;
}
void CTREPCMSim::SetAllSolenoidOutputs(uint8_t outputs) {
HALSIM_SetCTREPCMAllSolenoids(m_index, outputs);
}
void CTREPCMSim::ResetData() {
HALSIM_ResetCTREPCMData(m_index);
}

View File

@@ -1,91 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/simulation/DoubleSolenoidSim.h"
#include "frc/SensorUtil.h"
#include "frc/simulation/PCMSim.h"
using namespace frc;
using namespace frc::sim;
DoubleSolenoidSim::DoubleSolenoidSim(int fwd, int rev)
: m_fwd{fwd}, m_rev{rev} {}
DoubleSolenoidSim::DoubleSolenoidSim(int module, int fwd, int rev)
: m_pcm{module}, m_fwd{fwd}, m_rev{rev} {}
DoubleSolenoidSim::DoubleSolenoidSim(PCMSim& pcm, int fwd, int rev)
: m_pcm{pcm}, m_fwd{fwd}, m_rev{rev} {}
DoubleSolenoidSim::DoubleSolenoidSim(DoubleSolenoid& solenoid)
: m_pcm{solenoid.GetModuleNumber()},
m_fwd{solenoid.GetFwdChannel()},
m_rev{solenoid.GetRevChannel()} {}
std::unique_ptr<CallbackStore>
DoubleSolenoidSim::RegisterFwdInitializedCallback(NotifyCallback callback,
bool initialNotify) {
return m_pcm.RegisterSolenoidInitializedCallback(m_fwd, callback,
initialNotify);
}
bool DoubleSolenoidSim::GetFwdInitialized() const {
return m_pcm.GetSolenoidInitialized(m_fwd);
}
void DoubleSolenoidSim::SetFwdInitialized(bool initialized) {
m_pcm.SetSolenoidInitialized(m_fwd, initialized);
}
std::unique_ptr<CallbackStore>
DoubleSolenoidSim::RegisterRevInitializedCallback(NotifyCallback callback,
bool initialNotify) {
return m_pcm.RegisterSolenoidInitializedCallback(m_rev, callback,
initialNotify);
}
bool DoubleSolenoidSim::GetRevInitialized() const {
return m_pcm.GetSolenoidInitialized(m_rev);
}
void DoubleSolenoidSim::SetRevInitialized(bool initialized) {
m_pcm.SetSolenoidInitialized(m_rev, initialized);
}
void DoubleSolenoidSim::Set(DoubleSolenoid::Value value) {
bool forward = false;
bool reverse = false;
switch (value) {
case DoubleSolenoid::Value::kOff:
forward = false;
reverse = false;
break;
case DoubleSolenoid::Value::kForward:
forward = true;
reverse = false;
break;
case DoubleSolenoid::Value::kReverse:
forward = false;
reverse = true;
break;
}
m_pcm.SetSolenoidOutput(m_fwd, forward);
m_pcm.SetSolenoidOutput(m_rev, reverse);
}
DoubleSolenoid::Value DoubleSolenoidSim::Get() const {
bool valueForward = m_pcm.GetSolenoidOutput(m_fwd);
bool valueReverse = m_pcm.GetSolenoidOutput(m_rev);
if (valueForward) {
return DoubleSolenoid::Value::kForward;
} else if (valueReverse) {
return DoubleSolenoid::Value::kReverse;
} else {
return DoubleSolenoid::Value::kOff;
}
}

View File

@@ -1,157 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/simulation/PCMSim.h"
#include <memory>
#include <utility>
#include <hal/simulation/PCMData.h>
#include "frc/Compressor.h"
#include "frc/SensorUtil.h"
using namespace frc;
using namespace frc::sim;
PCMSim::PCMSim() : m_index{SensorUtil::GetDefaultSolenoidModule()} {}
PCMSim::PCMSim(int module) : m_index{module} {}
PCMSim::PCMSim(const Compressor& compressor)
: m_index{compressor.GetModule()} {}
std::unique_ptr<CallbackStore> PCMSim::RegisterSolenoidInitializedCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback,
&HALSIM_CancelPCMSolenoidInitializedCallback);
store->SetUid(HALSIM_RegisterPCMSolenoidInitializedCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetSolenoidInitialized(int channel) const {
return HALSIM_GetPCMSolenoidInitialized(m_index, channel);
}
void PCMSim::SetSolenoidInitialized(int channel, bool solenoidInitialized) {
HALSIM_SetPCMSolenoidInitialized(m_index, channel, solenoidInitialized);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterSolenoidOutputCallback(
int channel, NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, channel, -1, callback, &HALSIM_CancelPCMSolenoidOutputCallback);
store->SetUid(HALSIM_RegisterPCMSolenoidOutputCallback(
m_index, channel, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetSolenoidOutput(int channel) const {
return HALSIM_GetPCMSolenoidOutput(m_index, channel);
}
void PCMSim::SetSolenoidOutput(int channel, bool solenoidOutput) {
HALSIM_SetPCMSolenoidOutput(m_index, channel, solenoidOutput);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorInitializedCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorInitializedCallback);
store->SetUid(HALSIM_RegisterPCMCompressorInitializedCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetCompressorInitialized() const {
return HALSIM_GetPCMCompressorInitialized(m_index);
}
void PCMSim::SetCompressorInitialized(bool compressorInitialized) {
HALSIM_SetPCMCompressorInitialized(m_index, compressorInitialized);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorOnCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorOnCallback);
store->SetUid(HALSIM_RegisterPCMCompressorOnCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetCompressorOn() const {
return HALSIM_GetPCMCompressorOn(m_index);
}
void PCMSim::SetCompressorOn(bool compressorOn) {
HALSIM_SetPCMCompressorOn(m_index, compressorOn);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterClosedLoopEnabledCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMClosedLoopEnabledCallback);
store->SetUid(HALSIM_RegisterPCMClosedLoopEnabledCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetClosedLoopEnabled() const {
return HALSIM_GetPCMClosedLoopEnabled(m_index);
}
void PCMSim::SetClosedLoopEnabled(bool closedLoopEnabled) {
HALSIM_SetPCMClosedLoopEnabled(m_index, closedLoopEnabled);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterPressureSwitchCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMPressureSwitchCallback);
store->SetUid(HALSIM_RegisterPCMPressureSwitchCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
bool PCMSim::GetPressureSwitch() const {
return HALSIM_GetPCMPressureSwitch(m_index);
}
void PCMSim::SetPressureSwitch(bool pressureSwitch) {
HALSIM_SetPCMPressureSwitch(m_index, pressureSwitch);
}
std::unique_ptr<CallbackStore> PCMSim::RegisterCompressorCurrentCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
m_index, -1, callback, &HALSIM_CancelPCMCompressorCurrentCallback);
store->SetUid(HALSIM_RegisterPCMCompressorCurrentCallback(
m_index, &CallbackStoreThunk, store.get(), initialNotify));
return store;
}
double PCMSim::GetCompressorCurrent() const {
return HALSIM_GetPCMCompressorCurrent(m_index);
}
void PCMSim::SetCompressorCurrent(double compressorCurrent) {
HALSIM_SetPCMCompressorCurrent(m_index, compressorCurrent);
}
uint8_t PCMSim::GetAllSolenoidOutputs() const {
uint8_t ret = 0;
HALSIM_GetPCMAllSolenoids(m_index, &ret);
return ret;
}
void PCMSim::SetAllSolenoidOutputs(uint8_t outputs) {
HALSIM_SetPCMAllSolenoids(m_index, outputs);
}
void PCMSim::ResetData() {
HALSIM_ResetPCMData(m_index);
}

View File

@@ -1,50 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "frc/simulation/SolenoidSim.h"
#include "frc/SensorUtil.h"
#include "frc/simulation/PCMSim.h"
using namespace frc;
using namespace frc::sim;
SolenoidSim::SolenoidSim(int channel) : m_channel{channel} {}
SolenoidSim::SolenoidSim(int module, int channel)
: m_pcm{module}, m_channel{channel} {}
SolenoidSim::SolenoidSim(PCMSim& pcm, int channel)
: m_pcm{pcm}, m_channel{channel} {}
SolenoidSim::SolenoidSim(Solenoid& solenoid)
: m_pcm{solenoid.GetModuleNumber()}, m_channel{solenoid.GetChannel()} {}
std::unique_ptr<CallbackStore> SolenoidSim::RegisterInitializedCallback(
NotifyCallback callback, bool initialNotify) {
return m_pcm.RegisterSolenoidInitializedCallback(m_channel, callback,
initialNotify);
}
bool SolenoidSim::GetInitialized() const {
return m_pcm.GetSolenoidInitialized(m_channel);
}
void SolenoidSim::SetInitialized(bool initialized) {
m_pcm.SetSolenoidInitialized(m_channel, initialized);
}
std::unique_ptr<CallbackStore> SolenoidSim::RegisterOutputCallback(
NotifyCallback callback, bool initialNotify) {
return m_pcm.RegisterSolenoidOutputCallback(m_channel, callback,
initialNotify);
}
bool SolenoidSim::GetOutput() const {
return m_pcm.GetSolenoidOutput(m_channel);
}
void SolenoidSim::SetOutput(bool output) {
m_pcm.SetSolenoidOutput(m_channel, output);
}