From 5f5f808bc09b24891ab052386d8c0d1a938d9b8d Mon Sep 17 00:00:00 2001 From: Benjamin Hall Date: Wed, 30 Oct 2024 20:09:02 -0400 Subject: [PATCH] Clean up C++ changes --- cpp/ArcadeDrive/src/main/cpp/Robot.cpp | 7 ---- .../main/cpp/subsystems/DriveSubsystem.cpp | 42 +++++++------------ cpp/CurrentLimits/src/main/cpp/Robot.cpp | 6 +-- .../src/main/cpp/sim/SimProfile.cpp | 8 ++-- .../src/main/include/sim/SimProfile.h | 2 +- .../src/main/java/frc/robot/Robot.java | 6 --- .../frc/robot/subsystems/DriveSubsystem.java | 6 --- 7 files changed, 24 insertions(+), 53 deletions(-) diff --git a/cpp/ArcadeDrive/src/main/cpp/Robot.cpp b/cpp/ArcadeDrive/src/main/cpp/Robot.cpp index 2b3feb38..03b6ab52 100644 --- a/cpp/ArcadeDrive/src/main/cpp/Robot.cpp +++ b/cpp/ArcadeDrive/src/main/cpp/Robot.cpp @@ -20,13 +20,6 @@ void Robot::RobotInit() { leftFollower.GetConfigurator().Apply(leftConfiguration); rightLeader.GetConfigurator().Apply(rightConfiguration); rightFollower.GetConfigurator().Apply(rightConfiguration); - - /* Currently in simulation, we do not support FOC, so disable it while simulating */ - if (utils::IsSimulation()) - { - leftOut.EnableFOC = false; - rightOut.EnableFOC = false; - } /* Set up followers to follow leaders */ leftFollower.SetControl(controls::Follower{leftLeader.GetDeviceID(), false}); diff --git a/cpp/CommandBasedDrive/src/main/cpp/subsystems/DriveSubsystem.cpp b/cpp/CommandBasedDrive/src/main/cpp/subsystems/DriveSubsystem.cpp index 034d3284..303a7c12 100644 --- a/cpp/CommandBasedDrive/src/main/cpp/subsystems/DriveSubsystem.cpp +++ b/cpp/CommandBasedDrive/src/main/cpp/subsystems/DriveSubsystem.cpp @@ -32,12 +32,6 @@ DriveSubsystem::DriveSubsystem() /* Set the update frequency of the main requests to 0 so updates are sent immediately in the arcadeDrive method */ m_leftOut.UpdateFreqHz = 0_Hz; m_rightOut.UpdateFreqHz = 0_Hz; - - /* Currently in simulation, we do not support FOC, so disable it while simulating */ - if (utils::IsSimulation()) { - m_leftOut.EnableFOC = false; - m_rightOut.EnableFOC = false; - } /* * Set the orientation of the simulated TalonFX devices relative to the robot chassis. @@ -170,44 +164,40 @@ void DriveSubsystem::SimulationPeriodic() units::meter_t DriveSubsystem::rotationsToMeters(units::turn_t rotations) { - /* Get circumference of wheel */ - constexpr auto circumference = kWheelRadiusInches / 1_rad; - /* Every rotation of the wheel travels this many inches */ + /* Every radian of rotation, the wheel travels this many inches */ + constexpr auto wheelDistancePerRad = kWheelRadiusInches / 1_rad; /* Now apply gear ratio to input rotations */ auto gearedRotations = rotations / kGearRatio; /* And multiply geared rotations by meters per rotation */ - return gearedRotations * circumference; + return gearedRotations * wheelDistancePerRad; } units::turn_t DriveSubsystem::metersToRotations(units::meter_t meters) { - /* Get circumference of wheel */ - constexpr auto circumference = kWheelRadiusInches / 1_rad; - /* Every rotation of the wheel travels this many inches */ - /* Now apply wheel rotations to input meters */ - auto wheelRotations = meters / circumference; + /* Every radian of rotation, the wheel travels this many inches */ + constexpr auto wheelDistancePerRad = kWheelRadiusInches / 1_rad; + /* Now get wheel rotations from input meters */ + auto wheelRadians = meters / wheelDistancePerRad; /* And multiply by gear ratio to get rotor rotations */ - return wheelRotations * kGearRatio; + return wheelRadians * kGearRatio; } units::meters_per_second_t DriveSubsystem::rotationsToMetersVel(units::turns_per_second_t rotations) { - /* Get circumference of wheel */ - constexpr auto circumference = kWheelRadiusInches / 1_rad; - /* Every rotation of the wheel travels this many inches */ + /* Every radian of rotation, the wheel travels this many inches */ + constexpr auto wheelDistancePerRad = kWheelRadiusInches / 1_rad; /* Now apply gear ratio to input rotations */ auto gearedRotations = rotations / kGearRatio; /* And multiply geared rotations by meters per rotation */ - return gearedRotations * circumference; + return gearedRotations * wheelDistancePerRad; } units::turns_per_second_t DriveSubsystem::metersToRotationsVel(units::meters_per_second_t meters) { - /* Get circumference of wheel */ - constexpr auto circumference = kWheelRadiusInches / 1_rad; - /* Every rotation of the wheel travels this many inches */ - /* Now apply wheel rotations to input meters */ - auto wheelRotations = meters / circumference; + /* Every radian of rotation, the wheel travels this many inches */ + constexpr auto wheelDistancePerRad = kWheelRadiusInches / 1_rad; + /* Now get wheel rotations from input meters */ + auto wheelRadians = meters / wheelDistancePerRad; /* And multiply by gear ratio to get rotor rotations */ - return wheelRotations * kGearRatio; + return wheelRadians * kGearRatio; } diff --git a/cpp/CurrentLimits/src/main/cpp/Robot.cpp b/cpp/CurrentLimits/src/main/cpp/Robot.cpp index 79dc3984..6a9c106d 100644 --- a/cpp/CurrentLimits/src/main/cpp/Robot.cpp +++ b/cpp/CurrentLimits/src/main/cpp/Robot.cpp @@ -10,9 +10,9 @@ using namespace ctre::phoenix6; void Robot::RobotInit() { /* Configure the Talon to use a supply limit of 60 amps IF we exceed 80 amps for over 0.1 seconds */ configs::TalonFXConfiguration toConfigure{}; - m_currentLimits.SupplyCurrentLimit = 80_A; // Default limit of 80 A - m_currentLimits.SupplyCurrentLowerLimit = 40_A; // This is the limit if we've exceeded 80 A for more than 1 second - m_currentLimits.SupplyCurrentLowerTime = 1_s; // Threshold before activating lower limit + m_currentLimits.SupplyCurrentLimit = 70_A; // Default limit of 70 A + m_currentLimits.SupplyCurrentLowerLimit = 40_A; // Reduce the limit to 40 A if we've limited to 70 A... + m_currentLimits.SupplyCurrentLowerTime = 1_s; // ...for at least 1 second m_currentLimits.SupplyCurrentLimitEnable = true; // And enable it m_currentLimits.StatorCurrentLimit = 120_A; // Limit stator to 120 amps diff --git a/cpp/MotionMagic/src/main/cpp/sim/SimProfile.cpp b/cpp/MotionMagic/src/main/cpp/sim/SimProfile.cpp index e1ccfc39..151553fb 100644 --- a/cpp/MotionMagic/src/main/cpp/sim/SimProfile.cpp +++ b/cpp/MotionMagic/src/main/cpp/sim/SimProfile.cpp @@ -7,13 +7,13 @@ units::second_t SimProfile::GetPeriod() { // set the start time if not yet running if (!_running) { - _lastTime = utils::GetCurrentTimeSeconds(); + _lastTime = utils::GetCurrentTime(); _running = true; } - double now = utils::GetCurrentTimeSeconds(); - double period = now - _lastTime; + auto now = utils::GetCurrentTime(); + auto period = now - _lastTime; _lastTime = now; - return units::second_t{period}; + return period; } \ No newline at end of file diff --git a/cpp/MotionMagic/src/main/include/sim/SimProfile.h b/cpp/MotionMagic/src/main/include/sim/SimProfile.h index f646f65e..49bd87b8 100644 --- a/cpp/MotionMagic/src/main/include/sim/SimProfile.h +++ b/cpp/MotionMagic/src/main/include/sim/SimProfile.h @@ -6,7 +6,7 @@ * Holds information about a simulated device. */ class SimProfile { - double _lastTime; + units::second_t _lastTime; bool _running = false; public: diff --git a/java/ArcadeDrive/src/main/java/frc/robot/Robot.java b/java/ArcadeDrive/src/main/java/frc/robot/Robot.java index 7f76f2d0..a6f49395 100644 --- a/java/ArcadeDrive/src/main/java/frc/robot/Robot.java +++ b/java/ArcadeDrive/src/main/java/frc/robot/Robot.java @@ -59,12 +59,6 @@ public void robotInit() { leftLeader.setSafetyEnabled(true); rightLeader.setSafetyEnabled(true); - - /* Currently in simulation, we do not support FOC, so disable it while simulating */ - if (Utils.isSimulation()){ - leftOut.EnableFOC = false; - rightOut.EnableFOC = false; - } } @Override diff --git a/java/CommandBasedDrive/src/main/java/frc/robot/subsystems/DriveSubsystem.java b/java/CommandBasedDrive/src/main/java/frc/robot/subsystems/DriveSubsystem.java index 58ccbd94..e5acba31 100644 --- a/java/CommandBasedDrive/src/main/java/frc/robot/subsystems/DriveSubsystem.java +++ b/java/CommandBasedDrive/src/main/java/frc/robot/subsystems/DriveSubsystem.java @@ -122,12 +122,6 @@ public DriveSubsystem() { m_leftOut.UpdateFreqHz = 0; m_rightOut.UpdateFreqHz = 0; - /* Currently in simulation, we do not support FOC, so disable it while simulating */ - if (Utils.isSimulation()) { - m_leftOut.EnableFOC = false; - m_rightOut.EnableFOC = false; - } - /* * Set the orientation of the simulated TalonFX devices relative to the robot chassis. * WPILib expects +V to be forward. Specify orientations to match that behavior.