Fix warnings
This commit is contained in:
parent
b269ce00bd
commit
51cd3df642
|
|
@ -2,12 +2,14 @@ package org.fairportrobotics.frc.robolib.drivesystems.swerve;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.ctre.phoenix6.CANBus;
|
||||||
|
|
||||||
import edu.wpi.first.math.geometry.Translation2d;
|
import edu.wpi.first.math.geometry.Translation2d;
|
||||||
|
|
||||||
public class SwerveBuilder {
|
public class SwerveBuilder {
|
||||||
|
|
||||||
ArrayList<SwerveModule> modules = new ArrayList<SwerveModule>();
|
ArrayList<SwerveModule> modules = new ArrayList<SwerveModule>();
|
||||||
String canBusName = "rio";
|
CANBus canBusObj;
|
||||||
|
|
||||||
private double maxAngularVelRadiansSecond = 1.0;
|
private double maxAngularVelRadiansSecond = 1.0;
|
||||||
private double maxLinearVelMetersSecond = Math.PI;
|
private double maxLinearVelMetersSecond = Math.PI;
|
||||||
|
|
@ -24,7 +26,7 @@ public class SwerveBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SwerveBuilder withCanbusName(String canBusname) {
|
public SwerveBuilder withCanbusName(String canBusname) {
|
||||||
this.canBusName = canBusname;
|
this.canBusObj = new CANBus(canBusname);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +58,7 @@ public class SwerveBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SwerveDriveSubsystem build() {
|
public SwerveDriveSubsystem build() {
|
||||||
return new SwerveDriveSubsystem(pigeonId, canBusName, maxLinearVelMetersSecond, maxAngularVelRadiansSecond,
|
return new SwerveDriveSubsystem(pigeonId, canBusObj, maxLinearVelMetersSecond, maxAngularVelRadiansSecond,
|
||||||
modules.toArray(size -> new SwerveModule[size]));
|
modules.toArray(size -> new SwerveModule[size]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,7 +186,7 @@ public class SwerveBuilder {
|
||||||
public SwerveModule build() {
|
public SwerveModule build() {
|
||||||
return new SwerveModule(driveMotorId, driveKP, driveKI, driveKD, driveKV, driveInverted, steerMotorId, steerKP, steerKI,
|
return new SwerveModule(driveMotorId, driveKP, driveKI, driveKD, driveKV, driveInverted, steerMotorId, steerKP, steerKI,
|
||||||
steerKD, steerKS, steerKV, steerKA,
|
steerKD, steerKS, steerKV, steerKA,
|
||||||
steerEncoderId, steerOffset, canBusName, moduleLocation, gearRatio, wheelDiameterInMeters,
|
steerEncoderId, steerOffset, canBusObj, moduleLocation, gearRatio, wheelDiameterInMeters,
|
||||||
moduleName);
|
moduleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.fairportrobotics.frc.robolib.drivesystems.swerve;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import com.ctre.phoenix6.CANBus;
|
||||||
import com.ctre.phoenix6.Utils;
|
import com.ctre.phoenix6.Utils;
|
||||||
import com.ctre.phoenix6.hardware.Pigeon2;
|
import com.ctre.phoenix6.hardware.Pigeon2;
|
||||||
|
|
||||||
|
|
@ -34,7 +35,7 @@ public class SwerveDriveSubsystem extends SubsystemBase{
|
||||||
|
|
||||||
private double mLastSimTime = 0;
|
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_LINEAR_SPEED = maxLinearVelMetersSecond;
|
||||||
MAX_ANGULAR_SPEED = maxAngularVelRadiansSecond;
|
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])
|
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);
|
poseEstimator = new SwerveDrivePoseEstimator3d(driveKiniematics, new Rotation3d(Rotation2d.fromRotations(getCurrentYaw().magnitude())), getModulePositions(), Pose3d.kZero);
|
||||||
chassisSpeeds = new ChassisSpeeds();
|
chassisSpeeds = new ChassisSpeeds();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package org.fairportrobotics.frc.robolib.drivesystems.swerve;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
import com.ctre.phoenix6.CANBus;
|
||||||
import com.ctre.phoenix6.configs.CANcoderConfiguration;
|
import com.ctre.phoenix6.configs.CANcoderConfiguration;
|
||||||
import com.ctre.phoenix6.configs.ClosedLoopGeneralConfigs;
|
import com.ctre.phoenix6.configs.ClosedLoopGeneralConfigs;
|
||||||
import com.ctre.phoenix6.configs.FeedbackConfigs;
|
import com.ctre.phoenix6.configs.FeedbackConfigs;
|
||||||
|
|
@ -63,24 +64,24 @@ public class SwerveModule {
|
||||||
double steerKA,
|
double steerKA,
|
||||||
int steerEncoderId,
|
int steerEncoderId,
|
||||||
double steerOffset,
|
double steerOffset,
|
||||||
String canBusName,
|
CANBus canBusObj,
|
||||||
Translation2d moduleLocation,
|
Translation2d moduleLocation,
|
||||||
double gearRatio,
|
double gearRatio,
|
||||||
double wheelDiameterInMeters,
|
double wheelDiameterInMeters,
|
||||||
String moduleName
|
String moduleName
|
||||||
){
|
){
|
||||||
|
|
||||||
steerEncoder = new CANcoder(steerEncoderId, canBusName);
|
steerEncoder = new CANcoder(steerEncoderId, canBusObj);
|
||||||
// steerEncoder.getAbsolutePosition().setUpdateFrequency(CAN_UPDATE_FREQUENCY);
|
// steerEncoder.getAbsolutePosition().setUpdateFrequency(CAN_UPDATE_FREQUENCY);
|
||||||
// steerEncoder.optimizeBusUtilization();
|
// steerEncoder.optimizeBusUtilization();
|
||||||
steerEncoder.getConfigurator().apply(generateCanCoderConfiguration(steerOffset));
|
steerEncoder.getConfigurator().apply(generateCanCoderConfiguration(steerOffset));
|
||||||
|
|
||||||
driveMotor = new TalonFX(driveMotorId, canBusName);
|
driveMotor = new TalonFX(driveMotorId, canBusObj);
|
||||||
// driveMotor.getVelocity().setUpdateFrequency(CAN_UPDATE_FREQUENCY);
|
// driveMotor.getVelocity().setUpdateFrequency(CAN_UPDATE_FREQUENCY);
|
||||||
// driveMotor.optimizeBusUtilization();
|
// driveMotor.optimizeBusUtilization();
|
||||||
driveMotor.getConfigurator().apply(generateDriveTalonConfiguration(driveKP, driveKI, driveKD, driveKV, driveInverted));
|
driveMotor.getConfigurator().apply(generateDriveTalonConfiguration(driveKP, driveKI, driveKD, driveKV, driveInverted));
|
||||||
|
|
||||||
steerMotor = new TalonFX(steerMotorId, canBusName);
|
steerMotor = new TalonFX(steerMotorId, canBusObj);
|
||||||
// steerMotor.optimizeBusUtilization();
|
// steerMotor.optimizeBusUtilization();
|
||||||
steerMotor.getConfigurator().apply(generateSteerTalonConfiguration(steerKP, steerKI, steerKD, steerKS, steerKV, steerKA));
|
steerMotor.getConfigurator().apply(generateSteerTalonConfiguration(steerKP, steerKI, steerKD, steerKS, steerKV, steerKA));
|
||||||
// steerMotor.setNeutralMode(NeutralModeValue.Brake);
|
// steerMotor.setNeutralMode(NeutralModeValue.Brake);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue