Don't force public variables to use Hungarian notation (#8774)

People generally have expressed a dislike for the Hungarian notation
used in member variables, especially in examples/templates, and our
styleguide shouldn't be forced on downstream consumers, so this removes
all Hungarian notation from the examples/templates.

There are _some_ benefits to Hungarian for private member variables
(like knowing what's a member vs. local in a PR review) so we'll keep
private member variables the same for now, but public variables should
no longer use Hungarian notation, since it looks much worse. A new PMD
XPath rule has been added to accomplish this goal. Some other
non-compliant variables were fixed for the new rule.
This commit is contained in:
Gold856
2026-04-25 14:32:08 -04:00
committed by GitHub
parent e7e51c9c05
commit 35e8abedeb
443 changed files with 4584 additions and 4789 deletions

View File

@@ -50,25 +50,25 @@ public class SysIdRoutine extends SysIdRoutineLog {
* @param mechanism Hardware interface for the SysId routine.
*/
public SysIdRoutine(Config config, Mechanism mechanism) {
super(mechanism.m_name);
super(mechanism.name);
m_config = config;
m_mechanism = mechanism;
m_recordState = config.m_recordState != null ? config.m_recordState : this::recordState;
m_recordState = config.recordState != null ? config.recordState : this::recordState;
}
/** Hardware-independent configuration for a SysId test routine. */
public static class Config {
/** The voltage ramp rate used for quasistatic test routines. */
public final Velocity<VoltageUnit> m_rampRate;
public final Velocity<VoltageUnit> rampRate;
/** The step voltage output used for dynamic test routines. */
public final Voltage m_stepVoltage;
public final Voltage stepVoltage;
/** Safety timeout for the test routine commands. */
public final Time m_timeout;
public final Time timeout;
/** Optional handle for recording test state in a third-party logging solution. */
public final Consumer<State> m_recordState;
public final Consumer<State> recordState;
/**
* Create a new configuration for a SysId test routine.
@@ -88,10 +88,10 @@ public class SysIdRoutine extends SysIdRoutineLog {
Voltage stepVoltage,
Time timeout,
Consumer<State> recordState) {
m_rampRate = rampRate != null ? rampRate : Volts.of(1).per(Second);
m_stepVoltage = stepVoltage != null ? stepVoltage : Volts.of(7);
m_timeout = timeout != null ? timeout : Seconds.of(10);
m_recordState = recordState;
this.rampRate = rampRate != null ? rampRate : Volts.of(1).per(Second);
this.stepVoltage = stepVoltage != null ? stepVoltage : Volts.of(7);
this.timeout = timeout != null ? timeout : Seconds.of(10);
this.recordState = recordState;
}
/**
@@ -128,19 +128,19 @@ public class SysIdRoutine extends SysIdRoutineLog {
*/
public static class Mechanism {
/** Sends the SysId-specified drive signal to the mechanism motors during test routines. */
public final Consumer<? super Voltage> m_drive;
public final Consumer<? super Voltage> drive;
/**
* Returns measured data (voltages, positions, velocities) of the mechanism motors during test
* routines.
*/
public final Consumer<SysIdRoutineLog> m_log;
public final Consumer<SysIdRoutineLog> log;
/** The subsystem containing the motor(s) that is (or are) being characterized. */
public final Subsystem m_subsystem;
public final Subsystem subsystem;
/** The name of the mechanism being tested. */
public final String m_name;
public final String name;
/**
* Create a new mechanism specification for a SysId routine.
@@ -160,10 +160,10 @@ public class SysIdRoutine extends SysIdRoutineLog {
*/
public Mechanism(
Consumer<Voltage> drive, Consumer<SysIdRoutineLog> log, Subsystem subsystem, String name) {
m_drive = drive;
m_log = log != null ? log : l -> {};
m_subsystem = subsystem;
m_name = name != null ? name : subsystem.getName();
this.drive = drive;
this.log = log != null ? log : l -> {};
this.subsystem = subsystem;
this.name = name != null ? name : subsystem.getName();
}
/**
@@ -217,24 +217,24 @@ public class SysIdRoutine extends SysIdRoutineLog {
Timer timer = new Timer();
return m_mechanism
.m_subsystem
.subsystem
.runOnce(timer::restart)
.andThen(
m_mechanism.m_subsystem.run(
m_mechanism.subsystem.run(
() -> {
m_mechanism.m_drive.accept(
(Voltage) m_config.m_rampRate.times(Seconds.of(timer.get() * outputSign)));
m_mechanism.m_log.accept(this);
m_mechanism.drive.accept(
(Voltage) m_config.rampRate.times(Seconds.of(timer.get() * outputSign)));
m_mechanism.log.accept(this);
m_recordState.accept(state);
}))
.finallyDo(
() -> {
m_mechanism.m_drive.accept(Volts.of(0));
m_mechanism.drive.accept(Volts.of(0));
m_recordState.accept(State.NONE);
timer.stop();
})
.withName("sysid-" + state.toString() + "-" + m_mechanism.m_name)
.withTimeout(m_config.m_timeout.in(Seconds));
.withName("sysid-" + state.toString() + "-" + m_mechanism.name)
.withTimeout(m_config.timeout.in(Seconds));
}
/**
@@ -257,21 +257,21 @@ public class SysIdRoutine extends SysIdRoutineLog {
Voltage[] output = {Volts.zero()};
return m_mechanism
.m_subsystem
.runOnce(() -> output[0] = m_config.m_stepVoltage.times(outputSign))
.subsystem
.runOnce(() -> output[0] = m_config.stepVoltage.times(outputSign))
.andThen(
m_mechanism.m_subsystem.run(
m_mechanism.subsystem.run(
() -> {
m_mechanism.m_drive.accept(output[0]);
m_mechanism.m_log.accept(this);
m_mechanism.drive.accept(output[0]);
m_mechanism.log.accept(this);
m_recordState.accept(state);
}))
.finallyDo(
() -> {
m_mechanism.m_drive.accept(Volts.of(0));
m_mechanism.drive.accept(Volts.of(0));
m_recordState.accept(State.NONE);
})
.withName("sysid-" + state.toString() + "-" + m_mechanism.m_name)
.withTimeout(m_config.m_timeout.in(Seconds));
.withName("sysid-" + state.toString() + "-" + m_mechanism.name)
.withTimeout(m_config.timeout.in(Seconds));
}
}

View File

@@ -18,24 +18,24 @@ wpi::cmd::CommandPtr SysIdRoutine::Quasistatic(Direction direction) {
double outputSign = direction == Direction::kForward ? 1.0 : -1.0;
return m_mechanism.m_subsystem->RunOnce([this] { timer.Restart(); })
return m_mechanism.subsystem->RunOnce([this] { timer.Restart(); })
.AndThen(
m_mechanism.m_subsystem
m_mechanism.subsystem
->Run([this, state, outputSign] {
m_outputVolts = outputSign * timer.Get() * m_config.m_rampRate;
m_mechanism.m_drive(m_outputVolts);
m_mechanism.m_log(this);
m_outputVolts = outputSign * timer.Get() * m_config.rampRate;
m_mechanism.drive(m_outputVolts);
m_mechanism.log(this);
m_recordState(state);
})
.FinallyDo([this] {
m_mechanism.m_drive(0_V);
m_mechanism.drive(0_V);
m_recordState(wpi::sysid::State::NONE);
timer.Stop();
})
.WithName("sysid-" +
wpi::sysid::SysIdRoutineLog::StateEnumToString(state) +
"-" + m_mechanism.m_name)
.WithTimeout(m_config.m_timeout));
"-" + m_mechanism.name)
.WithTimeout(m_config.timeout));
}
wpi::cmd::CommandPtr SysIdRoutine::Dynamic(Direction direction) {
@@ -48,19 +48,19 @@ wpi::cmd::CommandPtr SysIdRoutine::Dynamic(Direction direction) {
double outputSign = direction == Direction::kForward ? 1.0 : -1.0;
return m_mechanism.m_subsystem
->RunOnce([this] { m_outputVolts = m_config.m_stepVoltage; })
.AndThen(m_mechanism.m_subsystem->Run([this, state, outputSign] {
m_mechanism.m_drive(m_outputVolts * outputSign);
m_mechanism.m_log(this);
return m_mechanism.subsystem
->RunOnce([this] { m_outputVolts = m_config.stepVoltage; })
.AndThen(m_mechanism.subsystem->Run([this, state, outputSign] {
m_mechanism.drive(m_outputVolts * outputSign);
m_mechanism.log(this);
m_recordState(state);
}))
.FinallyDo([this] {
m_mechanism.m_drive(0_V);
m_mechanism.drive(0_V);
m_recordState(wpi::sysid::State::NONE);
})
.WithName("sysid-" +
wpi::sysid::SysIdRoutineLog::StateEnumToString(state) + "-" +
m_mechanism.m_name)
.WithTimeout(m_config.m_timeout);
m_mechanism.name)
.WithTimeout(m_config.timeout);
}

View File

@@ -23,17 +23,17 @@ using ramp_rate_t = wpi::units::unit_t<wpi::units::compound_unit<
class Config {
public:
/// The voltage ramp rate used for quasistatic test routines.
ramp_rate_t m_rampRate{1_V / 1_s};
ramp_rate_t rampRate{1_V / 1_s};
/// The step voltage output used for dynamic test routines.
wpi::units::volt_t m_stepVoltage{7_V};
wpi::units::volt_t stepVoltage{7_V};
/// Safety timeout for the test routine commands.
wpi::units::second_t m_timeout{10_s};
wpi::units::second_t timeout{10_s};
/// Optional handle for recording test state in a third-party logging
/// solution.
std::function<void(wpi::sysid::State)> m_recordState;
std::function<void(wpi::sysid::State)> recordState;
/**
* Create a new configuration for a SysId test routine.
@@ -52,15 +52,15 @@ class Config {
std::optional<wpi::units::volt_t> stepVoltage,
std::optional<wpi::units::second_t> timeout,
std::function<void(wpi::sysid::State)> recordState)
: m_recordState{std::move(recordState)} {
: recordState{std::move(recordState)} {
if (rampRate) {
m_rampRate = rampRate.value();
this->rampRate = rampRate.value();
}
if (stepVoltage) {
m_stepVoltage = stepVoltage.value();
this->stepVoltage = stepVoltage.value();
}
if (timeout) {
m_timeout = timeout.value();
this->timeout = timeout.value();
}
}
};
@@ -69,19 +69,19 @@ class Mechanism {
public:
/// Sends the SysId-specified drive signal to the mechanism motors during test
/// routines.
std::function<void(wpi::units::volt_t)> m_drive;
std::function<void(wpi::units::volt_t)> drive;
/// Returns measured data (voltages, positions, velocities) of the mechanism
/// motors during test routines.
std::function<void(wpi::sysid::SysIdRoutineLog*)> m_log;
std::function<void(wpi::sysid::SysIdRoutineLog*)> log;
/// The subsystem containing the motor(s) that is (or are) being
/// characterized.
wpi::cmd::Subsystem* m_subsystem;
wpi::cmd::Subsystem* subsystem;
/// The name of the mechanism being tested. Will be appended to the log entry
/// title for the routine's test state, e.g. "sysid-test-state-mechanism".
std::string m_name;
std::string name;
/**
* Create a new mechanism specification for a SysId routine.
@@ -105,10 +105,10 @@ class Mechanism {
Mechanism(std::function<void(wpi::units::volt_t)> drive,
std::function<void(wpi::sysid::SysIdRoutineLog*)> log,
wpi::cmd::Subsystem* subsystem, std::string_view name)
: m_drive{std::move(drive)},
m_log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}},
m_subsystem{subsystem},
m_name{name} {}
: drive{std::move(drive)},
log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}},
subsystem{subsystem},
name{name} {}
/**
* Create a new mechanism specification for a SysId routine. Defaults the
@@ -130,10 +130,10 @@ class Mechanism {
Mechanism(std::function<void(wpi::units::volt_t)> drive,
std::function<void(wpi::sysid::SysIdRoutineLog*)> log,
wpi::cmd::Subsystem* subsystem)
: m_drive{std::move(drive)},
m_log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}},
m_subsystem{subsystem},
m_name{m_subsystem->GetName()} {}
: drive{std::move(drive)},
log{log ? std::move(log) : [](wpi::sysid::SysIdRoutineLog* log) {}},
subsystem{subsystem},
name{subsystem->GetName()} {}
};
/**
@@ -176,13 +176,13 @@ class SysIdRoutine : public wpi::sysid::SysIdRoutineLog {
* @param mechanism Hardware interface for the SysId routine.
*/
SysIdRoutine(Config config, Mechanism mechanism)
: SysIdRoutineLog(mechanism.m_name),
: SysIdRoutineLog(mechanism.name),
m_config(config),
m_mechanism(mechanism),
m_recordState(config.m_recordState ? config.m_recordState
: [this](wpi::sysid::State state) {
this->RecordState(state);
}) {}
m_recordState(config.recordState ? config.recordState
: [this](wpi::sysid::State state) {
this->RecordState(state);
}) {}
wpi::cmd::CommandPtr Quasistatic(Direction direction);
wpi::cmd::CommandPtr Dynamic(Direction direction);