diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/CloseClaw.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/CloseClaw.cpp index 0b6b8b0055..a3c1469f9a 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/CloseClaw.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/commands/CloseClaw.cpp @@ -4,6 +4,8 @@ #include "commands/CloseClaw.h" +#include + #include "Robot.h" CloseClaw::CloseClaw(Claw& claw) : m_claw(&claw) { @@ -23,10 +25,10 @@ bool CloseClaw::IsFinished() { // Called once after isFinished returns true void CloseClaw::End(bool) { -// NOTE: Doesn't stop in simulation due to lower friction causing the can to -// fall out -// + there is no need to worry about stalling the motor or crushing the can. -#ifndef SIMULATION - m_claw->Stop(); -#endif + // NOTE: Doesn't stop in simulation due to lower friction causing the can to + // fall out + there is no need to worry about stalling the motor or crushing + // the can. + if constexpr (frc::RobotBase::IsSimulation()) { + m_claw->Stop(); + } } diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp index 2928036afc..e6109bf61a 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Drivetrain.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -22,21 +23,20 @@ Drivetrain::Drivetrain() { // gearbox is constructed, you might have to invert the left side instead. m_frontRight.SetInverted(true); -// Encoders may measure differently in the real world and in -// simulation. In this example the robot moves 0.042 barleycorns -// per tick in the real world, but the simulated encoders -// simulate 360 tick encoders. This if statement allows for the -// real robot to handle this difference in devices. -#ifndef SIMULATION - m_leftEncoder.SetDistancePerPulse(0.042); - m_rightEncoder.SetDistancePerPulse(0.042); -#else - // Circumference = diameter * pi. 360 tick simulated encoders. - m_leftEncoder.SetDistancePerPulse(units::foot_t{4_in}.value() * - std::numbers::pi / 360.0); - m_rightEncoder.SetDistancePerPulse(units::foot_t{4_in}.value() * - std::numbers::pi / 360.0); -#endif + // Encoders may measure differently in the real world and in simulation. In + // this example the robot moves 0.042 barleycorns per tick in the real world, + // but the simulated encoders simulate 360 tick encoders. This if statement + // allows for the real robot to handle this difference in devices. + if constexpr (frc::RobotBase::IsSimulation()) { + m_leftEncoder.SetDistancePerPulse(0.042); + m_rightEncoder.SetDistancePerPulse(0.042); + } else { + // Circumference = diameter * pi. 360 tick simulated encoders. + m_leftEncoder.SetDistancePerPulse(units::foot_t{4_in}.value() * + std::numbers::pi / 360.0); + m_rightEncoder.SetDistancePerPulse(units::foot_t{4_in}.value() * + std::numbers::pi / 360.0); + } SetName("Drivetrain"); // Let's show everything on the LiveWindow AddChild("Front_Left Motor", &m_frontLeft); diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp index 03db3142f2..d8c88d641d 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp @@ -10,9 +10,11 @@ Elevator::Elevator() : frc2::PIDSubsystem{frc::PIDController{kP_real, kI_real, 0}} { -#ifdef SIMULATION // Check for simulation and update PID values - GetPIDController()->SetPID(kP_simulation, kI_simulation, 0, 0); -#endif + if constexpr (frc::RobotBase::IsSimulation()) { + // Check for simulation and update PID values + GetController().SetPID(kP_simulation, kI_simulation, 0); + } + m_controller.SetTolerance(0.005); SetName("Elevator"); diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h index 055680d9dc..a4c2c7dce4 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -44,14 +45,12 @@ class Elevator : public frc2::PIDSubsystem { private: frc::PWMSparkMax m_motor{5}; - -// Conversion value of potentiometer varies between the real world and -// simulation -#ifndef SIMULATION - frc::AnalogPotentiometer m_pot{2, -2.0 / 5}; -#else - frc::AnalogPotentiometer m_pot{2}; // Defaults to meters -#endif + // Conversion value of potentiometer varies between the real world and + // simulation + frc::AnalogPotentiometer m_pot = + frc::RobotBase::IsReal() + ? frc::AnalogPotentiometer{2, -2.0 / 5} + : frc::AnalogPotentiometer{2}; // Defaults to meters static constexpr double kP_real = 4; static constexpr double kI_real = 0.07; diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h index 7b99f175d0..2222d5e44a 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -41,14 +42,12 @@ class Wrist : public frc2::PIDSubsystem { private: frc::PWMSparkMax m_motor{6}; - -// Conversion value of potentiometer varies between the real world and -// simulation -#ifndef SIMULATION - frc::AnalogPotentiometer m_pot{3, -270.0 / 5}; -#else - frc::AnalogPotentiometer m_pot{3}; // Defaults to degrees -#endif + // Conversion value of potentiometer varies between the real world and + // simulation + frc::AnalogPotentiometer m_pot = + frc::RobotBase::IsReal() + ? frc::AnalogPotentiometer{3, -270.0 / 5} + : frc::AnalogPotentiometer{3}; // Defaults to degrees static constexpr double kP = 1; };