Fix warnings

This commit is contained in:
Tyler Wilcox 2026-01-29 21:54:53 -05:00
parent b269ce00bd
commit 51cd3df642
3 changed files with 14 additions and 10 deletions

View File

@ -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<SwerveModule> modules = new ArrayList<SwerveModule>();
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);
}

View File

@ -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();

View File

@ -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);