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

@@ -15,9 +15,9 @@ ADXL345_I2C::ADXL345_I2C(I2C::Port port, Range range, int deviceAddress)
: m_i2c(port, deviceAddress),
m_simDevice("Accel:ADXL345_I2C", port, deviceAddress) {
if (m_simDevice) {
m_simRange = m_simDevice.CreateEnumDouble("range", wpi::hal::SimDevice::kOutput,
{"2G", "4G", "8G", "16G"},
{2.0, 4.0, 8.0, 16.0}, 0);
m_simRange = m_simDevice.CreateEnumDouble(
"range", wpi::hal::SimDevice::kOutput, {"2G", "4G", "8G", "16G"},
{2.0, 4.0, 8.0, 16.0}, 0);
m_simX = m_simDevice.CreateDouble("x", wpi::hal::SimDevice::kInput, 0.0);
m_simY = m_simDevice.CreateDouble("y", wpi::hal::SimDevice::kInput, 0.0);
m_simZ = m_simDevice.CreateDouble("z", wpi::hal::SimDevice::kInput, 0.0);

View File

@@ -55,5 +55,5 @@ void AnalogAccelerometer::InitAccelerometer() {
HAL_ReportUsage("IO", m_analogInput->GetChannel(), "Accelerometer");
wpi::util::SendableRegistry::Add(this, "Accelerometer",
m_analogInput->GetChannel());
m_analogInput->GetChannel());
}

View File

@@ -23,7 +23,7 @@ CAN::CAN(int busId, int deviceId, int deviceManufacturer, int deviceType) {
busId, static_cast<HAL_CANManufacturer>(deviceManufacturer), deviceId,
static_cast<HAL_CANDeviceType>(deviceType), &status);
WPILIB_CheckErrorStatus(status, "device id {} mfg {} type {}", deviceId,
deviceManufacturer, deviceType);
deviceManufacturer, deviceType);
HAL_ReportUsage(
fmt::format("CAN[{}][{}][{}]", deviceType, deviceManufacturer, deviceId),

View File

@@ -25,10 +25,11 @@ SerialPort::SerialPort(int baudRate, Port port, int dataBits,
HAL_SetSerialDataBits(m_portHandle, dataBits, &status);
WPILIB_CheckErrorStatus(status, "SetSerialDataBits {}", dataBits);
HAL_SetSerialParity(m_portHandle, parity, &status);
WPILIB_CheckErrorStatus(status, "SetSerialParity {}", static_cast<int>(parity));
WPILIB_CheckErrorStatus(status, "SetSerialParity {}",
static_cast<int>(parity));
HAL_SetSerialStopBits(m_portHandle, stopBits, &status);
WPILIB_CheckErrorStatus(status, "SetSerialStopBits {}",
static_cast<int>(stopBits));
static_cast<int>(stopBits));
// Set the default timeout to 5 seconds.
SetTimeout(5_s);
@@ -55,10 +56,11 @@ SerialPort::SerialPort(int baudRate, std::string_view portName, Port port,
HAL_SetSerialDataBits(m_portHandle, dataBits, &status);
WPILIB_CheckErrorStatus(status, "SetSerialDataBits {}", dataBits);
HAL_SetSerialParity(m_portHandle, parity, &status);
WPILIB_CheckErrorStatus(status, "SetSerialParity {}", static_cast<int>(parity));
WPILIB_CheckErrorStatus(status, "SetSerialParity {}",
static_cast<int>(parity));
HAL_SetSerialStopBits(m_portHandle, stopBits, &status);
WPILIB_CheckErrorStatus(status, "SetSerialStopBits {}",
static_cast<int>(stopBits));
static_cast<int>(stopBits));
// Set the default timeout to 5 seconds.
SetTimeout(5_s);
@@ -75,7 +77,7 @@ void SerialPort::SetFlowControl(SerialPort::FlowControl flowControl) {
int32_t status = 0;
HAL_SetSerialFlowControl(m_portHandle, flowControl, &status);
WPILIB_CheckErrorStatus(status, "SetFlowControl {}",
static_cast<int>(flowControl));
static_cast<int>(flowControl));
}
void SerialPort::EnableTermination(char terminator) {
@@ -137,7 +139,8 @@ void SerialPort::SetWriteBufferSize(int size) {
void SerialPort::SetWriteBufferMode(SerialPort::WriteBufferMode mode) {
int32_t status = 0;
HAL_SetSerialWriteMode(m_portHandle, mode, &status);
WPILIB_CheckErrorStatus(status, "SetWriteBufferMode {}", static_cast<int>(mode));
WPILIB_CheckErrorStatus(status, "SetWriteBufferMode {}",
static_cast<int>(mode));
}
void SerialPort::Flush() {

View File

@@ -82,7 +82,7 @@ void PWM::SetOutputPeriod(OutputPeriod mult) {
break;
default:
throw WPILIB_MakeError(err::InvalidParameter, "OutputPeriod value {}",
static_cast<int>(mult));
static_cast<int>(mult));
}
WPILIB_CheckErrorStatus(status, "Channel {}", m_channel);
@@ -101,5 +101,7 @@ void PWM::InitSendable(wpi::util::SendableBuilder& builder) {
builder.SetActuator(true);
builder.AddDoubleProperty(
"Value", [=, this] { return GetPulseTime().value(); },
[=, this](double value) { SetPulseTime(wpi::units::millisecond_t{value}); });
[=, this](double value) {
SetPulseTime(wpi::units::millisecond_t{value});
});
}

View File

@@ -55,7 +55,7 @@ LEDPattern LEDPattern::Reversed() {
LEDPattern LEDPattern::OffsetBy(int offset) {
return MapIndex([offset](size_t bufLen, size_t i) {
return wpi::math::FloorMod(static_cast<int>(i) + offset,
static_cast<int>(bufLen));
static_cast<int>(bufLen));
});
}
@@ -74,7 +74,7 @@ LEDPattern LEDPattern::ScrollAtRelativeSpeed(wpi::units::hertz_t velocity) {
int offset = static_cast<int>(std::floor(t * bufLen));
return wpi::math::FloorMod(static_cast<int>(i) + offset,
static_cast<int>(bufLen));
static_cast<int>(bufLen));
});
}
@@ -95,11 +95,12 @@ LEDPattern LEDPattern::ScrollAtAbsoluteSpeed(
auto offset = static_cast<int64_t>(now) / microsPerLed;
return wpi::math::FloorMod(static_cast<int>(i) + offset,
static_cast<int>(bufLen));
static_cast<int>(bufLen));
});
}
LEDPattern LEDPattern::Blink(wpi::units::second_t onTime, wpi::units::second_t offTime) {
LEDPattern LEDPattern::Blink(wpi::units::second_t onTime,
wpi::units::second_t offTime) {
auto totalMicros = wpi::units::microsecond_t{onTime + offTime}.to<uint64_t>();
auto onMicros = wpi::units::microsecond_t{onTime}.to<uint64_t>();

View File

@@ -158,18 +158,20 @@ void MotorSafety::Check() {
}
if (stopTime < Timer::GetFPGATimestamp()) {
WPILIB_ReportError(err::Timeout,
"{}... Output not updated often enough. See "
"https://docs.wpilib.org/motorsafety for more information.",
GetDescription());
WPILIB_ReportError(
err::Timeout,
"{}... Output not updated often enough. See "
"https://docs.wpilib.org/motorsafety for more information.",
GetDescription());
try {
StopMotor();
} catch (wpi::RuntimeError& e) {
e.Report();
} catch (std::exception& e) {
WPILIB_ReportError(err::Error, "{} StopMotor threw unexpected exception: {}",
GetDescription(), e.what());
WPILIB_ReportError(err::Error,
"{} StopMotor threw unexpected exception: {}",
GetDescription(), e.what());
}
}
}

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)

