mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
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:
@@ -34,11 +34,11 @@ void Robot::DisabledPeriodic() {}
|
||||
* RobotContainer} class.
|
||||
*/
|
||||
void Robot::AutonomousInit() {
|
||||
m_autonomousCommand = m_container.GetAutonomousCommand();
|
||||
autonomousCommand = container.GetAutonomousCommand();
|
||||
|
||||
if (m_autonomousCommand) {
|
||||
if (autonomousCommand) {
|
||||
wpi::cmd::CommandScheduler::GetInstance().Schedule(
|
||||
m_autonomousCommand.value());
|
||||
autonomousCommand.value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ void Robot::TeleopInit() {
|
||||
// teleop starts running. If you want the autonomous to
|
||||
// continue until interrupted by another command, remove
|
||||
// this line or comment it out.
|
||||
if (m_autonomousCommand) {
|
||||
m_autonomousCommand->Cancel();
|
||||
if (autonomousCommand) {
|
||||
autonomousCommand->Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,15 @@ void RobotContainer::ConfigureBindings() {
|
||||
|
||||
// Schedule `ExampleCommand` when `exampleCondition` changes to `true`
|
||||
wpi::cmd::Trigger([this] {
|
||||
return m_subsystem.ExampleCondition();
|
||||
}).OnTrue(ExampleCommand(&m_subsystem).ToPtr());
|
||||
return subsystem.ExampleCondition();
|
||||
}).OnTrue(ExampleCommand(&subsystem).ToPtr());
|
||||
|
||||
// Schedule `ExampleMethodCommand` when the Gamepad's East Face button is
|
||||
// pressed, cancelling on release.
|
||||
m_driverController.EastFace().WhileTrue(m_subsystem.ExampleMethodCommand());
|
||||
driverController.EastFace().WhileTrue(subsystem.ExampleMethodCommand());
|
||||
}
|
||||
|
||||
wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() {
|
||||
// An example command will be run in autonomous
|
||||
return autos::ExampleAuto(&m_subsystem);
|
||||
return autos::ExampleAuto(&subsystem);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "commands/ExampleCommand.hpp"
|
||||
|
||||
ExampleCommand::ExampleCommand(ExampleSubsystem* subsystem)
|
||||
: m_subsystem{subsystem} {
|
||||
: subsystem{subsystem} {
|
||||
// Register that this command requires the subsystem.
|
||||
AddRequirements(m_subsystem);
|
||||
AddRequirements(this->subsystem);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class Robot : public wpi::TimedRobot {
|
||||
private:
|
||||
// Have it empty by default so that if testing teleop it
|
||||
// doesn't have undefined behavior and potentially crash.
|
||||
std::optional<wpi::cmd::CommandPtr> m_autonomousCommand;
|
||||
std::optional<wpi::cmd::CommandPtr> autonomousCommand;
|
||||
|
||||
RobotContainer m_container;
|
||||
RobotContainer container;
|
||||
};
|
||||
|
||||
@@ -24,11 +24,11 @@ class RobotContainer {
|
||||
|
||||
private:
|
||||
// Replace with CommandPS4Controller or CommandJoystick if needed
|
||||
wpi::cmd::CommandGamepad m_driverController{
|
||||
wpi::cmd::CommandGamepad driverController{
|
||||
OperatorConstants::kDriverControllerPort};
|
||||
|
||||
// The robot's subsystems are defined here...
|
||||
ExampleSubsystem m_subsystem;
|
||||
ExampleSubsystem subsystem;
|
||||
|
||||
void ConfigureBindings();
|
||||
};
|
||||
|
||||
@@ -26,5 +26,5 @@ class ExampleCommand
|
||||
explicit ExampleCommand(ExampleSubsystem* subsystem);
|
||||
|
||||
private:
|
||||
ExampleSubsystem* m_subsystem;
|
||||
ExampleSubsystem* subsystem;
|
||||
};
|
||||
|
||||
@@ -19,11 +19,11 @@ void Robot::DisabledPeriodic() {}
|
||||
void Robot::DisabledExit() {}
|
||||
|
||||
void Robot::AutonomousInit() {
|
||||
m_autonomousCommand = m_container.GetAutonomousCommand();
|
||||
autonomousCommand = container.GetAutonomousCommand();
|
||||
|
||||
if (m_autonomousCommand) {
|
||||
if (autonomousCommand) {
|
||||
wpi::cmd::CommandScheduler::GetInstance().Schedule(
|
||||
m_autonomousCommand.value());
|
||||
autonomousCommand.value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ void Robot::AutonomousPeriodic() {}
|
||||
void Robot::AutonomousExit() {}
|
||||
|
||||
void Robot::TeleopInit() {
|
||||
if (m_autonomousCommand) {
|
||||
m_autonomousCommand->Cancel();
|
||||
if (autonomousCommand) {
|
||||
autonomousCommand->Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class Robot : public wpi::TimedRobot {
|
||||
void UtilityExit() override;
|
||||
|
||||
private:
|
||||
std::optional<wpi::cmd::CommandPtr> m_autonomousCommand;
|
||||
std::optional<wpi::cmd::CommandPtr> autonomousCommand;
|
||||
|
||||
RobotContainer m_container;
|
||||
RobotContainer container;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "Robot.hpp"
|
||||
|
||||
/** The Robot instance is passed into the opmode via the constructor. */
|
||||
MyAuto::MyAuto(Robot& robot) : m_robot{robot} {
|
||||
MyAuto::MyAuto(Robot& robot) : robot{robot} {
|
||||
/*
|
||||
* Can call the base class constructor with the period to set a different
|
||||
* periodic time interval.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "Robot.hpp"
|
||||
|
||||
/** The Robot instance is passed into the opmode via the constructor. */
|
||||
MyTeleop::MyTeleop(Robot& robot) : m_robot{robot} {}
|
||||
MyTeleop::MyTeleop(Robot& robot) : robot{robot} {}
|
||||
|
||||
MyTeleop::~MyTeleop() {
|
||||
/* Called when the opmode is de-selected. */
|
||||
|
||||
@@ -19,5 +19,5 @@ class MyAuto : public wpi::PeriodicOpMode {
|
||||
|
||||
private:
|
||||
[[maybe_unused]]
|
||||
Robot& m_robot;
|
||||
Robot& robot;
|
||||
};
|
||||
|
||||
@@ -19,5 +19,5 @@ class MyTeleop : public wpi::PeriodicOpMode {
|
||||
|
||||
private:
|
||||
[[maybe_unused]]
|
||||
Robot& m_robot;
|
||||
Robot& robot;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ void Robot::StartCompetition() {
|
||||
// Tell the DS that the robot is ready to be enabled
|
||||
wpi::internal::DriverStationBackend::ObserveUserProgramStarting();
|
||||
|
||||
while (!m_exit) {
|
||||
while (!exit) {
|
||||
modeThread.InControl(wpi::internal::DriverStationBackend::GetControlWord());
|
||||
if (IsDisabled()) {
|
||||
Disabled();
|
||||
@@ -62,7 +62,7 @@ void Robot::StartCompetition() {
|
||||
}
|
||||
|
||||
void Robot::EndCompetition() {
|
||||
m_exit = true;
|
||||
exit = true;
|
||||
}
|
||||
|
||||
#ifndef RUNNING_WPILIB_TESTS
|
||||
|
||||
@@ -20,5 +20,5 @@ class Robot : public wpi::RobotBase {
|
||||
void EndCompetition() override;
|
||||
|
||||
private:
|
||||
std::atomic<bool> m_exit{false};
|
||||
std::atomic<bool> exit{false};
|
||||
};
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#include "wpi/util/print.hpp"
|
||||
|
||||
Robot::Robot() {
|
||||
m_chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault);
|
||||
m_chooser.AddOption(kAutoNameCustom, kAutoNameCustom);
|
||||
wpi::SmartDashboard::PutData("Auto Modes", &m_chooser);
|
||||
chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault);
|
||||
chooser.AddOption(kAutoNameCustom, kAutoNameCustom);
|
||||
wpi::SmartDashboard::PutData("Auto Modes", &chooser);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,12 +35,12 @@ void Robot::RobotPeriodic() {}
|
||||
* make sure to add them to the chooser code above as well.
|
||||
*/
|
||||
void Robot::AutonomousInit() {
|
||||
m_autoSelected = m_chooser.GetSelected();
|
||||
// m_autoSelected = SmartDashboard::GetString("Auto Selector",
|
||||
autoSelected = chooser.GetSelected();
|
||||
// autoSelected = SmartDashboard::GetString("Auto Selector",
|
||||
// kAutoNameDefault);
|
||||
wpi::util::print("Auto selected: {}\n", m_autoSelected);
|
||||
wpi::util::print("Auto selected: {}\n", autoSelected);
|
||||
|
||||
if (m_autoSelected == kAutoNameCustom) {
|
||||
if (autoSelected == kAutoNameCustom) {
|
||||
// Custom Auto goes here
|
||||
} else {
|
||||
// Default Auto goes here
|
||||
@@ -48,7 +48,7 @@ void Robot::AutonomousInit() {
|
||||
}
|
||||
|
||||
void Robot::AutonomousPeriodic() {
|
||||
if (m_autoSelected == kAutoNameCustom) {
|
||||
if (autoSelected == kAutoNameCustom) {
|
||||
// Custom Auto goes here
|
||||
} else {
|
||||
// Default Auto goes here
|
||||
|
||||
@@ -25,8 +25,8 @@ class Robot : public wpi::TimedRobot {
|
||||
void SimulationPeriodic() override;
|
||||
|
||||
private:
|
||||
wpi::SendableChooser<std::string> m_chooser;
|
||||
wpi::SendableChooser<std::string> chooser;
|
||||
const std::string kAutoNameDefault = "Default";
|
||||
const std::string kAutoNameCustom = "My Auto";
|
||||
std::string m_autoSelected;
|
||||
std::string autoSelected;
|
||||
};
|
||||
|
||||
@@ -19,9 +19,9 @@ Robot::Robot() : wpi::TimesliceRobot{5_ms, 10_ms} {
|
||||
// 5 ms (robot) + 2 ms (controller 1) + 2 ms (controller 2) = 9 ms
|
||||
// 9 ms / 10 ms -> 90% allocated
|
||||
|
||||
m_chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault);
|
||||
m_chooser.AddOption(kAutoNameCustom, kAutoNameCustom);
|
||||
wpi::SmartDashboard::PutData("Auto Modes", &m_chooser);
|
||||
chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault);
|
||||
chooser.AddOption(kAutoNameCustom, kAutoNameCustom);
|
||||
wpi::SmartDashboard::PutData("Auto Modes", &chooser);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,12 +46,12 @@ void Robot::RobotPeriodic() {}
|
||||
* make sure to add them to the chooser code above as well.
|
||||
*/
|
||||
void Robot::AutonomousInit() {
|
||||
m_autoSelected = m_chooser.GetSelected();
|
||||
// m_autoSelected = SmartDashboard::GetString("Auto Selector",
|
||||
autoSelected = chooser.GetSelected();
|
||||
// autoSelected = SmartDashboard::GetString("Auto Selector",
|
||||
// kAutoNameDefault);
|
||||
wpi::util::print("Auto selected: {}\n", m_autoSelected);
|
||||
wpi::util::print("Auto selected: {}\n", autoSelected);
|
||||
|
||||
if (m_autoSelected == kAutoNameCustom) {
|
||||
if (autoSelected == kAutoNameCustom) {
|
||||
// Custom Auto goes here
|
||||
} else {
|
||||
// Default Auto goes here
|
||||
@@ -59,7 +59,7 @@ void Robot::AutonomousInit() {
|
||||
}
|
||||
|
||||
void Robot::AutonomousPeriodic() {
|
||||
if (m_autoSelected == kAutoNameCustom) {
|
||||
if (autoSelected == kAutoNameCustom) {
|
||||
// Custom Auto goes here
|
||||
} else {
|
||||
// Default Auto goes here
|
||||
|
||||
@@ -23,8 +23,8 @@ class Robot : public wpi::TimesliceRobot {
|
||||
void UtilityPeriodic() override;
|
||||
|
||||
private:
|
||||
wpi::SendableChooser<std::string> m_chooser;
|
||||
wpi::SendableChooser<std::string> chooser;
|
||||
const std::string kAutoNameDefault = "Default";
|
||||
const std::string kAutoNameCustom = "My Auto";
|
||||
std::string m_autoSelected;
|
||||
std::string autoSelected;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user