Created constants for motor offset and id numbers

This commit is contained in:
Lukas H 2026-03-02 20:17:19 -05:00
parent dfec133581
commit 940614c790
2 changed files with 57 additions and 18 deletions

View File

@ -23,7 +23,43 @@ public final class Constants {
REAL, REAL,
REPLAY REPLAY
} }
public static final RobotType CURRENT_MODE = RobotType.REAL; public static final RobotType CURRENT_MODE = RobotType.REAL;
} }
// Swerve offsets as of 3/2/26
public static class SwerveDriveOffsets {
public static final float FRONT_LEFT_MOTOR_OFFSET = -0.336426f;
public static final float FRONT_RIGHT_MOTOR_OFFSET = 0.108887f;
public static final float BACK_LEFT_MOTOR_OFFSET = -0.492432f;
public static final float BACK_RIGHT_MOTOR_OFFSET = 0.470215f;
}
/*
* Numbers starting with 1 (E.g. 11, 12, 13) are in the Front Left of the robot
* Numbers starting with 2 (E.g. 21, 22, 23) are in the Front Right of the robot
* Numbers starting with 3 (E.g. 31, 32, 33) are in the Back Left of the robot
* Numbers starting with 4 (E.g. 41, 42, 43) are in the Back Right of the robot
* Laters numbers will be added for more subsystems
* Single diget numbers (E.g. 1, 2, 3) are extra, non-motor, pieces that require IDs, such as the Pigeon
*/
public static class SwerveDriveIDs {
public static final int FRONT_LEFT_STEER_ID = 11;
public static final int FRONT_LEFT_DRIVE_ID = 12;
public static final int FRONT_LEFT_ENCODER_ID = 13;
public static final int FRONT_RIGHT_STEER_ID = 21;
public static final int FRONT_RIGHT_DRIVE_ID = 22;
public static final int FRONT_RIGHT_ENCODER_ID = 23;
public static final int BACK_LEFT_STEER_ID = 31;
public static final int BACK_LEFT_DRIVE_ID = 32;
public static final int BACK_LEFT_ENCODER_ID = 33;
public static final int BACK_RIGHT_STEER_ID = 41;
public static final int BACK_RIGHT_DRIVE_ID = 42;
public static final int BACK_RIGHT_ENCODER_ID = 43;
}
//Bird
public static class ExtraIDEntities {
public static final int PIGEON_ID = 1;
}
} }

View File

