diff --git a/config/LeftBackCANCoder.json b/config/LeftBackCANCoder.json new file mode 100644 index 0000000..69ab1f3 --- /dev/null +++ b/config/LeftBackCANCoder.json @@ -0,0 +1,47 @@ +{ + "Configs": [ + { + "Name": "Integrated Sensor", + "Type": "IntegratedSensor", + "Description": "Configures how the sensor is processed.", + "Ordinal": 0, + "Values": { + "Absolute Sensor Range": 0, + "Magnet Offset (deg)": -240.0293, + "Sensor Direction": false, + "Sensor Initialization Strategy": 0 + } + }, + { + "Name": "Unit Coefficient And String", + "Type": "UnitCoeffGroup", + "Description": "Describes the units to report in API and Self-Test.", + "Ordinal": 0, + "Values": { + "Sensor Coefficient": 0.087890625, + "Sensor Time Base": 1, + "Unit String": "deg" + } + }, + { + "Name": "Custom Params", + "Type": "CustomParams", + "Description": "These are arbitrary values not used by the firmware.", + "Ordinal": 0, + "Values": { + "Custom Param 0": 0, + "Custom Param 1": 0 + } + }, + { + "Name": "Advanced Sensor and Meas", + "Type": "AdvancedSensorMeas", + "Description": "Group of configs relating to advanced sensor features and filters", + "Ordinal": 0, + "Values": { + "Velocity Period": 100, + "Velocity Window": 64 + } + } + ] +} \ No newline at end of file diff --git a/config/LeftFrontCANCoder.json b/config/LeftFrontCANCoder.json new file mode 100644 index 0000000..1a5edcd --- /dev/null +++ b/config/LeftFrontCANCoder.json @@ -0,0 +1,47 @@ +{ + "Configs": [ + { + "Name": "Integrated Sensor", + "Type": "IntegratedSensor", + "Description": "Configures how the sensor is processed.", + "Ordinal": 0, + "Values": { + "Absolute Sensor Range": 0, + "Magnet Offset (deg)": -181.230469, + "Sensor Direction": false, + "Sensor Initialization Strategy": 0 + } + }, + { + "Name": "Unit Coefficient And String", + "Type": "UnitCoeffGroup", + "Description": "Describes the units to report in API and Self-Test.", + "Ordinal": 0, + "Values": { + "Sensor Coefficient": 0.087890625, + "Sensor Time Base": 1, + "Unit String": "deg" + } + }, + { + "Name": "Custom Params", + "Type": "CustomParams", + "Description": "These are arbitrary values not used by the firmware.", + "Ordinal": 0, + "Values": { + "Custom Param 0": 0, + "Custom Param 1": 0 + } + }, + { + "Name": "Advanced Sensor and Meas", + "Type": "AdvancedSensorMeas", + "Description": "Group of configs relating to advanced sensor features and filters", + "Ordinal": 0, + "Values": { + "Velocity Period": 100, + "Velocity Window": 64 + } + } + ] +} \ No newline at end of file diff --git a/config/RightBackCANCoder.json b/config/RightBackCANCoder.json new file mode 100644 index 0000000..236a112 --- /dev/null +++ b/config/RightBackCANCoder.json @@ -0,0 +1,47 @@ +{ + "Configs": [ + { + "Name": "Integrated Sensor", + "Type": "IntegratedSensor", + "Description": "Configures how the sensor is processed.", + "Ordinal": 0, + "Values": { + "Absolute Sensor Range": 0, + "Magnet Offset (deg)": -40.86914, + "Sensor Direction": false, + "Sensor Initialization Strategy": 0 + } + }, + { + "Name": "Unit Coefficient And String", + "Type": "UnitCoeffGroup", + "Description": "Describes the units to report in API and Self-Test.", + "Ordinal": 0, + "Values": { + "Sensor Coefficient": 0.087890625, + "Sensor Time Base": 1, + "Unit String": "deg" + } + }, + { + "Name": "Custom Params", + "Type": "CustomParams", + "Description": "These are arbitrary values not used by the firmware.", + "Ordinal": 0, + "Values": { + "Custom Param 0": 0, + "Custom Param 1": 0 + } + }, + { + "Name": "Advanced Sensor and Meas", + "Type": "AdvancedSensorMeas", + "Description": "Group of configs relating to advanced sensor features and filters", + "Ordinal": 0, + "Values": { + "Velocity Period": 100, + "Velocity Window": 64 + } + } + ] +} \ No newline at end of file diff --git a/config/RightFrontCANCoder.json b/config/RightFrontCANCoder.json new file mode 100644 index 0000000..ec93eb5 --- /dev/null +++ b/config/RightFrontCANCoder.json @@ -0,0 +1,47 @@ +{ + "Configs": [ + { + "Name": "Integrated Sensor", + "Type": "IntegratedSensor", + "Description": "Configures how the sensor is processed.", + "Ordinal": 0, + "Values": { + "Absolute Sensor Range": 0, + "Magnet Offset (deg)": -270.615234, + "Sensor Direction": false, + "Sensor Initialization Strategy": 0 + } + }, + { + "Name": "Unit Coefficient And String", + "Type": "UnitCoeffGroup", + "Description": "Describes the units to report in API and Self-Test.", + "Ordinal": 0, + "Values": { + "Sensor Coefficient": 0.087890625, + "Sensor Time Base": 1, + "Unit String": "deg" + } + }, + { + "Name": "Custom Params", + "Type": "CustomParams", + "Description": "These are arbitrary values not used by the firmware.", + "Ordinal": 0, + "Values": { + "Custom Param 0": 0, + "Custom Param 1": 0 + } + }, + { + "Name": "Advanced Sensor and Meas", + "Type": "AdvancedSensorMeas", + "Description": "Group of configs relating to advanced sensor features and filters", + "Ordinal": 0, + "Values": { + "Velocity Period": 100, + "Velocity Window": 64 + } + } + ] +} \ No newline at end of file diff --git a/src/main/java/frc4388/robot/RobotMap.java b/src/main/java/frc4388/robot/RobotMap.java index d4dad2b..c33a95f 100644 --- a/src/main/java/frc4388/robot/RobotMap.java +++ b/src/main/java/frc4388/robot/RobotMap.java @@ -127,14 +127,11 @@ public class RobotMap { // rightBackEncoder.configMagnetOffset(225.0); //180.0); //270.0);//267.01171875);//SwerveDriveConstants.Configurations.RIGHT_BACK_ENCODER_OFFSET); // initialize SwerveModules - this.leftFront = new SwerveModule(leftFrontWheel, leftFrontSteer, leftFrontEncoder); - this.rightFront = new SwerveModule(rightFrontWheel, rightFrontSteer, rightFrontEncoder); - this.leftBack = new SwerveModule(leftBackWheel, leftBackSteer, leftBackEncoder); - this.rightBack = new SwerveModule(rightBackWheel, rightBackSteer, rightBackEncoder); + this.leftFront = new SwerveModule(leftFrontWheel, leftFrontSteer, leftFrontEncoder, -181.230469); + this.rightFront = new SwerveModule(rightFrontWheel, rightFrontSteer, rightFrontEncoder, -270.615234); + this.leftBack = new SwerveModule(leftBackWheel, leftBackSteer, leftBackEncoder, -240.029297); + this.rightBack = new SwerveModule(rightBackWheel, rightBackSteer, rightBackEncoder, -40.869142); - - - // FINAL OFFSETS (I THINK) // LEFT FRONT: -181.230469 // RIGHT FRONT: -270.615234 // LEFT BACK: -240.029297 diff --git a/src/main/java/frc4388/robot/commands/DriveWithInput.java b/src/main/java/frc4388/robot/commands/DriveWithInput.java index 784536d..1fcaccc 100644 --- a/src/main/java/frc4388/robot/commands/DriveWithInput.java +++ b/src/main/java/frc4388/robot/commands/DriveWithInput.java @@ -57,7 +57,7 @@ public class DriveWithInput extends CommandBase { x = -xLimiter.calculate(MathUtil.applyDeadband(x * -0.3, 0.02) * Units.feetToMeters(SwerveDriveConstants.MAX_SPEED_FEET_PER_SECOND)); y = -yLimiter.calculate(MathUtil.applyDeadband(y * 0.3, 0.02) * Units.feetToMeters(SwerveDriveConstants.MAX_SPEED_FEET_PER_SECOND)); - r = -rotLimiter.calculate(MathUtil.applyDeadband(r * 0.3, 0.02) * Units.feetToMeters(Math.PI)); + r = -rotLimiter.calculate(MathUtil.applyDeadband(r * 0.3, 0.02) * Units.feetToMeters(5*Math.PI)); swerve.drive(x, y, r, fieldRelative); } diff --git a/src/main/java/frc4388/robot/subsystems/SwerveModule.java b/src/main/java/frc4388/robot/subsystems/SwerveModule.java index 95fdaa2..082991d 100644 --- a/src/main/java/frc4388/robot/subsystems/SwerveModule.java +++ b/src/main/java/frc4388/robot/subsystems/SwerveModule.java @@ -31,7 +31,7 @@ public class SwerveModule extends SubsystemBase { public static Gains swerveGains = SwerveDriveConstants.PIDConstants.SWERVE_GAINS; /** Creates a new SwerveModule. */ - public SwerveModule(WPI_TalonFX driveMotor, WPI_TalonFX angleMotor, CANCoder encoder) {//, double offset) { + public SwerveModule(WPI_TalonFX driveMotor, WPI_TalonFX angleMotor, CANCoder encoder, double offset) { this.driveMotor = driveMotor; this.angleMotor = angleMotor; this.encoder = encoder; @@ -47,9 +47,10 @@ public class SwerveModule extends SubsystemBase { angleConfig.primaryPID.selectedFeedbackSensor = FeedbackDevice.RemoteSensor0; angleMotor.configAllSettings(angleConfig); - CANCoderConfiguration canCoderConfig = new CANCoderConfiguration(); + // CANCoderConfiguration canCoderConfig = new CANCoderConfiguration(); // canCoderConfig.magnetOffsetDegrees = offset; - encoder.configAllSettings(canCoderConfig); + // encoder.configAllSettings(canCoderConfig); + encoder.configMagnetOffset(offset); // driveMotor.config_kP(0, 0.4);