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

@@ -14,8 +14,8 @@ import org.wpilib.framework.TimedRobot;
* this project, you must also update the Main.java file in the project.
*/
public class Robot extends TimedRobot {
private Command m_autonomousCommand;
private final RobotContainer m_robotContainer;
private Command autonomousCommand;
private final RobotContainer robotContainer;
/**
* This function is run when the robot is first started up and should be used for any
@@ -24,7 +24,7 @@ public class Robot extends TimedRobot {
public Robot() {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
robotContainer = new RobotContainer();
}
/**
@@ -54,11 +54,11 @@ public class Robot extends TimedRobot {
@Override
public void autonomousInit() {
// Get selected routine from the SmartDashboard
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
autonomousCommand = robotContainer.getAutonomousCommand();
// schedule the autonomous command (example)
if (m_autonomousCommand != null) {
CommandScheduler.getInstance().schedule(m_autonomousCommand);
if (autonomousCommand != null) {
CommandScheduler.getInstance().schedule(autonomousCommand);
}
}
@@ -72,8 +72,8 @@ public class Robot extends TimedRobot {
// use the default command which is ArcadeDrive. If you want the autonomous
// to continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand != null) {
m_autonomousCommand.cancel();
if (autonomousCommand != null) {
autonomousCommand.cancel();
}
}

View File

@@ -27,14 +27,14 @@ import org.wpilib.smartdashboard.SmartDashboard;
*/
public class RobotContainer {
// The robot's subsystems and commands are defined here...
private final Drivetrain m_drivetrain = new Drivetrain();
private final OnBoardIO m_onboardIO = new OnBoardIO(ChannelMode.INPUT, ChannelMode.INPUT);
private final Drivetrain drivetrain = new Drivetrain();
private final OnBoardIO onboardIO = new OnBoardIO(ChannelMode.INPUT, ChannelMode.INPUT);
// Assumes a gamepad plugged into channel 0
private final Joystick m_controller = new Joystick(0);
private final Joystick controller = new Joystick(0);
// Create SmartDashboard chooser for autonomous routines
private final SendableChooser<Command> m_chooser = new SendableChooser<>();
private final SendableChooser<Command> chooser = new SendableChooser<>();
// NOTE: The I/O pin functionality of the 5 exposed I/O pins depends on the hardware "overlay"
// that is specified when launching the wpilib-ws server on the Romi raspberry pi.
@@ -62,18 +62,18 @@ public class RobotContainer {
private void configureButtonBindings() {
// Default command is arcade drive. This will run unless another command
// is scheduled over it.
m_drivetrain.setDefaultCommand(getArcadeDriveCommand());
drivetrain.setDefaultCommand(getArcadeDriveCommand());
// Example of how to use the onboard IO
Trigger onboardButtonA = new Trigger(m_onboardIO::getButtonAPressed);
Trigger onboardButtonA = new Trigger(onboardIO::getButtonAPressed);
onboardButtonA
.onTrue(new PrintCommand("Button A Pressed"))
.onFalse(new PrintCommand("Button A Released"));
// Setup SmartDashboard options
m_chooser.setDefaultOption("Auto Routine Distance", new AutonomousDistance(m_drivetrain));
m_chooser.addOption("Auto Routine Time", new AutonomousTime(m_drivetrain));
SmartDashboard.putData(m_chooser);
chooser.setDefaultOption("Auto Routine Distance", new AutonomousDistance(drivetrain));
chooser.addOption("Auto Routine Time", new AutonomousTime(drivetrain));
SmartDashboard.putData(chooser);
}
/**
@@ -82,7 +82,7 @@ public class RobotContainer {
* @return the command to run in autonomous
*/
public Command getAutonomousCommand() {
return m_chooser.getSelected();
return chooser.getSelected();
}
/**
@@ -92,6 +92,6 @@ public class RobotContainer {
*/
public Command getArcadeDriveCommand() {
return new ArcadeDrive(
m_drivetrain, () -> -m_controller.getRawAxis(1), () -> -m_controller.getRawAxis(2));
drivetrain, () -> -controller.getRawAxis(1), () -> -controller.getRawAxis(2));
}
}

View File

@@ -9,9 +9,9 @@ import org.wpilib.command2.Command;
import org.wpilib.examples.romireference.subsystems.Drivetrain;
public class ArcadeDrive extends Command {
private final Drivetrain m_drivetrain;
private final Supplier<Double> m_xaxisVelocitySupplier;
private final Supplier<Double> m_zaxisRotateSupplier;
private final Drivetrain drivetrain;
private final Supplier<Double> xaxisVelocitySupplier;
private final Supplier<Double> zaxisRotateSupplier;
/**
* Creates a new ArcadeDrive. This command will drive your robot according to the velocity
@@ -25,9 +25,9 @@ public class ArcadeDrive extends Command {
Drivetrain drivetrain,
Supplier<Double> xaxisVelocitySupplier,
Supplier<Double> zaxisRotateSupplier) {
m_drivetrain = drivetrain;
m_xaxisVelocitySupplier = xaxisVelocitySupplier;
m_zaxisRotateSupplier = zaxisRotateSupplier;
this.drivetrain = drivetrain;
this.xaxisVelocitySupplier = xaxisVelocitySupplier;
this.zaxisRotateSupplier = zaxisRotateSupplier;
addRequirements(drivetrain);
}
@@ -38,7 +38,7 @@ public class ArcadeDrive extends Command {
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_drivetrain.arcadeDrive(m_xaxisVelocitySupplier.get(), m_zaxisRotateSupplier.get());
drivetrain.arcadeDrive(xaxisVelocitySupplier.get(), zaxisRotateSupplier.get());
}
// Called once the command ends or is interrupted.

View File

@@ -8,9 +8,9 @@ import org.wpilib.command2.Command;
import org.wpilib.examples.romireference.subsystems.Drivetrain;
public class DriveDistance extends Command {
private final Drivetrain m_drive;
private final double m_distance;
private final double m_velocity;
private final Drivetrain drive;
private final double distance;
private final double velocity;
/**
* Creates a new DriveDistance. This command will drive your your robot for a desired distance at
@@ -21,35 +21,35 @@ public class DriveDistance extends Command {
* @param drive The drivetrain subsystem on which this command will run
*/
public DriveDistance(double velocity, double inches, Drivetrain drive) {
m_distance = inches;
m_velocity = velocity;
m_drive = drive;
distance = inches;
this.velocity = velocity;
this.drive = drive;
addRequirements(drive);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
m_drive.arcadeDrive(0, 0);
m_drive.resetEncoders();
drive.arcadeDrive(0, 0);
drive.resetEncoders();
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_drive.arcadeDrive(m_velocity, 0);
drive.arcadeDrive(velocity, 0);
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
m_drive.arcadeDrive(0, 0);
drive.arcadeDrive(0, 0);
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
// Compare distance travelled from start to desired distance
return Math.abs(m_drive.getAverageDistanceInch()) >= m_distance;
return Math.abs(drive.getAverageDistanceInch()) >= distance;
}
}

View File

@@ -8,10 +8,10 @@ import org.wpilib.command2.Command;
import org.wpilib.examples.romireference.subsystems.Drivetrain;
public class DriveTime extends Command {
private final double m_duration;
private final double m_velocity;
private final Drivetrain m_drive;
private long m_startTime;
private final double duration;
private final double velocity;
private final Drivetrain drive;
private long startTime;
/**
* Creates a new DriveTime. This command will drive your robot for a desired velocity and time.
@@ -21,34 +21,34 @@ public class DriveTime extends Command {
* @param drive The drivetrain subsystem on which this command will run
*/
public DriveTime(double velocity, double time, Drivetrain drive) {
m_velocity = velocity;
m_duration = time * 1000;
m_drive = drive;
this.velocity = velocity;
duration = time * 1000;
this.drive = drive;
addRequirements(drive);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
m_startTime = System.currentTimeMillis();
m_drive.arcadeDrive(0, 0);
startTime = System.currentTimeMillis();
drive.arcadeDrive(0, 0);
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_drive.arcadeDrive(m_velocity, 0);
drive.arcadeDrive(velocity, 0);
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
m_drive.arcadeDrive(0, 0);
drive.arcadeDrive(0, 0);
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return (System.currentTimeMillis() - m_startTime) >= m_duration;
return (System.currentTimeMillis() - startTime) >= duration;
}
}

View File

@@ -8,9 +8,9 @@ import org.wpilib.command2.Command;
import org.wpilib.examples.romireference.subsystems.Drivetrain;
public class TurnDegrees extends Command {
private final Drivetrain m_drive;
private final double m_degrees;
private final double m_velocity;
private final Drivetrain drive;
private final double degrees;
private final double velocity;
/**
* Creates a new TurnDegrees. This command will turn your robot for a desired rotation (in
@@ -21,9 +21,9 @@ public class TurnDegrees extends Command {
* @param drive The drive subsystem on which this command will run
*/
public TurnDegrees(double velocity, double degrees, Drivetrain drive) {
m_degrees = degrees;
m_velocity = velocity;
m_drive = drive;
this.degrees = degrees;
this.velocity = velocity;
this.drive = drive;
addRequirements(drive);
}
@@ -31,20 +31,20 @@ public class TurnDegrees extends Command {
@Override
public void initialize() {
// Set motors to stop, read encoder values for starting point
m_drive.arcadeDrive(0, 0);
m_drive.resetEncoders();
drive.arcadeDrive(0, 0);
drive.resetEncoders();
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_drive.arcadeDrive(0, m_velocity);
drive.arcadeDrive(0, velocity);
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
m_drive.arcadeDrive(0, 0);
drive.arcadeDrive(0, 0);
}
// Returns true when the command should end.
@@ -57,12 +57,12 @@ public class TurnDegrees extends Command {
*/
double inchPerDegree = Math.PI * 5.551 / 360;
// Compare distance travelled from start to distance based on degree turn
return getAverageTurningDistance() >= (inchPerDegree * m_degrees);
return getAverageTurningDistance() >= (inchPerDegree * degrees);
}
private double getAverageTurningDistance() {
double leftDistance = Math.abs(m_drive.getLeftDistanceInch());
double rightDistance = Math.abs(m_drive.getRightDistanceInch());
double leftDistance = Math.abs(drive.getLeftDistanceInch());
double rightDistance = Math.abs(drive.getRightDistanceInch());
return (leftDistance + rightDistance) / 2.0;
}
}

View File

@@ -12,10 +12,10 @@ import org.wpilib.examples.romireference.subsystems.Drivetrain;
* desired rotational velocity and time.
*/
public class TurnTime extends Command {
private final double m_duration;
private final double m_rotationalVelocity;
private final Drivetrain m_drive;
private long m_startTime;
private final double duration;
private final double rotationalVelocity;
private final Drivetrain drive;
private long startTime;
/**
* Creates a new TurnTime.
@@ -25,34 +25,34 @@ public class TurnTime extends Command {
* @param drive The drive subsystem on which this command will run
*/
public TurnTime(double velocity, double time, Drivetrain drive) {
m_rotationalVelocity = velocity;
m_duration = time * 1000;
m_drive = drive;
rotationalVelocity = velocity;
duration = time * 1000;
this.drive = drive;
addRequirements(drive);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
m_startTime = System.currentTimeMillis();
m_drive.arcadeDrive(0, 0);
startTime = System.currentTimeMillis();
drive.arcadeDrive(0, 0);
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
m_drive.arcadeDrive(0, m_rotationalVelocity);
drive.arcadeDrive(0, rotationalVelocity);
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
m_drive.arcadeDrive(0, 0);
drive.arcadeDrive(0, 0);
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return (System.currentTimeMillis() - m_startTime) >= m_duration;
return (System.currentTimeMillis() - startTime) >= duration;
}
}

View File

@@ -17,60 +17,60 @@ public class Drivetrain extends SubsystemBase {
// The Romi has the left and right motors set to
// PWM channels 0 and 1 respectively
private final Spark m_leftMotor = new Spark(0);
private final Spark m_rightMotor = new Spark(1);
private final Spark leftMotor = new Spark(0);
private final Spark rightMotor = new Spark(1);
// The Romi has onboard encoders that are hardcoded
// to use DIO pins 4/5 and 6/7 for the left and right
private final Encoder m_leftEncoder = new Encoder(4, 5);
private final Encoder m_rightEncoder = new Encoder(6, 7);
private final Encoder leftEncoder = new Encoder(4, 5);
private final Encoder rightEncoder = new Encoder(6, 7);
// Set up the differential drive controller
private final DifferentialDrive m_diffDrive =
new DifferentialDrive(m_leftMotor::setThrottle, m_rightMotor::setThrottle);
private final DifferentialDrive diffDrive =
new DifferentialDrive(leftMotor::setThrottle, rightMotor::setThrottle);
// Set up the RomiGyro
private final RomiGyro m_gyro = new RomiGyro();
private final RomiGyro gyro = new RomiGyro();
/** Creates a new Drivetrain. */
public Drivetrain() {
SendableRegistry.addChild(m_diffDrive, m_leftMotor);
SendableRegistry.addChild(m_diffDrive, m_rightMotor);
SendableRegistry.addChild(diffDrive, leftMotor);
SendableRegistry.addChild(diffDrive, rightMotor);
// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead.
m_rightMotor.setInverted(true);
rightMotor.setInverted(true);
// Use inches as unit for encoder distances
m_leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution);
m_rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution);
leftEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution);
rightEncoder.setDistancePerPulse((Math.PI * kWheelDiameterInch) / kCountsPerRevolution);
resetEncoders();
}
public void arcadeDrive(double xaxisVelocity, double zaxisRotate) {
m_diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate);
diffDrive.arcadeDrive(xaxisVelocity, zaxisRotate);
}
public void resetEncoders() {
m_leftEncoder.reset();
m_rightEncoder.reset();
leftEncoder.reset();
rightEncoder.reset();
}
public int getLeftEncoderCount() {
return m_leftEncoder.get();
return leftEncoder.get();
}
public int getRightEncoderCount() {
return m_rightEncoder.get();
return rightEncoder.get();
}
public double getLeftDistanceInch() {
return m_leftEncoder.getDistance();
return leftEncoder.getDistance();
}
public double getRightDistanceInch() {
return m_rightEncoder.getDistance();
return rightEncoder.getDistance();
}
public double getAverageDistanceInch() {
@@ -83,7 +83,7 @@ public class Drivetrain extends SubsystemBase {
* @return The current angle of the Romi in degrees
*/
public double getGyroAngleX() {
return m_gyro.getAngleX();
return gyro.getAngleX();
}
/**
@@ -92,7 +92,7 @@ public class Drivetrain extends SubsystemBase {
* @return The current angle of the Romi in degrees
*/
public double getGyroAngleY() {
return m_gyro.getAngleY();
return gyro.getAngleY();
}
/**
@@ -101,12 +101,12 @@ public class Drivetrain extends SubsystemBase {
* @return The current angle of the Romi in degrees
*/
public double getGyroAngleZ() {
return m_gyro.getAngleZ();
return gyro.getAngleZ();
}
/** Reset the gyro. */
public void resetGyro() {
m_gyro.reset();
gyro.reset();
}
@Override