diff --git a/src/main/java/org/codeorange/frc2024/robot/Constants.java b/src/main/java/org/codeorange/frc2024/robot/Constants.java index 33f0c8f..7ef980c 100644 --- a/src/main/java/org/codeorange/frc2024/robot/Constants.java +++ b/src/main/java/org/codeorange/frc2024/robot/Constants.java @@ -9,6 +9,7 @@ import edu.wpi.first.math.util.Units; import org.codeorange.frc2024.utility.MacAddressUtil; import org.codeorange.frc2024.utility.MacAddressUtil.RobotIdentity; +import org.codeorange.frc2024.utility.swerve.SecondOrderModuleState; import org.codeorange.frc2024.utility.swerve.SwerveSetpointGenerator; import org.codeorange.frc2024.utility.swerve.SecondOrderKinematics; import org.jetbrains.annotations.NotNull; @@ -135,10 +136,10 @@ public static class Ports { } case COMPETITION_BOT -> { - FL_ABSOLUTE_ENCODER_OFFSET = -0.962158203125; - BL_ABSOLUTE_ENCODER_OFFSET = -0.38037109375; - FR_ABSOLUTE_ENCODER_OFFSET = -0.038330078125; - BR_ABSOLUTE_ENCODER_OFFSET = -0.699462890625; + FL_ABSOLUTE_ENCODER_OFFSET = -0.669677734375 + 0.5; + BL_ABSOLUTE_ENCODER_OFFSET = -0.02197265625 + 0.5; + FR_ABSOLUTE_ENCODER_OFFSET = -0.378662109375 + 0.5; + BR_ABSOLUTE_ENCODER_OFFSET = -0.949462890625 + 0.5; WRIST_ABSOLUTE_ENCODER_OFFSET = -0.10498046875; ARM_ABSOLUTE_ENCODER_OFFSET = 0.45068359375; } @@ -226,7 +227,7 @@ public static class Ports { public static final double SS_HOMING_WRIST = isPrototype() ? 0 : 0; public static final double SS_HOMING_CLIMBER = isPrototype() ? 0 : 0; - public static final double SWERVE_DRIVE_P = 50; + public static final double SWERVE_DRIVE_P = 30; public static final double SWERVE_DRIVE_D = 0; public static final double SWERVE_DRIVE_I = 0; @@ -274,7 +275,7 @@ public static class Ports { public static final double SWERVE_INCHES_PER_ROTATION = 2*Math.PI*SWERVE_WHEEL_RADIUS; public static final double SWERVE_METER_PER_ROTATION = Units.inchesToMeters(SWERVE_INCHES_PER_ROTATION); public static final boolean USE_SECOND_ORDER_KINEMATICS = false; - public static final double STEER_MOTOR_POSITION_CONVERSION_FACTOR = 1 / 12.8; + public static final double STEER_MOTOR_POSITION_CONVERSION_FACTOR = 7.0 / 150.0; public static final double DRIVE_MOTOR_REDUCTION = 9 / 53.125; public static final double wheelBaseInches = isPrototype() ? 22.75 : 24.25; // not real number, just example @@ -289,7 +290,7 @@ public static class Ports { SWERVE_RIGHT_BACK_LOCATION }; // really, figure out if these locations are correct <_< - public static final SwerveDriveKinematics SWERVE_DRIVE_KINEMATICS = new SwerveDriveKinematics( + public static final SecondOrderKinematics SWERVE_DRIVE_KINEMATICS = new SecondOrderKinematics( SWERVE_MODULE_LOCATIONS ); diff --git a/src/main/java/org/codeorange/frc2024/subsystem/drive/Drive.java b/src/main/java/org/codeorange/frc2024/subsystem/drive/Drive.java index 0494214..416dc76 100644 --- a/src/main/java/org/codeorange/frc2024/subsystem/drive/Drive.java +++ b/src/main/java/org/codeorange/frc2024/subsystem/drive/Drive.java @@ -188,11 +188,11 @@ private void setMotorSpeed(int module, double velocity, double acceleration, boo SwerveModuleState[] wantedStates = new SwerveModuleState[4]; SwerveModuleState[] realStates = new SwerveModuleState[4]; - private synchronized void setSwerveModuleStates(SwerveModuleState[] swerveModuleStates, boolean isOpenLoop) { + private synchronized void setSwerveModuleStates(SecondOrderModuleState[] swerveModuleStates, boolean isOpenLoop) { for (int i = 0; i < 4; i++) { var moduleState = swerveModuleStates[i]; moduleState = SecondOrderModuleState.optimize(moduleState, Rotation2d.fromDegrees(getWheelRotation(i))); - wantedStates[i] = swerveModuleStates[i]; + wantedStates[i] = swerveModuleStates[i].toFirstOrder(); moduleIO[i].setSteerMotorPosition(moduleState.angle.getDegrees()); setMotorSpeed(i, moduleState.speedMetersPerSecond, 0, isOpenLoop); @@ -209,7 +209,7 @@ private synchronized void setSwerveModuleStates(SwerveModuleState[] swerveModule } public synchronized void drive(@NotNull ControllerDriveInputs inputs, boolean fieldRel, boolean openLoop) { - SwerveModuleState[] states = + SecondOrderModuleState[] states = SWERVE_DRIVE_KINEMATICS.toSwerveModuleStates( ChassisSpeeds.discretize(fieldRel ? ChassisSpeeds.fromFieldRelativeSpeeds( @@ -222,7 +222,7 @@ public synchronized void drive(@NotNull ControllerDriveInputs inputs, boolean fi DRIVE_HIGH_SPEED_M * inputs.getY(), inputs.getRotation() * MAX_TELEOP_TURN_SPEED), 0.02 )); - SwerveDriveKinematics.desaturateWheelSpeeds(states, DRIVE_HIGH_SPEED_M); + SecondOrderKinematics.desaturateWheelSpeeds(states, DRIVE_HIGH_SPEED_M); setSwerveModuleStates(states, openLoop); } @@ -230,13 +230,13 @@ public synchronized void drive(@NotNull ControllerDriveInputs inputs, boolean fi public void swerveDriveTargetAngle(@NotNull ControllerDriveInputs inputs, double targetAngleRad) { double turn = turnPID.calculate(gyroInputs.yawPositionRad, targetAngleRad); Logger.recordOutput("Drive/Wanted Omega", turn); - SwerveModuleState[] states = SWERVE_DRIVE_KINEMATICS.toSwerveModuleStates( + SecondOrderModuleState[] states = SWERVE_DRIVE_KINEMATICS.toSwerveModuleStates( ChassisSpeeds.discretize( ChassisSpeeds.fromFieldRelativeSpeeds(DRIVE_HIGH_SPEED_M * inputs.getX(), DRIVE_HIGH_SPEED_M * inputs.getY(), -turn, gyroInputs.rotation2d), 0.02)); - SwerveDriveKinematics.desaturateWheelSpeeds(states, DRIVE_HIGH_SPEED_M); + SecondOrderKinematics.desaturateWheelSpeeds(states, DRIVE_HIGH_SPEED_M); setSwerveModuleStates(states, true); } @@ -312,7 +312,7 @@ public Pose2d getPose() { public void setNextChassisSpeeds(ChassisSpeeds nextChassisSpeeds) { var states = SWERVE_DRIVE_KINEMATICS.toSwerveModuleStates(ChassisSpeeds.discretize(nextChassisSpeeds, 0.02)); - SwerveDriveKinematics.desaturateWheelSpeeds(states, DRIVE_HIGH_SPEED_M); + SecondOrderKinematics.desaturateWheelSpeeds(states, DRIVE_HIGH_SPEED_M); setSwerveModuleStates(states, false); } }