SCRIPT: wpiformat

This commit is contained in:
PJ Reiniger
2025-11-07 20:01:58 -05:00
committed by Peter Johnson
parent ae6bdc9d25
commit 2109161534
749 changed files with 5504 additions and 3936 deletions

View File

@@ -63,13 +63,15 @@ void Compressor::EnableDigital() {
m_module->EnableCompressorDigital();
}
void Compressor::EnableAnalog(wpi::units::pounds_per_square_inch_t minPressure,
wpi::units::pounds_per_square_inch_t maxPressure) {
void Compressor::EnableAnalog(
wpi::units::pounds_per_square_inch_t minPressure,
wpi::units::pounds_per_square_inch_t maxPressure) {
m_module->EnableCompressorAnalog(minPressure, maxPressure);
}
void Compressor::EnableHybrid(wpi::units::pounds_per_square_inch_t minPressure,
wpi::units::pounds_per_square_inch_t maxPressure) {
void Compressor::EnableHybrid(
wpi::units::pounds_per_square_inch_t minPressure,
wpi::units::pounds_per_square_inch_t maxPressure) {
m_module->EnableCompressorHybrid(minPressure, maxPressure);
}

View File

@@ -23,11 +23,11 @@ DoubleSolenoid::DoubleSolenoid(int busId, int module,
m_reverseChannel{reverseChannel} {
if (!m_module->CheckSolenoidChannel(m_forwardChannel)) {
throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
m_forwardChannel);
m_forwardChannel);
}
if (!m_module->CheckSolenoidChannel(m_reverseChannel)) {
throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
m_reverseChannel);
m_reverseChannel);
}
m_forwardMask = 1 << forwardChannel;
@@ -37,14 +37,15 @@ DoubleSolenoid::DoubleSolenoid(int busId, int module,
int allocMask = m_module->CheckAndReserveSolenoids(m_mask);
if (allocMask != 0) {
if (allocMask == m_mask) {
throw WPILIB_MakeError(err::ResourceAlreadyAllocated, "Channels {} and {}",
m_forwardChannel, m_reverseChannel);
throw WPILIB_MakeError(err::ResourceAlreadyAllocated,
"Channels {} and {}", m_forwardChannel,
m_reverseChannel);
} else if (allocMask == m_forwardMask) {
throw WPILIB_MakeError(err::ResourceAlreadyAllocated, "Channel {}",
m_forwardChannel);
m_forwardChannel);
} else {
throw WPILIB_MakeError(err::ResourceAlreadyAllocated, "Channel {}",
m_reverseChannel);
m_reverseChannel);
}
}
@@ -52,8 +53,8 @@ DoubleSolenoid::DoubleSolenoid(int busId, int module,
fmt::format("Solenoid[{},{}]", m_forwardChannel, m_reverseChannel),
"DoubleSolenoid");
wpi::util::SendableRegistry::Add(this, "DoubleSolenoid",
m_module->GetModuleNumber(), m_forwardChannel);
wpi::util::SendableRegistry::Add(
this, "DoubleSolenoid", m_module->GetModuleNumber(), m_forwardChannel);
}
DoubleSolenoid::DoubleSolenoid(int busId, PneumaticsModuleType moduleType,

View File

@@ -26,21 +26,22 @@
using namespace wpi;
/** Converts volts to PSI per the REV Analog Pressure Sensor datasheet. */
wpi::units::pounds_per_square_inch_t VoltsToPSI(wpi::units::volt_t sensorVoltage,
wpi::units::volt_t supplyVoltage) {
wpi::units::pounds_per_square_inch_t VoltsToPSI(
wpi::units::volt_t sensorVoltage, wpi::units::volt_t supplyVoltage) {
return wpi::units::pounds_per_square_inch_t{
250 * (sensorVoltage.value() / supplyVoltage.value()) - 25};
}
/** Converts PSI to volts per the REV Analog Pressure Sensor datasheet. */
wpi::units::volt_t PSIToVolts(wpi::units::pounds_per_square_inch_t pressure,
wpi::units::volt_t supplyVoltage) {
wpi::units::volt_t supplyVoltage) {
return wpi::units::volt_t{supplyVoltage.value() *
(0.004 * pressure.value() + 0.1)};
(0.004 * pressure.value() + 0.1)};
}
wpi::util::mutex PneumaticHub::m_handleLock;
std::unique_ptr<wpi::util::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>
std::unique_ptr<
wpi::util::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>
PneumaticHub::m_handleMaps = nullptr;
// Always called under lock, so we can avoid the double lock from the magic
@@ -49,10 +50,11 @@ std::weak_ptr<PneumaticHub::DataStore>& PneumaticHub::GetDataStore(int busId,
int module) {
int32_t numBuses = HAL_GetNumCanBuses();
WPILIB_AssertMessage(busId >= 0 && busId < numBuses,
"Bus {} out of range. Must be [0-{}).", busId, numBuses);
"Bus {} out of range. Must be [0-{}).", busId, numBuses);
if (!m_handleMaps) {
m_handleMaps = std::make_unique<
wpi::util::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>(numBuses);
wpi::util::DenseMap<int, std::weak_ptr<PneumaticHub::DataStore>>[]>(
numBuses);
}
return m_handleMaps[busId][module];
}
@@ -138,17 +140,17 @@ void PneumaticHub::EnableCompressorAnalog(
wpi::units::pounds_per_square_inch_t maxPressure) {
if (minPressure >= maxPressure) {
throw WPILIB_MakeError(err::InvalidParameter,
"maxPressure must be greater than minPressure");
"maxPressure must be greater than minPressure");
}
if (minPressure < 0_psi || minPressure > 120_psi) {
throw WPILIB_MakeError(err::ParameterOutOfRange,
"minPressure must be between 0 and 120 PSI, got {}",
minPressure);
"minPressure must be between 0 and 120 PSI, got {}",
minPressure);
}
if (maxPressure < 0_psi || maxPressure > 120_psi) {
throw WPILIB_MakeError(err::ParameterOutOfRange,
"maxPressure must be between 0 and 120 PSI, got {}",
maxPressure);
"maxPressure must be between 0 and 120 PSI, got {}",
maxPressure);
}
// Send the voltage as it would be if the 5V rail was at exactly 5V.
@@ -168,17 +170,17 @@ void PneumaticHub::EnableCompressorHybrid(
wpi::units::pounds_per_square_inch_t maxPressure) {
if (minPressure >= maxPressure) {
throw WPILIB_MakeError(err::InvalidParameter,
"maxPressure must be greater than minPressure");
"maxPressure must be greater than minPressure");
}
if (minPressure < 0_psi || minPressure > 120_psi) {
throw WPILIB_MakeError(err::ParameterOutOfRange,
"minPressure must be between 0 and 120 PSI, got {}",
minPressure);
"minPressure must be between 0 and 120 PSI, got {}",
minPressure);
}
if (maxPressure < 0_psi || maxPressure > 120_psi) {
throw WPILIB_MakeError(err::ParameterOutOfRange,
"maxPressure must be between 0 and 120 PSI, got {}",
maxPressure);
"maxPressure must be between 0 and 120 PSI, got {}",
maxPressure);
}
// Send the voltage as it would be if the 5V rail was at exactly 5V.
@@ -245,7 +247,8 @@ void PneumaticHub::FireOneShot(int index) {
WPILIB_ReportError(status, "Module {}", m_module);
}
void PneumaticHub::SetOneShotDuration(int index, wpi::units::second_t duration) {
void PneumaticHub::SetOneShotDuration(int index,
wpi::units::second_t duration) {
m_dataStore->m_oneShotDurMs[index] = duration;
}
@@ -360,7 +363,7 @@ bool PneumaticHub::Faults::GetChannelFault(int channel) const {
return Channel15Fault != 0;
default:
throw WPILIB_MakeError(err::ChannelIndexOutOfRange,
"Pneumatics fault channel out of bounds!");
"Pneumatics fault channel out of bounds!");
}
}
@@ -405,13 +408,15 @@ wpi::units::volt_t PneumaticHub::GetAnalogVoltage(int channel) const {
return wpi::units::volt_t{voltage};
}
wpi::units::pounds_per_square_inch_t PneumaticHub::GetPressure(int channel) const {
wpi::units::pounds_per_square_inch_t PneumaticHub::GetPressure(
int channel) const {
int32_t status = 0;
auto sensorVoltage = HAL_GetREVPHAnalogVoltage(m_handle, channel, &status);
WPILIB_ReportError(status, "Module {}", m_module);
auto supplyVoltage = HAL_GetREVPH5VVoltage(m_handle, &status);
WPILIB_ReportError(status, "Module {}", m_module);
return VoltsToPSI(wpi::units::volt_t{sensorVoltage}, wpi::units::volt_t{supplyVoltage});
return VoltsToPSI(wpi::units::volt_t{sensorVoltage},
wpi::units::volt_t{supplyVoltage});
}
Solenoid PneumaticHub::MakeSolenoid(int channel) {

View File

@@ -35,7 +35,7 @@ std::shared_ptr<PneumaticsBase> PneumaticsBase::GetForType(
return PneumaticHub::GetForModule(busId, module);
}
throw WPILIB_MakeError(err::InvalidParameter, "{}",
static_cast<int>(moduleType));
static_cast<int>(moduleType));
}
int PneumaticsBase::GetDefaultForType(PneumaticsModuleType moduleType) {
@@ -45,5 +45,5 @@ int PneumaticsBase::GetDefaultForType(PneumaticsModuleType moduleType) {
return SensorUtil::GetDefaultREVPHModule();
}
throw WPILIB_MakeError(err::InvalidParameter, "{}",
static_cast<int>(moduleType));
static_cast<int>(moduleType));
}