@ -14,6 +14,8 @@ import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import frc.robot.Constants;
public class DriveSubsystem extends TestableSubsystem { public class DriveSubsystem extends TestableSubsystem {
private SwerveBuilder swerveBuilder = new SwerveBuilder(); private SwerveBuilder swerveBuilder = new SwerveBuilder();
@ -33,23 +35,24 @@ public class DriveSubsystem extends TestableSubsystem {
driveSystem = swerveBuilder driveSystem = swerveBuilder
.withCanbusName("Drive") .withCanbusName("Drive")
.withPigeonId(1) .withPigeonId(Constants.ExtraIDEntities.PIGEON_ID)
.withMaxLinearVelocity(3.0) .withMaxLinearVelocity(3.0)
.withMaxAngularVelocity(Math.PI) .withMaxAngularVelocity(Math.PI)
.withSwerveModule( .withSwerveModule(
swerveBuilder.new SwerveModuleBuilder() swerveBuilder.new SwerveModuleBuilder()
.withDriveMotorId(12) .withDriveMotorId(Constants.SwerveDriveIDs.FRONT_LEFT_DRIVE_ID)
.withDriveKP(driveP) .withDriveKP(driveP)
.withDriveKI(driveI) .withDriveKI(driveI)
.withDriveKD(driveD) .withDriveKD(driveD)
.withDriveKV(driveKV) .withDriveKV(driveKV)
.withSteerMotorId(11) .withSteerMotorId(Constants.SwerveDriveIDs.FRONT_LEFT_STEER_ID)
.withSteerKP(steerP) .withSteerKP(steerP)
.withSteerKI(steerI) .withSteerKI(steerI)
.withSteerKD(steerD) .withSteerKD(steerD)
.withSteerKV(steerKV) .withSteerKV(steerKV)
.withSteerOffset(-0.336426) //If the offsets don't work, contact Tyler W or Dom G
.withSteerEncoderId(13) .withSteerOffset(Constants.SwerveDriveOffsets.FRONT_LEFT_MOTOR_OFFSET)
.withSteerEncoderId(Constants.SwerveDriveIDs.FRONT_LEFT_ENCODER_ID)
.withModuleLocation(new Translation2d(1, 1)) .withModuleLocation(new Translation2d(1, 1))
.withModuleName("Front Left") .withModuleName("Front Left")
.withGearRatio(8.14) .withGearRatio(8.14)
@ -57,19 +60,19 @@ public class DriveSubsystem extends TestableSubsystem {
.build()) .build())
.withSwerveModule( .withSwerveModule(
swerveBuilder.new SwerveModuleBuilder() swerveBuilder.new SwerveModuleBuilder()
.withDriveMotorId(22) .withDriveMotorId(Constants.SwerveDriveIDs.FRONT_RIGHT_DRIVE_ID)
.withDriveKP(driveP) .withDriveKP(driveP)
.withDriveKI(driveI) .withDriveKI(driveI)
.withDriveKD(driveD) .withDriveKD(driveD)
.withDriveKV(driveKV) .withDriveKV(driveKV)
.withDriveInverted() .withDriveInverted()
.withSteerMotorId(21) .withSteerMotorId(Constants.SwerveDriveIDs.FRONT_RIGHT_STEER_ID)
.withSteerKP(steerP) .withSteerKP(steerP)
.withSteerKI(steerI) .withSteerKI(steerI)
.withSteerKD(steerD) .withSteerKD(steerD)
.withSteerKV(steerKV) .withSteerKV(steerKV)
.withSteerOffset(0.108887) .withSteerOffset(Constants.SwerveDriveOffsets.FRONT_RIGHT_MOTOR_OFFSET)
.withSteerEncoderId(23) .withSteerEncoderId(Constants.SwerveDriveIDs.FRONT_RIGHT_ENCODER_ID)
.withModuleLocation(new Translation2d(1, -1)) .withModuleLocation(new Translation2d(1, -1))
.withModuleName("Front Right") .withModuleName("Front Right")
.withGearRatio(8.14) .withGearRatio(8.14)
@ -77,18 +80,18 @@ public class DriveSubsystem extends TestableSubsystem {
.build()) .build())
.withSwerveModule( .withSwerveModule(
swerveBuilder.new SwerveModuleBuilder() swerveBuilder.new SwerveModuleBuilder()
.withDriveMotorId(32) .withDriveMotorId(Constants.SwerveDriveIDs.BACK_LEFT_DRIVE_ID)
.withDriveKP(driveP) .withDriveKP(driveP)
.withDriveKI(driveI) .withDriveKI(driveI)
.withDriveKD(driveD) .withDriveKD(driveD)
.withDriveKV(driveKV) .withDriveKV(driveKV)
.withSteerMotorId(31) .withSteerMotorId(Constants.SwerveDriveIDs.BACK_LEFT_STEER_ID)
.withSteerKP(steerP) .withSteerKP(steerP)
.withSteerKI(steerI) .withSteerKI(steerI)
.withSteerKD(steerD) .withSteerKD(steerD)
.withSteerKV(steerKV) .withSteerKV(steerKV)
.withSteerOffset(-0.492432) .withSteerOffset(Constants.SwerveDriveOffsets.BACK_LEFT_MOTOR_OFFSET)
.withSteerEncoderId(33) .withSteerEncoderId(Constants.SwerveDriveIDs.BACK_LEFT_ENCODER_ID)
.withModuleLocation(new Translation2d(-1, 1)) .withModuleLocation(new Translation2d(-1, 1))
.withModuleName("Back Left") .withModuleName("Back Left")
.withGearRatio(8.14) .withGearRatio(8.14)
@ -96,19 +99,19 @@ public class DriveSubsystem extends TestableSubsystem {
.build()) .build())
.withSwerveModule( .withSwerveModule(
swerveBuilder.new SwerveModuleBuilder() swerveBuilder.new SwerveModuleBuilder()
.withDriveMotorId(42) .withDriveMotorId(Constants.SwerveDriveIDs.BACK_RIGHT_DRIVE_ID)
.withDriveKP(driveP) .withDriveKP(driveP)
.withDriveKI(driveI) .withDriveKI(driveI)
.withDriveKD(driveD) .withDriveKD(driveD)
.withDriveKV(driveKV) .withDriveKV(driveKV)
.withDriveInverted() .withDriveInverted()
.withSteerMotorId(41) .withSteerMotorId(Constants.SwerveDriveIDs.BACK_RIGHT_STEER_ID)
.withSteerKP(steerP) .withSteerKP(steerP)
.withSteerKI(steerI) .withSteerKI(steerI)
.withSteerKD(steerD) .withSteerKD(steerD)
.withSteerKV(steerKV) .withSteerKV(steerKV)
.withSteerOffset(0.470215) .withSteerOffset(Constants.SwerveDriveOffsets.BACK_RIGHT_MOTOR_OFFSET)
.withSteerEncoderId(43) .withSteerEncoderId(Constants.SwerveDriveIDs.BACK_RIGHT_ENCODER_ID)
.withModuleLocation(new Translation2d(-1, -1)) .withModuleLocation(new Translation2d(-1, -1))
.withModuleName("Back Right") .withModuleName("Back Right")
.withGearRatio(8.14) .withGearRatio(8.14)