From a1ed7ee9063561a388dfc83f53a692a67e06dfe7 Mon Sep 17 00:00:00 2001 From: Ethan Hardy <102838865+978-9-17-637879-3@users.noreply.github.com> Date: Tue, 30 Jan 2024 22:55:45 -0500 Subject: [PATCH] cleanup and fix usage of constants Change some names to match scheme, replace hardcoded "magic constants" with ones in Constants.java, remove auton acceleration constant that cannot be used with PathPlanner --- src/main/java/frc/robot/Constants.java | 13 ++++++------- src/main/java/frc/robot/Robot.java | 2 +- .../subsystems/swervedrive/SwerveSubsystem.java | 8 +++----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index c8f57a191..59a788472 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -4,10 +4,11 @@ package frc.robot; +import com.pathplanner.lib.util.PIDConstants; + import edu.wpi.first.math.geometry.Translation3d; import edu.wpi.first.math.util.Units; import swervelib.math.Matter; -import swervelib.parser.PIDFConfig; /** * The Constants class provides a convenient place for teams to hold robot-wide numerical or boolean constants. This @@ -24,16 +25,14 @@ public final class Constants public static final Matter CHASSIS = new Matter(new Translation3d(0, 0, Units.inchesToMeters(8)), ROBOT_MASS); public static final double LOOP_TIME = 0.13; //s, 20ms + 110ms sprk max velocity lag - public static final class Auton + public static final class AutonConstants { - public static final PIDFConfig TranslationPID = new PIDFConfig(0.7, 0, 0); - public static final PIDFConfig angleAutoPID = new PIDFConfig(0.4, 0, 0.01); - - public static final double MAX_ACCELERATION = 2; + public static final PIDConstants TRANSLATION_PID = new PIDConstants(0.7, 0, 0); + public static final PIDConstants ANGLE_PID = new PIDConstants(0.4, 0, 0.01); } - public static final class Drivebase + public static final class DrivebaseConstants { // Hold time on motor brakes when disabled diff --git a/src/main/java/frc/robot/Robot.java b/src/main/java/frc/robot/Robot.java index 25f81c915..94e6ddb60 100644 --- a/src/main/java/frc/robot/Robot.java +++ b/src/main/java/frc/robot/Robot.java @@ -84,7 +84,7 @@ public void disabledInit() @Override public void disabledPeriodic() { - if (disabledTimer.hasElapsed(Constants.Drivebase.WHEEL_LOCK_TIME)) + if (disabledTimer.hasElapsed(Constants.DrivebaseConstants.WHEEL_LOCK_TIME)) { m_robotContainer.setMotorBrake(false); disabledTimer.stop(); diff --git a/src/main/java/frc/robot/subsystems/swervedrive/SwerveSubsystem.java b/src/main/java/frc/robot/subsystems/swervedrive/SwerveSubsystem.java index 049163d6d..973eb92b1 100644 --- a/src/main/java/frc/robot/subsystems/swervedrive/SwerveSubsystem.java +++ b/src/main/java/frc/robot/subsystems/swervedrive/SwerveSubsystem.java @@ -8,7 +8,6 @@ import com.pathplanner.lib.path.PathConstraints; import com.pathplanner.lib.path.PathPlannerPath; import com.pathplanner.lib.util.HolonomicPathFollowerConfig; -import com.pathplanner.lib.util.PIDConstants; import com.pathplanner.lib.util.ReplanningConfig; import edu.wpi.first.math.geometry.Pose2d; import edu.wpi.first.math.geometry.Rotation2d; @@ -22,6 +21,7 @@ import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine.Config; +import frc.robot.Constants.AutonConstants; import java.io.File; import java.util.function.DoubleSupplier; import swervelib.SwerveController; @@ -105,11 +105,9 @@ public void setupPathPlanner() this::getRobotVelocity, // ChassisSpeeds supplier. MUST BE ROBOT RELATIVE this::setChassisSpeeds, // Method that will drive the robot given ROBOT RELATIVE ChassisSpeeds new HolonomicPathFollowerConfig( // HolonomicPathFollowerConfig, this should likely live in your Constants class - new PIDConstants(5.0, 0.0, 0.0), + AutonConstants.TRANSLATION_PID, // Translation PID constants - new PIDConstants(swerveDrive.swerveController.config.headingPIDF.p, - swerveDrive.swerveController.config.headingPIDF.i, - swerveDrive.swerveController.config.headingPIDF.d), + AutonConstants.ANGLE_PID, // Rotation PID constants 4.5, // Max module speed, in m/s