View File

@@ -246,7 +246,7 @@ bool PowerDistribution::Faults::GetBreakerFault(int channel) const {
return Channel23BreakerFault != 0;
default:
throw WPILIB_MakeError(err::ChannelIndexOutOfRange,
"Power distribution fault channel out of bounds!");
"Power distribution fault channel out of bounds!");
}
}
@@ -302,7 +302,7 @@ bool PowerDistribution::StickyFaults::GetBreakerFault(int channel) const {
return Channel23BreakerFault != 0;
default:
throw WPILIB_MakeError(err::ChannelIndexOutOfRange,
"Power distribution fault channel out of bounds!");
"Power distribution fault channel out of bounds!");
}
}

View File

@@ -58,7 +58,8 @@ AnalogEncoder::AnalogEncoder(std::shared_ptr<AnalogInput> analogInput,
}
void AnalogEncoder::Init(double fullRange, double expectedZero) {
m_simDevice = wpi::hal::SimDevice{"AnalogEncoder", m_analogInput->GetChannel()};
m_simDevice =
wpi::hal::SimDevice{"AnalogEncoder", m_analogInput->GetChannel()};
if (m_simDevice) {
m_simPosition = m_simDevice.CreateDouble("Position", false, 0.0);
@@ -70,7 +71,7 @@ void AnalogEncoder::Init(double fullRange, double expectedZero) {
HAL_ReportUsage("IO", m_analogInput->GetChannel(), "AnalogEncoder");
wpi::util::SendableRegistry::Add(this, "Analog Encoder",
m_analogInput->GetChannel());
m_analogInput->GetChannel());
}
double AnalogEncoder::Get() const {

View File

@@ -23,9 +23,9 @@ AnalogPotentiometer::AnalogPotentiometer(int channel, double fullRange,
AnalogPotentiometer::AnalogPotentiometer(AnalogInput* input, double fullRange,
double offset)
: AnalogPotentiometer(
std::shared_ptr<AnalogInput>(input, wpi::util::NullDeleter<AnalogInput>()),
fullRange, offset) {}
: AnalogPotentiometer(std::shared_ptr<AnalogInput>(
input, wpi::util::NullDeleter<AnalogInput>()),
fullRange, offset) {}
AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
double fullRange, double offset)
@@ -33,7 +33,7 @@ AnalogPotentiometer::AnalogPotentiometer(std::shared_ptr<AnalogInput> input,
m_fullRange(fullRange),
m_offset(offset) {
wpi::util::SendableRegistry::Add(this, "AnalogPotentiometer",
m_analog_input->GetChannel());
m_analog_input->GetChannel());
}
double AnalogPotentiometer::Get() const {

View File

@@ -61,19 +61,19 @@ DutyCycleEncoder::DutyCycleEncoder(std::shared_ptr<DutyCycle> dutyCycle,
void DutyCycleEncoder::Init(double fullRange, double expectedZero) {
m_simDevice = wpi::hal::SimDevice{"DutyCycle:DutyCycleEncoder",
m_dutyCycle->GetSourceChannel()};
m_dutyCycle->GetSourceChannel()};
if (m_simDevice) {
m_simPosition = m_simDevice.CreateDouble("Position", false, 0.0);
m_simIsConnected =
m_simDevice.CreateBoolean("Connected", wpi::hal::SimDevice::kInput, true);
m_simIsConnected = m_simDevice.CreateBoolean(
"Connected", wpi::hal::SimDevice::kInput, true);
}
m_fullRange = fullRange;
m_expectedZero = expectedZero;
wpi::util::SendableRegistry::Add(this, "DutyCycle Encoder",
m_dutyCycle->GetSourceChannel());
m_dutyCycle->GetSourceChannel());
}
double DutyCycleEncoder::Get() const {