diff --git a/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveBuilder.java b/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveBuilder.java index 9e46b49..ffbbf52 100644 --- a/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveBuilder.java +++ b/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveBuilder.java @@ -2,12 +2,14 @@ package org.fairportrobotics.frc.robolib.drivesystems.swerve; import java.util.ArrayList; +import com.ctre.phoenix6.CANBus; + import edu.wpi.first.math.geometry.Translation2d; public class SwerveBuilder { ArrayList modules = new ArrayList(); - String canBusName = "rio"; + CANBus canBusObj; private double maxAngularVelRadiansSecond = 1.0; private double maxLinearVelMetersSecond = Math.PI; @@ -24,7 +26,7 @@ public class SwerveBuilder { } public SwerveBuilder withCanbusName(String canBusname) { - this.canBusName = canBusname; + this.canBusObj = new CANBus(canBusname); return this; } @@ -56,7 +58,7 @@ public class SwerveBuilder { } public SwerveDriveSubsystem build() { - return new SwerveDriveSubsystem(pigeonId, canBusName, maxLinearVelMetersSecond, maxAngularVelRadiansSecond, + return new SwerveDriveSubsystem(pigeonId, canBusObj, maxLinearVelMetersSecond, maxAngularVelRadiansSecond, modules.toArray(size -> new SwerveModule[size])); } @@ -184,7 +186,7 @@ public class SwerveBuilder { public SwerveModule build() { return new SwerveModule(driveMotorId, driveKP, driveKI, driveKD, driveKV, driveInverted, steerMotorId, steerKP, steerKI, steerKD, steerKS, steerKV, steerKA, - steerEncoderId, steerOffset, canBusName, moduleLocation, gearRatio, wheelDiameterInMeters, + steerEncoderId, steerOffset, canBusObj, moduleLocation, gearRatio, wheelDiameterInMeters, moduleName); } diff --git a/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveDriveSubsystem.java b/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveDriveSubsystem.java index 53f98ac..1d928d0 100644 --- a/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveDriveSubsystem.java +++ b/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveDriveSubsystem.java @@ -2,6 +2,7 @@ package org.fairportrobotics.frc.robolib.drivesystems.swerve; import java.util.Arrays; +import com.ctre.phoenix6.CANBus; import com.ctre.phoenix6.Utils; import com.ctre.phoenix6.hardware.Pigeon2; @@ -34,7 +35,7 @@ public class SwerveDriveSubsystem extends SubsystemBase{ private double mLastSimTime = 0; - public SwerveDriveSubsystem(int pigeonId, String canBusName, double maxLinearVelMetersSecond, double maxAngularVelRadiansSecond, SwerveModule... modules){ + public SwerveDriveSubsystem(int pigeonId, CANBus canBus, double maxLinearVelMetersSecond, double maxAngularVelRadiansSecond, SwerveModule... modules){ MAX_LINEAR_SPEED = maxLinearVelMetersSecond; MAX_ANGULAR_SPEED = maxAngularVelRadiansSecond; @@ -45,7 +46,7 @@ public class SwerveDriveSubsystem extends SubsystemBase{ Arrays.stream(modules).map((m) -> m.getModuleLocation()).toArray(size -> new Translation2d[size]) ); - gyro = new Pigeon2(pigeonId, canBusName); + gyro = new Pigeon2(pigeonId, canBus); poseEstimator = new SwerveDrivePoseEstimator3d(driveKiniematics, new Rotation3d(Rotation2d.fromRotations(getCurrentYaw().magnitude())), getModulePositions(), Pose3d.kZero); chassisSpeeds = new ChassisSpeeds(); diff --git a/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveModule.java b/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveModule.java index 26a17ff..9f1b818 100644 --- a/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveModule.java +++ b/lib/src/main/java/org/fairportrobotics/frc/robolib/drivesystems/swerve/SwerveModule.java @@ -2,6 +2,7 @@ package org.fairportrobotics.frc.robolib.drivesystems.swerve; import java.lang.reflect.Modifier; +import com.ctre.phoenix6.CANBus; import com.ctre.phoenix6.configs.CANcoderConfiguration; import com.ctre.phoenix6.configs.ClosedLoopGeneralConfigs; import com.ctre.phoenix6.configs.FeedbackConfigs; @@ -63,24 +64,24 @@ public class SwerveModule { double steerKA, int steerEncoderId, double steerOffset, - String canBusName, + CANBus canBusObj, Translation2d moduleLocation, double gearRatio, double wheelDiameterInMeters, String moduleName ){ - steerEncoder = new CANcoder(steerEncoderId, canBusName); + steerEncoder = new CANcoder(steerEncoderId, canBusObj); // steerEncoder.getAbsolutePosition().setUpdateFrequency(CAN_UPDATE_FREQUENCY); // steerEncoder.optimizeBusUtilization(); steerEncoder.getConfigurator().apply(generateCanCoderConfiguration(steerOffset)); - driveMotor = new TalonFX(driveMotorId, canBusName); + driveMotor = new TalonFX(driveMotorId, canBusObj); // driveMotor.getVelocity().setUpdateFrequency(CAN_UPDATE_FREQUENCY); // driveMotor.optimizeBusUtilization(); driveMotor.getConfigurator().apply(generateDriveTalonConfiguration(driveKP, driveKI, driveKD, driveKV, driveInverted)); - steerMotor = new TalonFX(steerMotorId, canBusName); + steerMotor = new TalonFX(steerMotorId, canBusObj); // steerMotor.optimizeBusUtilization(); steerMotor.getConfigurator().apply(generateSteerTalonConfiguration(steerKP, steerKI, steerKD, steerKS, steerKV, steerKA)); // steerMotor.setNeutralMode(NeutralModeValue.Brake);