mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00: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:
@@ -18,29 +18,29 @@
|
||||
#include "wpi/util/Preferences.hpp"
|
||||
|
||||
class ArmSimulationTest : public testing::TestWithParam<wpi::units::degree_t> {
|
||||
Robot m_robot;
|
||||
std::optional<std::thread> m_thread;
|
||||
Robot robot;
|
||||
std::optional<std::thread> thread;
|
||||
|
||||
protected:
|
||||
wpi::sim::PWMMotorControllerSim m_motorSim{kMotorPort};
|
||||
wpi::sim::EncoderSim m_encoderSim =
|
||||
wpi::sim::PWMMotorControllerSim motorSim{kMotorPort};
|
||||
wpi::sim::EncoderSim encoderSim =
|
||||
wpi::sim::EncoderSim::CreateForChannel(kEncoderAChannel);
|
||||
wpi::sim::JoystickSim m_joystickSim{kJoystickPort};
|
||||
wpi::sim::JoystickSim joystickSim{kJoystickPort};
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
wpi::sim::PauseTiming();
|
||||
wpi::sim::SetProgramStarted(false);
|
||||
|
||||
m_thread = std::thread([&] { m_robot.StartCompetition(); });
|
||||
thread = std::thread([&] { robot.StartCompetition(); });
|
||||
wpi::sim::WaitForProgramStart();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
m_robot.EndCompetition();
|
||||
m_thread->join();
|
||||
robot.EndCompetition();
|
||||
thread->join();
|
||||
|
||||
m_encoderSim.ResetData();
|
||||
encoderSim.ResetData();
|
||||
wpi::sim::DriverStationSim::ResetData();
|
||||
wpi::Preferences::RemoveAll();
|
||||
}
|
||||
@@ -60,25 +60,25 @@ TEST_P(ArmSimulationTest, Teleop) {
|
||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(m_encoderSim.GetInitialized());
|
||||
EXPECT_TRUE(encoderSim.GetInitialized());
|
||||
}
|
||||
|
||||
{
|
||||
wpi::sim::StepTiming(3_s);
|
||||
|
||||
// Ensure arm is still at minimum angle.
|
||||
EXPECT_NEAR(kMinAngle.value(), m_encoderSim.GetDistance(), 2.0);
|
||||
EXPECT_NEAR(kMinAngle.value(), encoderSim.GetDistance(), 2.0);
|
||||
}
|
||||
|
||||
{
|
||||
// Press button to reach setpoint
|
||||
m_joystickSim.SetTrigger(true);
|
||||
m_joystickSim.NotifyNewData();
|
||||
joystickSim.SetTrigger(true);
|
||||
joystickSim.NotifyNewData();
|
||||
|
||||
wpi::sim::StepTiming(1.5_s);
|
||||
|
||||
EXPECT_NEAR(setpoint.value(),
|
||||
wpi::units::radian_t(m_encoderSim.GetDistance())
|
||||
wpi::units::radian_t(encoderSim.GetDistance())
|
||||
.convert<wpi::units::degree>()
|
||||
.value(),
|
||||
2.0);
|
||||
@@ -87,7 +87,7 @@ TEST_P(ArmSimulationTest, Teleop) {
|
||||
wpi::sim::StepTiming(0.5_s);
|
||||
|
||||
EXPECT_NEAR(setpoint.value(),
|
||||
wpi::units::radian_t(m_encoderSim.GetDistance())
|
||||
wpi::units::radian_t(encoderSim.GetDistance())
|
||||
.convert<wpi::units::degree>()
|
||||
.value(),
|
||||
2.0);
|
||||
@@ -95,24 +95,24 @@ TEST_P(ArmSimulationTest, Teleop) {
|
||||
|
||||
{
|
||||
// Unpress the button to go back down
|
||||
m_joystickSim.SetTrigger(false);
|
||||
m_joystickSim.NotifyNewData();
|
||||
joystickSim.SetTrigger(false);
|
||||
joystickSim.NotifyNewData();
|
||||
|
||||
wpi::sim::StepTiming(3_s);
|
||||
|
||||
EXPECT_NEAR(kMinAngle.value(), m_encoderSim.GetDistance(), 2.0);
|
||||
EXPECT_NEAR(kMinAngle.value(), encoderSim.GetDistance(), 2.0);
|
||||
}
|
||||
|
||||
{
|
||||
// Press button to go back up
|
||||
m_joystickSim.SetTrigger(true);
|
||||
m_joystickSim.NotifyNewData();
|
||||
joystickSim.SetTrigger(true);
|
||||
joystickSim.NotifyNewData();
|
||||
|
||||
// advance 75 timesteps
|
||||
wpi::sim::StepTiming(1.5_s);
|
||||
|
||||
EXPECT_NEAR(setpoint.value(),
|
||||
wpi::units::radian_t(m_encoderSim.GetDistance())
|
||||
wpi::units::radian_t(encoderSim.GetDistance())
|
||||
.convert<wpi::units::degree>()
|
||||
.value(),
|
||||
2.0);
|
||||
@@ -121,7 +121,7 @@ TEST_P(ArmSimulationTest, Teleop) {
|
||||
wpi::sim::StepTiming(0.5_s);
|
||||
|
||||
EXPECT_NEAR(setpoint.value(),
|
||||
wpi::units::radian_t(m_encoderSim.GetDistance())
|
||||
wpi::units::radian_t(encoderSim.GetDistance())
|
||||
.convert<wpi::units::degree>()
|
||||
.value(),
|
||||
2.0);
|
||||
@@ -134,8 +134,8 @@ TEST_P(ArmSimulationTest, Teleop) {
|
||||
|
||||
wpi::sim::StepTiming(3_s);
|
||||
|
||||
ASSERT_NEAR(0.0, m_motorSim.GetThrottle(), 0.05);
|
||||
EXPECT_NEAR(kMinAngle.value(), m_encoderSim.GetDistance(), 2.0);
|
||||
ASSERT_NEAR(0.0, motorSim.GetThrottle(), 0.05);
|
||||
EXPECT_NEAR(kMinAngle.value(), encoderSim.GetDistance(), 2.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,29 +22,29 @@
|
||||
using namespace Constants;
|
||||
|
||||
class ElevatorSimulationTest : public testing::Test {
|
||||
Robot m_robot;
|
||||
std::optional<std::thread> m_thread;
|
||||
Robot robot;
|
||||
std::optional<std::thread> thread;
|
||||
|
||||
protected:
|
||||
wpi::sim::PWMMotorControllerSim m_motorSim{Constants::kMotorPort};
|
||||
wpi::sim::EncoderSim m_encoderSim =
|
||||
wpi::sim::PWMMotorControllerSim motorSim{Constants::kMotorPort};
|
||||
wpi::sim::EncoderSim encoderSim =
|
||||
wpi::sim::EncoderSim::CreateForChannel(Constants::kEncoderAChannel);
|
||||
wpi::sim::JoystickSim m_joystickSim{Constants::kJoystickPort};
|
||||
wpi::sim::JoystickSim joystickSim{Constants::kJoystickPort};
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
wpi::sim::PauseTiming();
|
||||
wpi::sim::SetProgramStarted(false);
|
||||
|
||||
m_thread = std::thread([&] { m_robot.StartCompetition(); });
|
||||
thread = std::thread([&] { robot.StartCompetition(); });
|
||||
wpi::sim::WaitForProgramStart();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
m_robot.EndCompetition();
|
||||
m_thread->join();
|
||||
robot.EndCompetition();
|
||||
thread->join();
|
||||
|
||||
m_encoderSim.ResetData();
|
||||
encoderSim.ResetData();
|
||||
wpi::sim::DriverStationSim::ResetData();
|
||||
}
|
||||
};
|
||||
@@ -56,7 +56,7 @@ TEST_F(ElevatorSimulationTest, Teleop) {
|
||||
wpi::sim::DriverStationSim::SetEnabled(true);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(m_encoderSim.GetInitialized());
|
||||
EXPECT_TRUE(encoderSim.GetInitialized());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -64,50 +64,50 @@ TEST_F(ElevatorSimulationTest, Teleop) {
|
||||
wpi::sim::StepTiming(1_s);
|
||||
|
||||
// Ensure elevator is still at 0.
|
||||
EXPECT_NEAR(0.0, m_encoderSim.GetDistance(), 0.05);
|
||||
EXPECT_NEAR(0.0, encoderSim.GetDistance(), 0.05);
|
||||
}
|
||||
|
||||
{
|
||||
// Press button to reach setpoint
|
||||
m_joystickSim.SetTrigger(true);
|
||||
m_joystickSim.NotifyNewData();
|
||||
joystickSim.SetTrigger(true);
|
||||
joystickSim.NotifyNewData();
|
||||
|
||||
// advance 75 timesteps
|
||||
wpi::sim::StepTiming(1.5_s);
|
||||
|
||||
EXPECT_NEAR(kSetpoint.value(), m_encoderSim.GetDistance(), 0.05);
|
||||
EXPECT_NEAR(kSetpoint.value(), encoderSim.GetDistance(), 0.05);
|
||||
|
||||
// advance 25 timesteps to see setpoint is held.
|
||||
wpi::sim::StepTiming(0.5_s);
|
||||
|
||||
EXPECT_NEAR(kSetpoint.value(), m_encoderSim.GetDistance(), 0.05);
|
||||
EXPECT_NEAR(kSetpoint.value(), encoderSim.GetDistance(), 0.05);
|
||||
}
|
||||
|
||||
{
|
||||
// Unpress the button to go back down
|
||||
m_joystickSim.SetTrigger(false);
|
||||
m_joystickSim.NotifyNewData();
|
||||
joystickSim.SetTrigger(false);
|
||||
joystickSim.NotifyNewData();
|
||||
|
||||
// advance 75 timesteps
|
||||
wpi::sim::StepTiming(1.5_s);
|
||||
|
||||
EXPECT_NEAR(0.0, m_encoderSim.GetDistance(), 0.05);
|
||||
EXPECT_NEAR(0.0, encoderSim.GetDistance(), 0.05);
|
||||
}
|
||||
|
||||
{
|
||||
// Press button to go back up
|
||||
m_joystickSim.SetTrigger(true);
|
||||
m_joystickSim.NotifyNewData();
|
||||
joystickSim.SetTrigger(true);
|
||||
joystickSim.NotifyNewData();
|
||||
|
||||
// advance 75 timesteps
|
||||
wpi::sim::StepTiming(1.5_s);
|
||||
|
||||
EXPECT_NEAR(kSetpoint.value(), m_encoderSim.GetDistance(), 0.05);
|
||||
EXPECT_NEAR(kSetpoint.value(), encoderSim.GetDistance(), 0.05);
|
||||
|
||||
// advance 25 timesteps to see setpoint is held.
|
||||
wpi::sim::StepTiming(0.5_s);
|
||||
|
||||
EXPECT_NEAR(kSetpoint.value(), m_encoderSim.GetDistance(), 0.05);
|
||||
EXPECT_NEAR(kSetpoint.value(), encoderSim.GetDistance(), 0.05);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -118,7 +118,7 @@ TEST_F(ElevatorSimulationTest, Teleop) {
|
||||
// advance 75 timesteps
|
||||
wpi::sim::StepTiming(1.5_s);
|
||||
|
||||
ASSERT_NEAR(0.0, m_motorSim.GetThrottle(), 0.05);
|
||||
ASSERT_NEAR(0.0, m_encoderSim.GetDistance(), 0.05);
|
||||
ASSERT_NEAR(0.0, motorSim.GetThrottle(), 0.05);
|
||||
ASSERT_NEAR(0.0, encoderSim.GetDistance(), 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,29 +17,29 @@
|
||||
template <typename T>
|
||||
class DigitalCommunicationTest : public testing::TestWithParam<T> {
|
||||
public:
|
||||
wpi::sim::DIOSim m_allianceOutput{Robot::kAlliancePort};
|
||||
wpi::sim::DIOSim m_enabledOutput{Robot::kEnabledPort};
|
||||
wpi::sim::DIOSim m_autonomousOutput{Robot::kAutonomousPort};
|
||||
wpi::sim::DIOSim m_alertOutput{Robot::kAlertPort};
|
||||
Robot m_robot;
|
||||
std::optional<std::thread> m_thread;
|
||||
wpi::sim::DIOSim allianceOutput{Robot::kAlliancePort};
|
||||
wpi::sim::DIOSim enabledOutput{Robot::kEnabledPort};
|
||||
wpi::sim::DIOSim autonomousOutput{Robot::kAutonomousPort};
|
||||
wpi::sim::DIOSim alertOutput{Robot::kAlertPort};
|
||||
Robot robot;
|
||||
std::optional<std::thread> thread;
|
||||
|
||||
void SetUp() override {
|
||||
wpi::sim::PauseTiming();
|
||||
wpi::sim::SetProgramStarted(false);
|
||||
wpi::sim::DriverStationSim::ResetData();
|
||||
|
||||
m_thread = std::thread([&] { m_robot.StartCompetition(); });
|
||||
thread = std::thread([&] { robot.StartCompetition(); });
|
||||
wpi::sim::WaitForProgramStart();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
m_robot.EndCompetition();
|
||||
m_thread->join();
|
||||
m_allianceOutput.ResetData();
|
||||
m_enabledOutput.ResetData();
|
||||
m_autonomousOutput.ResetData();
|
||||
m_alertOutput.ResetData();
|
||||
robot.EndCompetition();
|
||||
thread->join();
|
||||
allianceOutput.ResetData();
|
||||
enabledOutput.ResetData();
|
||||
autonomousOutput.ResetData();
|
||||
alertOutput.ResetData();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,8 +50,8 @@ TEST_P(AllianceTest, Alliance) {
|
||||
wpi::sim::DriverStationSim::SetAllianceStationId(alliance);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(m_allianceOutput.GetInitialized());
|
||||
EXPECT_FALSE(m_allianceOutput.GetIsInput());
|
||||
EXPECT_TRUE(allianceOutput.GetInitialized());
|
||||
EXPECT_FALSE(allianceOutput.GetIsInput());
|
||||
|
||||
wpi::sim::StepTiming(20_ms);
|
||||
|
||||
@@ -69,7 +69,7 @@ TEST_P(AllianceTest, Alliance) {
|
||||
isRed = true;
|
||||
break;
|
||||
}
|
||||
EXPECT_EQ(isRed, m_allianceOutput.GetValue());
|
||||
EXPECT_EQ(isRed, allianceOutput.GetValue());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
@@ -106,12 +106,12 @@ TEST_P(EnabledTest, Enabled) {
|
||||
wpi::sim::DriverStationSim::SetEnabled(enabled);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(m_enabledOutput.GetInitialized());
|
||||
EXPECT_FALSE(m_enabledOutput.GetIsInput());
|
||||
EXPECT_TRUE(enabledOutput.GetInitialized());
|
||||
EXPECT_FALSE(enabledOutput.GetIsInput());
|
||||
|
||||
wpi::sim::StepTiming(20_ms);
|
||||
|
||||
EXPECT_EQ(enabled, m_enabledOutput.GetValue());
|
||||
EXPECT_EQ(enabled, enabledOutput.GetValue());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(DigitalCommunicationTests, EnabledTest,
|
||||
@@ -125,12 +125,12 @@ TEST_P(AutonomousTest, Autonomous) {
|
||||
autonomous ? HAL_ROBOT_MODE_AUTONOMOUS : HAL_ROBOT_MODE_TELEOPERATED);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(m_autonomousOutput.GetInitialized());
|
||||
EXPECT_FALSE(m_autonomousOutput.GetIsInput());
|
||||
EXPECT_TRUE(autonomousOutput.GetInitialized());
|
||||
EXPECT_FALSE(autonomousOutput.GetIsInput());
|
||||
|
||||
wpi::sim::StepTiming(20_ms);
|
||||
|
||||
EXPECT_EQ(autonomous, m_autonomousOutput.GetValue());
|
||||
EXPECT_EQ(autonomous, autonomousOutput.GetValue());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(DigitalCommunicationTests, AutonomousTest,
|
||||
@@ -143,12 +143,12 @@ TEST_P(AlertTest, Alert) {
|
||||
wpi::sim::DriverStationSim::SetMatchTime(matchTime);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(m_alertOutput.GetInitialized());
|
||||
EXPECT_FALSE(m_alertOutput.GetIsInput());
|
||||
EXPECT_TRUE(alertOutput.GetInitialized());
|
||||
EXPECT_FALSE(alertOutput.GetIsInput());
|
||||
|
||||
wpi::sim::StepTiming(20_ms);
|
||||
|
||||
EXPECT_EQ(matchTime <= 30 && matchTime >= 25, m_alertOutput.GetValue());
|
||||
EXPECT_EQ(matchTime <= 30 && matchTime >= 25, alertOutput.GetValue());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
|
||||
@@ -25,30 +25,30 @@ void callback(const char* name, void* param, const unsigned char* buffer,
|
||||
template <typename T>
|
||||
class I2CCommunicationTest : public testing::TestWithParam<T> {
|
||||
public:
|
||||
Robot m_robot;
|
||||
std::optional<std::thread> m_thread;
|
||||
int32_t m_callback;
|
||||
int32_t m_port;
|
||||
Robot robot;
|
||||
std::optional<std::thread> thread;
|
||||
int32_t callbackHandle;
|
||||
int32_t port;
|
||||
|
||||
void SetUp() override {
|
||||
gString = std::string();
|
||||
wpi::sim::PauseTiming();
|
||||
wpi::sim::SetProgramStarted(false);
|
||||
wpi::sim::DriverStationSim::ResetData();
|
||||
m_port = static_cast<int32_t>(Robot::kPort);
|
||||
port = static_cast<int32_t>(Robot::kPort);
|
||||
|
||||
m_callback = HALSIM_RegisterI2CWriteCallback(m_port, &callback, nullptr);
|
||||
callbackHandle = HALSIM_RegisterI2CWriteCallback(port, &callback, nullptr);
|
||||
|
||||
m_thread = std::thread([&] { m_robot.StartCompetition(); });
|
||||
thread = std::thread([&] { robot.StartCompetition(); });
|
||||
wpi::sim::WaitForProgramStart();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
m_robot.EndCompetition();
|
||||
m_thread->join();
|
||||
robot.EndCompetition();
|
||||
thread->join();
|
||||
|
||||
HALSIM_CancelI2CWriteCallback(m_port, m_callback);
|
||||
HALSIM_ResetI2CData(m_port);
|
||||
HALSIM_CancelI2CWriteCallback(port, callbackHandle);
|
||||
HALSIM_ResetI2CData(port);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ TEST_P(AllianceTest, Alliance) {
|
||||
wpi::sim::DriverStationSim::SetAllianceStationId(alliance);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port));
|
||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(port));
|
||||
|
||||
wpi::sim::StepTiming(20_ms);
|
||||
|
||||
@@ -116,7 +116,7 @@ TEST_P(EnabledTest, Enabled) {
|
||||
wpi::sim::DriverStationSim::SetEnabled(enabled);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port));
|
||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(port));
|
||||
|
||||
wpi::sim::StepTiming(20_ms);
|
||||
|
||||
@@ -135,7 +135,7 @@ TEST_P(AutonomousTest, Autonomous) {
|
||||
autonomous ? HAL_ROBOT_MODE_AUTONOMOUS : HAL_ROBOT_MODE_TELEOPERATED);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port));
|
||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(port));
|
||||
|
||||
wpi::sim::StepTiming(20_ms);
|
||||
|
||||
@@ -153,7 +153,7 @@ TEST_P(MatchTimeTest, Alert) {
|
||||
wpi::sim::DriverStationSim::SetMatchTime(matchTime);
|
||||
wpi::sim::DriverStationSim::NotifyNewData();
|
||||
|
||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(m_port));
|
||||
EXPECT_TRUE(HALSIM_GetI2CInitialized(port));
|
||||
|
||||
wpi::sim::StepTiming(20_ms);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user