mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[hal] Add a unified PCM object (#3331)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
162
wpilibc/src/main/native/cpp/PneumaticsControlModule.cpp
Normal file
162
wpilibc/src/main/native/cpp/PneumaticsControlModule.cpp
Normal 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
139
wpilibc/src/main/native/cpp/simulation/CTREPCMSim.cpp
Normal file
139
wpilibc/src/main/native/cpp/simulation/CTREPCMSim.cpp
Normal 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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -1,185 +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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/SensorUtil.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
namespace frc {
|
||||
|
||||
class SendableBuilder;
|
||||
|
||||
/**
|
||||
* Class for operating a compressor connected to a %PCM (Pneumatic Control
|
||||
* Module).
|
||||
*
|
||||
* The PCM will automatically run in closed loop mode by default whenever a
|
||||
* Solenoid object is created. For most cases, a Compressor object does not need
|
||||
* to be instantiated or used in a robot program. This class is only required in
|
||||
* cases where the robot program needs a more detailed status of the compressor
|
||||
* or to enable/disable closed loop control.
|
||||
*
|
||||
* Note: you cannot operate the compressor directly from this class as doing so
|
||||
* would circumvent the safety provided by using the pressure switch and closed
|
||||
* loop control. You can only turn off closed loop control, thereby stopping
|
||||
* the compressor from operating.
|
||||
*/
|
||||
class Compressor : public Sendable, public SendableHelper<Compressor> {
|
||||
public:
|
||||
/**
|
||||
* Constructor. The default PCM ID is 0.
|
||||
*
|
||||
* @param module The PCM ID to use (0-62)
|
||||
*/
|
||||
explicit Compressor(int pcmID = SensorUtil::GetDefaultSolenoidModule());
|
||||
|
||||
~Compressor() override = default;
|
||||
|
||||
Compressor(Compressor&&) = default;
|
||||
Compressor& operator=(Compressor&&) = default;
|
||||
|
||||
/**
|
||||
* Starts closed-loop control. Note that closed loop control is enabled by
|
||||
* default.
|
||||
*/
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* Stops closed-loop control. Note that closed loop control is enabled by
|
||||
* default.
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* Check if compressor output is active.
|
||||
*
|
||||
* @return true if the compressor is on
|
||||
*/
|
||||
bool Enabled() const;
|
||||
|
||||
/**
|
||||
* Check if the pressure switch is triggered.
|
||||
*
|
||||
* @return true if pressure is low
|
||||
*/
|
||||
bool GetPressureSwitchValue() const;
|
||||
|
||||
/**
|
||||
* Query how much current the compressor is drawing.
|
||||
*
|
||||
* @return The current through the compressor, in amps
|
||||
*/
|
||||
double GetCompressorCurrent() const;
|
||||
|
||||
/**
|
||||
* 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 SetClosedLoopControl(bool on);
|
||||
|
||||
/**
|
||||
* 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 GetClosedLoopControl() const;
|
||||
|
||||
/**
|
||||
* 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 GetCompressorCurrentTooHighFault() const;
|
||||
|
||||
/**
|
||||
* 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 GetCompressorCurrentTooHighStickyFault() const;
|
||||
|
||||
/**
|
||||
* 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 GetCompressorShortedStickyFault() const;
|
||||
|
||||
/**
|
||||
* 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 GetCompressorShortedFault() const;
|
||||
|
||||
/**
|
||||
* 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 GetCompressorNotConnectedStickyFault() const;
|
||||
|
||||
/**
|
||||
* 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 GetCompressorNotConnectedFault() const;
|
||||
|
||||
/**
|
||||
* 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 ClearAllPCMStickyFaults();
|
||||
|
||||
/**
|
||||
* Gets module number (CAN ID).
|
||||
*
|
||||
* @return Module number
|
||||
*/
|
||||
int GetModule() const;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
protected:
|
||||
hal::Handle<HAL_CompressorHandle> m_compressorHandle;
|
||||
|
||||
private:
|
||||
void SetCompressor(bool on);
|
||||
int m_module;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -4,9 +4,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "frc/SolenoidBase.h"
|
||||
#include "frc/PneumaticsBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -21,30 +23,16 @@ class SendableBuilder;
|
||||
* The DoubleSolenoid class is typically used for pneumatics solenoids that
|
||||
* have two positions controlled by two separate channels.
|
||||
*/
|
||||
class DoubleSolenoid : public SolenoidBase,
|
||||
public Sendable,
|
||||
public SendableHelper<DoubleSolenoid> {
|
||||
class DoubleSolenoid : public Sendable, public SendableHelper<DoubleSolenoid> {
|
||||
public:
|
||||
enum Value { kOff, kForward, kReverse };
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Uses the default PCM ID of 0.
|
||||
*
|
||||
* @param forwardChannel The forward channel number on the PCM (0..7).
|
||||
* @param reverseChannel The reverse channel number on the PCM (0..7).
|
||||
*/
|
||||
explicit DoubleSolenoid(int forwardChannel, int reverseChannel);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN ID of the PCM.
|
||||
* @param forwardChannel The forward channel on the PCM to control (0..7).
|
||||
* @param reverseChannel The reverse channel on the PCM to control (0..7).
|
||||
*/
|
||||
DoubleSolenoid(int moduleNumber, int forwardChannel, int reverseChannel);
|
||||
DoubleSolenoid(PneumaticsBase& module, int forwardChannel,
|
||||
int reverseChannel);
|
||||
DoubleSolenoid(PneumaticsBase* module, int forwardChannel,
|
||||
int reverseChannel);
|
||||
DoubleSolenoid(std::shared_ptr<PneumaticsBase> module, int forwardChannel,
|
||||
int reverseChannel);
|
||||
|
||||
~DoubleSolenoid() override;
|
||||
|
||||
@@ -89,26 +77,26 @@ class DoubleSolenoid : public SolenoidBase,
|
||||
int GetRevChannel() const;
|
||||
|
||||
/**
|
||||
* Check if the forward solenoid is blacklisted.
|
||||
* Check if the forward solenoid is Disabled.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and disabled until
|
||||
* power cycle, or until faults are cleared.
|
||||
* If a solenoid is shorted, it is added to the DisabledList and disabled
|
||||
* until power cycle, or until faults are cleared.
|
||||
*
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
* @return If solenoid is disabled due to short.
|
||||
*/
|
||||
bool IsFwdSolenoidBlackListed() const;
|
||||
bool IsFwdSolenoidDisabled() const;
|
||||
|
||||
/**
|
||||
* Check if the reverse solenoid is blacklisted.
|
||||
* Check if the reverse solenoid is Disabled.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and disabled until
|
||||
* power cycle, or until faults are cleared.
|
||||
* If a solenoid is shorted, it is added to the DisabledList and disabled
|
||||
* until power cycle, or until faults are cleared.
|
||||
*
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
* @return If solenoid is disabled due to short.
|
||||
*/
|
||||
bool IsRevSolenoidBlackListed() const;
|
||||
bool IsRevSolenoidDisabled() const;
|
||||
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
@@ -117,8 +105,8 @@ class DoubleSolenoid : public SolenoidBase,
|
||||
int m_reverseChannel; // The reverse channel on the module to control.
|
||||
int m_forwardMask; // The mask for the forward channel.
|
||||
int m_reverseMask; // The mask for the reverse channel.
|
||||
hal::Handle<HAL_SolenoidHandle> m_forwardHandle;
|
||||
hal::Handle<HAL_SolenoidHandle> m_reverseHandle;
|
||||
int m_mask;
|
||||
std::shared_ptr<PneumaticsBase> m_module;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
28
wpilibc/src/main/native/include/frc/PneumaticsBase.h
Normal file
28
wpilibc/src/main/native/include/frc/PneumaticsBase.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <units/time.h>
|
||||
|
||||
namespace frc {
|
||||
class PneumaticsBase {
|
||||
public:
|
||||
virtual ~PneumaticsBase() = default;
|
||||
|
||||
virtual void SetSolenoids(int mask, int values) = 0;
|
||||
|
||||
virtual int GetSolenoids() const = 0;
|
||||
|
||||
virtual int GetModuleNumber() const = 0;
|
||||
|
||||
virtual int GetSolenoidDisabledList() const = 0;
|
||||
|
||||
virtual void FireOneShot(int index) = 0;
|
||||
|
||||
virtual void SetOneShotDuration(int index, units::second_t duration) = 0;
|
||||
|
||||
virtual bool CheckSolenoidChannel(int channel) const = 0;
|
||||
};
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <hal/Types.h>
|
||||
|
||||
#include "PneumaticsBase.h"
|
||||
|
||||
namespace frc {
|
||||
class PneumaticsControlModule : public PneumaticsBase {
|
||||
public:
|
||||
PneumaticsControlModule();
|
||||
explicit PneumaticsControlModule(int module);
|
||||
|
||||
~PneumaticsControlModule() override;
|
||||
|
||||
PneumaticsControlModule(PneumaticsControlModule&&) = default;
|
||||
PneumaticsControlModule& operator=(PneumaticsControlModule&&) = default;
|
||||
|
||||
bool GetCompressor();
|
||||
|
||||
void SetClosedLoopControl(bool enabled);
|
||||
|
||||
bool GetClosedLoopControl();
|
||||
|
||||
bool GetPressureSwitch();
|
||||
|
||||
double GetCompressorCurrent();
|
||||
|
||||
bool GetCompressorCurrentTooHighFault();
|
||||
bool GetCompressorCurrentTooHighStickyFault();
|
||||
bool GetCompressorShortedFault();
|
||||
bool GetCompressorShortedStickyFault();
|
||||
bool GetCompressorNotConnectedFault();
|
||||
bool GetCompressorNotConnectedStickyFault();
|
||||
|
||||
bool GetSolenoidVoltageFault();
|
||||
bool GetSolenoidVoltageStickyFault();
|
||||
|
||||
void ClearAllStickyFaults();
|
||||
|
||||
void SetSolenoids(int mask, int values) override;
|
||||
|
||||
int GetSolenoids() const override;
|
||||
|
||||
int GetModuleNumber() const override;
|
||||
|
||||
int GetSolenoidDisabledList() const override;
|
||||
|
||||
void FireOneShot(int index) override;
|
||||
|
||||
void SetOneShotDuration(int index, units::second_t duration) override;
|
||||
|
||||
bool CheckSolenoidChannel(int channel) const override;
|
||||
|
||||
private:
|
||||
int m_module;
|
||||
hal::Handle<HAL_CTREPCMHandle> m_handle;
|
||||
};
|
||||
} // namespace frc
|
||||
@@ -19,14 +19,7 @@ class SensorUtil final {
|
||||
*
|
||||
* @return The number of the default solenoid module.
|
||||
*/
|
||||
static int GetDefaultSolenoidModule();
|
||||
|
||||
/**
|
||||
* Check that the solenoid module number is valid. module numbers are 0-based
|
||||
*
|
||||
* @return Solenoid module is valid and present
|
||||
*/
|
||||
static bool CheckSolenoidModule(int moduleNumber);
|
||||
static int GetDefaultCTREPCMModule();
|
||||
|
||||
/**
|
||||
* Check that the digital channel number is valid.
|
||||
@@ -78,13 +71,6 @@ class SensorUtil final {
|
||||
*/
|
||||
static bool CheckAnalogOutputChannel(int channel);
|
||||
|
||||
/**
|
||||
* Verify that the solenoid channel number is within limits.
|
||||
*
|
||||
* @return Solenoid channel is valid
|
||||
*/
|
||||
static bool CheckSolenoidChannel(int channel);
|
||||
|
||||
/**
|
||||
* Verify that the power distribution channel number is within limits.
|
||||
*
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <hal/Types.h>
|
||||
#include <units/time.h>
|
||||
|
||||
#include "frc/SolenoidBase.h"
|
||||
#include "frc/PneumaticsBase.h"
|
||||
#include "frc/smartdashboard/Sendable.h"
|
||||
#include "frc/smartdashboard/SendableHelper.h"
|
||||
|
||||
@@ -21,24 +23,11 @@ class SendableBuilder;
|
||||
* The Solenoid class is typically used for pneumatics solenoids, but could be
|
||||
* used for any device within the current spec of the PCM.
|
||||
*/
|
||||
class Solenoid : public SolenoidBase,
|
||||
public Sendable,
|
||||
public SendableHelper<Solenoid> {
|
||||
class Solenoid : public Sendable, public SendableHelper<Solenoid> {
|
||||
public:
|
||||
/**
|
||||
* Constructor using the default PCM ID (0).
|
||||
*
|
||||
* @param channel The channel on the PCM to control (0..7).
|
||||
*/
|
||||
explicit Solenoid(int channel);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN ID of the PCM the solenoid is attached to
|
||||
* @param channel The channel on the PCM to control (0..7).
|
||||
*/
|
||||
Solenoid(int moduleNumber, int channel);
|
||||
Solenoid(PneumaticsBase& module, int channel);
|
||||
Solenoid(PneumaticsBase* module, int channel);
|
||||
Solenoid(std::shared_ptr<PneumaticsBase> module, int channel);
|
||||
|
||||
~Solenoid() override;
|
||||
|
||||
@@ -73,16 +62,16 @@ class Solenoid : public SolenoidBase,
|
||||
int GetChannel() const;
|
||||
|
||||
/**
|
||||
* Check if solenoid is blacklisted.
|
||||
* Check if solenoid is Disabled.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and
|
||||
* If a solenoid is shorted, it is added to the DisabledList and
|
||||
* disabled until power cycle, or until faults are cleared.
|
||||
*
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
*
|
||||
* @return If solenoid is disabled due to short.
|
||||
*/
|
||||
bool IsBlackListed() const;
|
||||
bool IsDisabled() const;
|
||||
|
||||
/**
|
||||
* Set the pulse duration in the PCM. This is used in conjunction with
|
||||
@@ -107,8 +96,9 @@ class Solenoid : public SolenoidBase,
|
||||
void InitSendable(SendableBuilder& builder) override;
|
||||
|
||||
private:
|
||||
hal::Handle<HAL_SolenoidHandle> m_solenoidHandle;
|
||||
int m_channel; // The channel on the module to control
|
||||
std::shared_ptr<PneumaticsBase> m_module;
|
||||
int m_mask;
|
||||
int m_channel;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -1,131 +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.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace frc {
|
||||
|
||||
/**
|
||||
* SolenoidBase class is the common base class for the Solenoid and
|
||||
* DoubleSolenoid classes.
|
||||
*/
|
||||
class SolenoidBase {
|
||||
public:
|
||||
virtual ~SolenoidBase() = default;
|
||||
|
||||
/**
|
||||
* Get the CAN ID of the module this solenoid is connected to.
|
||||
*
|
||||
* @return the module number.
|
||||
*/
|
||||
int GetModuleNumber() const;
|
||||
|
||||
/**
|
||||
* Read all 8 solenoids as a single byte
|
||||
*
|
||||
* @param module the module to read from
|
||||
* @return The current value of all 8 solenoids on the module.
|
||||
*/
|
||||
static int GetAll(int module);
|
||||
|
||||
/**
|
||||
* Read all 8 solenoids as a single byte
|
||||
*
|
||||
* @return The current value of all 8 solenoids on the module.
|
||||
*/
|
||||
int GetAll() const;
|
||||
|
||||
/**
|
||||
* Reads complete solenoid blacklist for all 8 solenoids as a single byte.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and
|
||||
* disabled until power cycle, or until faults are cleared.
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
*
|
||||
* @param module the module to read from
|
||||
* @return The solenoid blacklist of all 8 solenoids on the module.
|
||||
*/
|
||||
static int GetPCMSolenoidBlackList(int module);
|
||||
|
||||
/**
|
||||
* Reads complete solenoid blacklist for all 8 solenoids as a single byte.
|
||||
*
|
||||
* If a solenoid is shorted, it is added to the blacklist and
|
||||
* disabled until power cycle, or until faults are cleared.
|
||||
* @see ClearAllPCMStickyFaults()
|
||||
*
|
||||
* @return The solenoid blacklist of all 8 solenoids on the module.
|
||||
*/
|
||||
int GetPCMSolenoidBlackList() const;
|
||||
|
||||
/**
|
||||
* @param module the module to read from
|
||||
* @return true if PCM sticky fault is set : The common highside solenoid
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
static bool GetPCMSolenoidVoltageStickyFault(int module);
|
||||
|
||||
/**
|
||||
* @return true if PCM sticky fault is set : The common highside solenoid
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
bool GetPCMSolenoidVoltageStickyFault() const;
|
||||
|
||||
/**
|
||||
* @param module the module to read from
|
||||
* @return true if PCM is in fault state : The common highside solenoid
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
static bool GetPCMSolenoidVoltageFault(int module);
|
||||
|
||||
/**
|
||||
* @return true if PCM is in fault state : The common highside solenoid
|
||||
* voltage rail is too low, most likely a solenoid channel is shorted.
|
||||
*/
|
||||
bool GetPCMSolenoidVoltageFault() const;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param module the module to read from
|
||||
*/
|
||||
static void ClearAllPCMStickyFaults(int module);
|
||||
|
||||
/**
|
||||
* 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 ClearAllPCMStickyFaults();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param moduleNumber The CAN PCM ID.
|
||||
*/
|
||||
explicit SolenoidBase(int pcmID);
|
||||
|
||||
SolenoidBase(SolenoidBase&&) = default;
|
||||
SolenoidBase& operator=(SolenoidBase&&) = default;
|
||||
|
||||
static constexpr int m_maxModules = 63;
|
||||
static constexpr int m_maxPorts = 8;
|
||||
|
||||
int m_moduleNumber; // PCM module number
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "frc/PneumaticsBase.h"
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -17,26 +18,21 @@ namespace sim {
|
||||
/**
|
||||
* Class to control a simulated Pneumatic Control Module (PCM).
|
||||
*/
|
||||
class PCMSim {
|
||||
class CTREPCMSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs with the default PCM module number (CAN ID).
|
||||
*/
|
||||
PCMSim();
|
||||
CTREPCMSim();
|
||||
|
||||
/**
|
||||
* Constructs from a PCM module number (CAN ID).
|
||||
*
|
||||
* @param module module number
|
||||
*/
|
||||
explicit PCMSim(int module);
|
||||
explicit CTREPCMSim(int module);
|
||||
|
||||
/**
|
||||
* Constructs from a Compressor object.
|
||||
*
|
||||
* @param compressor Compressor connected to PCM to simulate
|
||||
*/
|
||||
explicit PCMSim(const Compressor& compressor);
|
||||
explicit CTREPCMSim(const PneumaticsBase& pneumatics);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when a solenoid is initialized on a channel.
|
||||
@@ -46,17 +42,15 @@ class PCMSim {
|
||||
* @param initialNotify should the callback be run with the initial state
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore>
|
||||
RegisterSolenoidInitializedCallback(int channel, NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check if a solenoid has been initialized on a specific channel.
|
||||
*
|
||||
* @param channel the channel to check
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetSolenoidInitialized(int channel) const;
|
||||
bool GetInitialized() const;
|
||||
|
||||
/**
|
||||
* Define whether a solenoid has been initialized on a specific channel.
|
||||
@@ -64,7 +58,7 @@ class PCMSim {
|
||||
* @param channel the channel
|
||||
* @param solenoidInitialized is there a solenoid initialized on that channel
|
||||
*/
|
||||
void SetSolenoidInitialized(int channel, bool solenoidInitialized);
|
||||
void SetInitialized(bool solenoidInitialized);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the solenoid output on a channel
|
||||
@@ -94,31 +88,6 @@ class PCMSim {
|
||||
*/
|
||||
void SetSolenoidOutput(int channel, bool solenoidOutput);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the compressor is initialized.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify whether to run the callback with the initial state
|
||||
* @return the CallbackStore object associated with this callback
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore>
|
||||
RegisterCompressorInitializedCallback(NotifyCallback callback,
|
||||
bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check whether the compressor has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetCompressorInitialized() const;
|
||||
|
||||
/**
|
||||
* Define whether the compressor has been initialized.
|
||||
*
|
||||
* @param compressorInitialized whether the compressor is initialized
|
||||
*/
|
||||
void SetCompressorInitialized(bool compressorInitialized);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the compressor activates.
|
||||
*
|
||||
@@ -1,116 +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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "frc/DoubleSolenoid.h"
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
#include "frc/simulation/PCMSim.h"
|
||||
|
||||
namespace frc::sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated Pneumatic Control Module (PCM).
|
||||
*/
|
||||
class DoubleSolenoidSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs for a solenoid on the default PCM.
|
||||
*
|
||||
* @param channel the solenoid channel.
|
||||
*/
|
||||
DoubleSolenoidSim(int fwd, int rev);
|
||||
|
||||
/**
|
||||
* Constructs for a solenoid on the given PCM.
|
||||
*
|
||||
* @param pcm the PCM the solenoid is connected to.
|
||||
* @param channel the solenoid channel.
|
||||
*/
|
||||
DoubleSolenoidSim(int module, int fwd, int rev);
|
||||
|
||||
/**
|
||||
* Constructs from a PCMSim object.
|
||||
*
|
||||
* @param pcm the PCM the solenoid is connected to.
|
||||
*/
|
||||
DoubleSolenoidSim(PCMSim& pcm, int fwd, int rev);
|
||||
|
||||
/**
|
||||
* Constructs for the given solenoid.
|
||||
*
|
||||
* @param solenoid the solenoid to simulate.
|
||||
*/
|
||||
explicit DoubleSolenoidSim(DoubleSolenoid& solenoid);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the forward solenoid is initialized.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify should the callback be run with the initial state
|
||||
* @return the {@link CallbackStore} object associated with this callback.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterFwdInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check if the forward solenoid has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetFwdInitialized() const;
|
||||
|
||||
/**
|
||||
* Define whether the forward solenoid has been initialized.
|
||||
*
|
||||
* @param initialized whether the solenoid is intiialized.
|
||||
*/
|
||||
void SetFwdInitialized(bool initialized);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the reverse solenoid is initialized.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify should the callback be run with the initial state
|
||||
* @return the {@link CallbackStore} object associated with this callback.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterRevInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Define whether the reverse solenoid has been initialized.
|
||||
*
|
||||
* @param initialized whether the solenoid is intiialized.
|
||||
*/
|
||||
void SetRevInitialized(bool initialized);
|
||||
|
||||
/**
|
||||
* Check if the reverse solenoid has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetRevInitialized() const;
|
||||
|
||||
/**
|
||||
* Set the value of the double solenoid output.
|
||||
*
|
||||
* @param value The value to set (Off, Forward, Reverse)
|
||||
*/
|
||||
void Set(DoubleSolenoid::Value value);
|
||||
|
||||
/**
|
||||
* Check the value of the double solenoid output.
|
||||
*
|
||||
* @return the output value of the double solenoid.
|
||||
*/
|
||||
DoubleSolenoid::Value Get() const;
|
||||
|
||||
private:
|
||||
PCMSim m_pcm;
|
||||
int m_fwd;
|
||||
int m_rev;
|
||||
};
|
||||
} // namespace frc::sim
|
||||
@@ -1,104 +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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "frc/Solenoid.h"
|
||||
#include "frc/simulation/CallbackStore.h"
|
||||
#include "frc/simulation/PCMSim.h"
|
||||
|
||||
namespace frc::sim {
|
||||
|
||||
/**
|
||||
* Class to control a simulated Pneumatic Control Module (PCM).
|
||||
*/
|
||||
class SolenoidSim {
|
||||
public:
|
||||
/**
|
||||
* Constructs for a solenoid on the default PCM.
|
||||
*
|
||||
* @param channel the solenoid channel.
|
||||
*/
|
||||
explicit SolenoidSim(int channel);
|
||||
|
||||
/**
|
||||
* Constructs for the given solenoid.
|
||||
*
|
||||
* @param doubleSolenoid the solenoid to simulate.
|
||||
*/
|
||||
explicit SolenoidSim(Solenoid& solenoid);
|
||||
|
||||
/**
|
||||
* Constructs for a solenoid.
|
||||
*
|
||||
* @param module the CAN ID of the PCM the solenoid is connected to.
|
||||
* @param channel the solenoid channel.
|
||||
*
|
||||
* @see PCMSim#PCMSim(int)
|
||||
*/
|
||||
SolenoidSim(int module, int channel);
|
||||
|
||||
/**
|
||||
* Constructs for a solenoid on the given PCM.
|
||||
*
|
||||
* @param pcm the PCM the solenoid is connected to.
|
||||
* @param channel the solenoid channel.
|
||||
*/
|
||||
SolenoidSim(PCMSim& pcm, int channel);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when this solenoid is initialized.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify should the callback be run with the initial state
|
||||
* @return the {@link CallbackStore} object associated with this callback.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check if this solenoid has been initialized.
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
bool GetInitialized() const;
|
||||
|
||||
/**
|
||||
* Define whether this solenoid has been initialized.
|
||||
*
|
||||
* @param initialized whether the solenoid is intiialized.
|
||||
*/
|
||||
void SetInitialized(bool initialized);
|
||||
|
||||
/**
|
||||
* Register a callback to be run when the output of this solenoid has changed.
|
||||
*
|
||||
* @param callback the callback
|
||||
* @param initialNotify should the callback be run with the initial value
|
||||
* @return the {@link CallbackStore} object associated with this callback.
|
||||
*/
|
||||
[[nodiscard]] std::unique_ptr<CallbackStore> RegisterOutputCallback(
|
||||
NotifyCallback callback, bool initialNotify);
|
||||
|
||||
/**
|
||||
* Check the solenoid output.
|
||||
*
|
||||
* @return the solenoid output
|
||||
*/
|
||||
bool GetOutput() const;
|
||||
|
||||
/**
|
||||
* Change the solenoid output.
|
||||
*
|
||||
* @param output the new solenoid output
|
||||
*/
|
||||
void SetOutput(bool output);
|
||||
|
||||
private:
|
||||
PCMSim m_pcm;
|
||||
int m_channel;
|
||||
};
|
||||
} // namespace frc::sim
|
||||
Reference in New Issue
Block a user