View File

@@ -23,8 +23,8 @@
using namespace wpi;
wpi::util::mutex PneumaticsControlModule::m_handleLock;
std::unique_ptr<
wpi::util::DenseMap<int, std::weak_ptr<PneumaticsControlModule::DataStore>>[]>
std::unique_ptr<wpi::util::DenseMap<
int, std::weak_ptr<PneumaticsControlModule::DataStore>>[]>
PneumaticsControlModule::m_handleMaps = nullptr;
// Always called under lock, so we can avoid the double lock from the magic
@@ -33,7 +33,7 @@ std::weak_ptr<PneumaticsControlModule::DataStore>&
PneumaticsControlModule::GetDataStore(int busId, int module) {
int32_t numBuses = HAL_GetNumCanBuses();
WPILIB_AssertMessage(busId >= 0 && busId < numBuses,
"Bus {} out of range. Must be [0-{}).", busId, numBuses);
"Bus {} out of range. Must be [0-{}).", busId, numBuses);
if (!m_handleMaps) {
m_handleMaps = std::make_unique<wpi::util::DenseMap<
int, std::weak_ptr<PneumaticsControlModule::DataStore>>[]>(numBuses);
@@ -234,8 +234,8 @@ void PneumaticsControlModule::FireOneShot(int index) {
WPILIB_ReportError(status, "Module {}", m_module);
}
void PneumaticsControlModule::SetOneShotDuration(int index,
wpi::units::second_t duration) {
void PneumaticsControlModule::SetOneShotDuration(
int index, wpi::units::second_t duration) {
int32_t status = 0;
wpi::units::millisecond_t millis = duration;
HAL_SetCTREPCMOneShotDuration(m_handle, index, millis.to<int32_t>(), &status);
@@ -275,7 +275,8 @@ void PneumaticsControlModule::UnreserveCompressor() {
m_dataStore->m_compressorReserved = false;
}
wpi::units::volt_t PneumaticsControlModule::GetAnalogVoltage(int channel) const {
wpi::units::volt_t PneumaticsControlModule::GetAnalogVoltage(
int channel) const {
return 0_V;
}

View File

@@ -19,17 +19,19 @@ Solenoid::Solenoid(int busId, int module, PneumaticsModuleType moduleType,
: m_module{PneumaticsBase::GetForType(busId, module, moduleType)},
m_channel{channel} {
if (!m_module->CheckSolenoidChannel(m_channel)) {
throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}", m_channel);
throw WPILIB_MakeError(err::ChannelIndexOutOfRange, "Channel {}",
m_channel);
}
m_mask = 1 << channel;
if (m_module->CheckAndReserveSolenoids(m_mask) != 0) {
throw WPILIB_MakeError(err::ResourceAlreadyAllocated, "Channel {}", m_channel);
throw WPILIB_MakeError(err::ResourceAlreadyAllocated, "Channel {}",
m_channel);
}
m_module->ReportUsage(fmt::format("Solenoid[{}]", m_channel), "Solenoid");
wpi::util::SendableRegistry::Add(this, "Solenoid", m_module->GetModuleNumber(),
m_channel);
wpi::util::SendableRegistry::Add(this, "Solenoid",
m_module->GetModuleNumber(), m_channel);
}
Solenoid::Solenoid(int busId, PneumaticsModuleType moduleType, int channel)