From 700eb54e524f8a38ee8bc2a97480bad87b5eea78 Mon Sep 17 00:00:00 2001 From: T Grinch <10247070+thenetworkgrinch@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:23:06 -0600 Subject: [PATCH 1/3] Update vendordeps. Signed-off-by: thenetworkgrinch --- vendordeps/PathplannerLib.json | 6 +++--- vendordeps/Phoenix5.json | 22 +++++++++++----------- vendordeps/REVLib.json | 10 +++++----- vendordeps/photonlib.json | 10 +++++----- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/vendordeps/PathplannerLib.json b/vendordeps/PathplannerLib.json index ff15fab4..787450f4 100644 --- a/vendordeps/PathplannerLib.json +++ b/vendordeps/PathplannerLib.json @@ -1,7 +1,7 @@ { "fileName": "PathplannerLib.json", "name": "PathplannerLib", - "version": "2024.2.3", + "version": "2024.2.4", "uuid": "1b42324f-17c6-4875-8e77-1c312bc8c786", "frcYear": "2024", "mavenUrls": [ @@ -12,7 +12,7 @@ { "groupId": "com.pathplanner.lib", "artifactId": "PathplannerLib-java", - "version": "2024.2.3" + "version": "2024.2.4" } ], "jniDependencies": [], @@ -20,7 +20,7 @@ { "groupId": "com.pathplanner.lib", "artifactId": "PathplannerLib-cpp", - "version": "2024.2.3", + "version": "2024.2.4", "libName": "PathplannerLib", "headerClassifier": "headers", "sharedLibrary": false, diff --git a/vendordeps/Phoenix5.json b/vendordeps/Phoenix5.json index 88a68dd0..ff7359e1 100644 --- a/vendordeps/Phoenix5.json +++ b/vendordeps/Phoenix5.json @@ -1,7 +1,7 @@ { "fileName": "Phoenix5.json", "name": "CTRE-Phoenix (v5)", - "version": "5.33.0", + "version": "5.33.1", "frcYear": 2024, "uuid": "ab676553-b602-441f-a38d-f1296eff6537", "mavenUrls": [ @@ -20,19 +20,19 @@ { "groupId": "com.ctre.phoenix", "artifactId": "api-java", - "version": "5.33.0" + "version": "5.33.1" }, { "groupId": "com.ctre.phoenix", "artifactId": "wpiapi-java", - "version": "5.33.0" + "version": "5.33.1" } ], "jniDependencies": [ { "groupId": "com.ctre.phoenix", "artifactId": "cci", - "version": "5.33.0", + "version": "5.33.1", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -45,7 +45,7 @@ { "groupId": "com.ctre.phoenix.sim", "artifactId": "cci-sim", - "version": "5.33.0", + "version": "5.33.1", "isJar": false, "skipInvalidPlatforms": true, "validPlatforms": [ @@ -60,7 +60,7 @@ { "groupId": "com.ctre.phoenix", "artifactId": "wpiapi-cpp", - "version": "5.33.0", + "version": "5.33.1", "libName": "CTRE_Phoenix_WPI", "headerClassifier": "headers", "sharedLibrary": true, @@ -75,7 +75,7 @@ { "groupId": "com.ctre.phoenix", "artifactId": "api-cpp", - "version": "5.33.0", + "version": "5.33.1", "libName": "CTRE_Phoenix", "headerClassifier": "headers", "sharedLibrary": true, @@ -90,7 +90,7 @@ { "groupId": "com.ctre.phoenix", "artifactId": "cci", - "version": "5.33.0", + "version": "5.33.1", "libName": "CTRE_PhoenixCCI", "headerClassifier": "headers", "sharedLibrary": true, @@ -105,7 +105,7 @@ { "groupId": "com.ctre.phoenix.sim", "artifactId": "wpiapi-cpp-sim", - "version": "5.33.0", + "version": "5.33.1", "libName": "CTRE_Phoenix_WPISim", "headerClassifier": "headers", "sharedLibrary": true, @@ -120,7 +120,7 @@ { "groupId": "com.ctre.phoenix.sim", "artifactId": "api-cpp-sim", - "version": "5.33.0", + "version": "5.33.1", "libName": "CTRE_PhoenixSim", "headerClassifier": "headers", "sharedLibrary": true, @@ -135,7 +135,7 @@ { "groupId": "com.ctre.phoenix.sim", "artifactId": "cci-sim", - "version": "5.33.0", + "version": "5.33.1", "libName": "CTRE_PhoenixCCISim", "headerClassifier": "headers", "sharedLibrary": true, diff --git a/vendordeps/REVLib.json b/vendordeps/REVLib.json index a8295814..60eacf84 100644 --- a/vendordeps/REVLib.json +++ b/vendordeps/REVLib.json @@ -1,7 +1,7 @@ { "fileName": "REVLib.json", "name": "REVLib", - "version": "2024.2.1", + "version": "2024.2.3", "frcYear": "2024", "uuid": "3f48eb8c-50fe-43a6-9cb7-44c86353c4cb", "mavenUrls": [ @@ -12,14 +12,14 @@ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-java", - "version": "2024.2.1" + "version": "2024.2.3" } ], "jniDependencies": [ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-driver", - "version": "2024.2.1", + "version": "2024.2.3", "skipInvalidPlatforms": true, "isJar": false, "validPlatforms": [ @@ -37,7 +37,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-cpp", - "version": "2024.2.1", + "version": "2024.2.3", "libName": "REVLib", "headerClassifier": "headers", "sharedLibrary": false, @@ -55,7 +55,7 @@ { "groupId": "com.revrobotics.frc", "artifactId": "REVLib-driver", - "version": "2024.2.1", + "version": "2024.2.3", "libName": "REVLibDriver", "headerClassifier": "headers", "sharedLibrary": false, diff --git a/vendordeps/photonlib.json b/vendordeps/photonlib.json index 8b1044d3..8c565032 100644 --- a/vendordeps/photonlib.json +++ b/vendordeps/photonlib.json @@ -1,7 +1,7 @@ { "fileName": "photonlib.json", "name": "photonlib", - "version": "v2024.2.6", + "version": "v2024.2.8", "uuid": "515fe07e-bfc6-11fa-b3de-0242ac130004", "frcYear": "2024", "mavenUrls": [ @@ -14,7 +14,7 @@ { "groupId": "org.photonvision", "artifactId": "photonlib-cpp", - "version": "v2024.2.6", + "version": "v2024.2.8", "libName": "photonlib", "headerClassifier": "headers", "sharedLibrary": true, @@ -29,7 +29,7 @@ { "groupId": "org.photonvision", "artifactId": "photontargeting-cpp", - "version": "v2024.2.6", + "version": "v2024.2.8", "libName": "photontargeting", "headerClassifier": "headers", "sharedLibrary": true, @@ -46,12 +46,12 @@ { "groupId": "org.photonvision", "artifactId": "photonlib-java", - "version": "v2024.2.6" + "version": "v2024.2.8" }, { "groupId": "org.photonvision", "artifactId": "photontargeting-java", - "version": "v2024.2.6" + "version": "v2024.2.8" } ] } \ No newline at end of file From 504e1136ed231de4380e061edf199bbb0fc0e5f1 Mon Sep 17 00:00:00 2001 From: T Grinch <10247070+thenetworkgrinch@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:20:28 -0600 Subject: [PATCH 2/3] Address issue #159 and #166 by adding new PIDF helper functions, and optional anti jitter functions. Signed-off-by: thenetworkgrinch --- src/main/java/swervelib/SwerveDrive.java | 16 ++-- src/main/java/swervelib/SwerveModule.java | 89 +++++++++++++++++++++-- 2 files changed, 90 insertions(+), 15 deletions(-) diff --git a/src/main/java/swervelib/SwerveDrive.java b/src/main/java/swervelib/SwerveDrive.java index a99f880c..98c2f5c9 100644 --- a/src/main/java/swervelib/SwerveDrive.java +++ b/src/main/java/swervelib/SwerveDrive.java @@ -839,9 +839,9 @@ public void setMaximumSpeed(double maximumSpeed, boolean updateModuleFeedforward module.maxSpeed = maximumSpeed; if (updateModuleFeedforward) { - module.feedforward = SwerveMath.createDriveFeedforward(optimalVoltage, - maximumSpeed, - swerveDriveConfiguration.physicalCharacteristics.wheelGripCoefficientOfFriction); + module.setFeedforward(SwerveMath.createDriveFeedforward(optimalVoltage, + maximumSpeed, + swerveDriveConfiguration.physicalCharacteristics.wheelGripCoefficientOfFriction)); } } } @@ -851,7 +851,7 @@ public void setMaximumSpeed(double maximumSpeed, boolean updateModuleFeedforward * {@link SwerveDrive#setRawModuleStates(SwerveModuleState[], boolean)} function and * {@link SwerveController#getTargetSpeeds(double, double, double, double, double)} functions. This function overrides * what was placed in the JSON and could damage your motor/robot if set too high or unachievable rates. Overwrites the - * {@link SwerveModule#feedforward}. + * {@link SwerveModule#setFeedforward(SimpleMotorFeedforward)}. * * @param maximumSpeed Maximum speed for the drive motors in meters / second. */ @@ -908,13 +908,13 @@ public Pose2d[] getSwerveModulePoses(Pose2d robotPose) /** * Setup the swerve module feedforward. * - * @param feedforward Feedforward for the drive motor on swerve modules. + * @param driveFeedforward Feedforward for the drive motor on swerve modules. */ - public void replaceSwerveModuleFeedforward(SimpleMotorFeedforward feedforward) + public void replaceSwerveModuleFeedforward(SimpleMotorFeedforward driveFeedforward) { for (SwerveModule swerveModule : swerveModules) { - swerveModule.feedforward = feedforward; + swerveModule.setFeedforward(driveFeedforward); } } @@ -1114,7 +1114,7 @@ public void resetDriveEncoders() { for (SwerveModule module : swerveModules) { - module.configuration.driveMotor.setPosition(0); + module.getDriveMotor().setPosition(0); } } diff --git a/src/main/java/swervelib/SwerveModule.java b/src/main/java/swervelib/SwerveModule.java index 0957211e..61bb5914 100644 --- a/src/main/java/swervelib/SwerveModule.java +++ b/src/main/java/swervelib/SwerveModule.java @@ -9,6 +9,7 @@ import swervelib.math.SwerveMath; import swervelib.motors.SwerveMotor; import swervelib.parser.Cache; +import swervelib.parser.PIDFConfig; import swervelib.parser.SwerveModuleConfiguration; import swervelib.simulation.SwerveModuleSimulation; import swervelib.telemetry.Alert; @@ -78,13 +79,17 @@ public class SwerveModule */ public int moduleNumber; /** - * Feedforward for drive motor during closed loop control. + * Feedforward for the drive motor during closed loop control. */ - public SimpleMotorFeedforward feedforward; + private SimpleMotorFeedforward driveMotorFeedforward; /** * Maximum speed of the drive motors in meters per second. */ public double maxSpeed; + /** + * Anti-Jitter AKA auto-centering disabled. + */ + private boolean antiJitterEnabled = true; /** * Last swerve module state applied. */ @@ -122,8 +127,8 @@ public SwerveModule(int moduleNumber, SwerveModuleConfiguration moduleConfigurat configuration = moduleConfiguration; angleOffset = moduleConfiguration.angleOffset; - // Initialize Feedforward for drive motor. - feedforward = driveFeedforward; + // Initialize Feedforwards. + driveMotorFeedforward = driveFeedforward; // Create motors from configuration and reset them to defaults. angleMotor = moduleConfiguration.angleMotor; @@ -236,6 +241,76 @@ public void queueSynchronizeEncoders() } } + /** + * Set the antiJitter functionality, if true the modules will NOT auto center. Pushes the offsets to the angle motor + * controllers as well. + * + * @param antiJitter Anti-Jitter state desired. + */ + public void setAntiJitter(boolean antiJitter) + { + this.antiJitterEnabled = antiJitter; + if (antiJitter) + { + pushOffsetsToControllers(); + } else + { + restoreInternalOffset(); + } + } + + /** + * Set the feedforward attributes to the given parameters. + * + * @param drive Drive motor feedforward for the module. + */ + public void setFeedforward(SimpleMotorFeedforward drive) + { + this.driveMotorFeedforward = drive; + } + + /** + * Set the drive PIDF values. + * + * @param config {@link PIDFConfig} of that should be set. + */ + public void setDrivePIDF(PIDFConfig config) + { + configuration.velocityPIDF = config; + driveMotor.configurePIDF(config); + } + + /** + * Get the current drive motor PIDF values. + * + * @return {@link PIDFConfig} of the drive motor. + */ + public PIDFConfig getDrivePIDF() + { + return configuration.velocityPIDF; + } + + /** + * Set the angle/azimuth/steering motor PID + * + * @param config {@link PIDFConfig} of that should be set. + */ + public void setAnglePIDF(PIDFConfig config) + { + configuration.anglePIDF = config; + angleMotor.configurePIDF(config); + } + + /** + * Get the current angle/azimuth/steering motor PIDF values. + * + * @return {@link PIDFConfig} of the angle motor. + */ + public PIDFConfig getAnglePIDF() + { + return configuration.anglePIDF; + } + /** * Set the desired state of the swerve module.
WARNING: If you are not using one of the functions from * {@link SwerveDrive} you may screw up {@link SwerveDrive#kinematics} @@ -250,7 +325,7 @@ public void setDesiredState(SwerveModuleState desiredState, boolean isOpenLoop, desiredState = SwerveModuleState.optimize(desiredState, Rotation2d.fromDegrees(getAbsolutePosition())); // If we are forcing the angle - if (!force) + if (!force && antiJitterEnabled) { // Prevents module rotation if speed is less than 1% SwerveMath.antiJitter(desiredState, lastState, Math.min(maxSpeed, 4)); @@ -267,7 +342,7 @@ public void setDesiredState(SwerveModuleState desiredState, boolean isOpenLoop, driveMotor.set(percentOutput); } else { - driveMotor.setReference(velocity, feedforward.calculate(velocity)); + driveMotor.setReference(velocity, driveMotorFeedforward.calculate(velocity)); desiredState.speedMetersPerSecond = velocity; } @@ -507,7 +582,7 @@ public SwerveModuleConfiguration getConfiguration() */ public void pushOffsetsToControllers() { - if (absoluteEncoder != null) + if (absoluteEncoder != null && angleOffset == configuration.angleOffset) { if (absoluteEncoder.setAbsoluteEncoderOffset(angleOffset)) { From 425b4213b28d3a093ec748ef77aea46d2cee68fe Mon Sep 17 00:00:00 2001 From: T Grinch <10247070+thenetworkgrinch@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:13:11 -0600 Subject: [PATCH 3/3] Fixed negations. Signed-off-by: thenetworkgrinch --- src/main/java/frc/robot/RobotContainer.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 22dd9a88..55bb75ae 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -60,10 +60,10 @@ public RobotContainer() // left stick controls translation // right stick controls the desired angle NOT angular rotation Command driveFieldOrientedDirectAngle = drivebase.driveCommand( - () -> -MathUtil.applyDeadband(driverXbox.getLeftY(), OperatorConstants.LEFT_Y_DEADBAND), - () -> -MathUtil.applyDeadband(driverXbox.getLeftX(), OperatorConstants.LEFT_X_DEADBAND), - () -> -driverXbox.getRightX(), - () -> -driverXbox.getRightY()); + () -> MathUtil.applyDeadband(driverXbox.getLeftY(), OperatorConstants.LEFT_Y_DEADBAND), + () -> MathUtil.applyDeadband(driverXbox.getLeftX(), OperatorConstants.LEFT_X_DEADBAND), + () -> driverXbox.getRightX(), + () -> driverXbox.getRightY()); // Applies deadbands and inverts controls because joysticks // are back-right positive while robot @@ -71,14 +71,14 @@ public RobotContainer() // left stick controls translation // right stick controls the angular velocity of the robot Command driveFieldOrientedAnglularVelocity = drivebase.driveCommand( - () -> -MathUtil.applyDeadband(driverXbox.getLeftY(), OperatorConstants.LEFT_Y_DEADBAND), - () -> -MathUtil.applyDeadband(driverXbox.getLeftX(), OperatorConstants.LEFT_X_DEADBAND), - () -> -driverXbox.getRightX()); + () -> MathUtil.applyDeadband(driverXbox.getLeftY(), OperatorConstants.LEFT_Y_DEADBAND), + () -> MathUtil.applyDeadband(driverXbox.getLeftX(), OperatorConstants.LEFT_X_DEADBAND), + () -> driverXbox.getRightX() * 0.5); Command driveFieldOrientedDirectAngleSim = drivebase.simDriveCommand( - () -> -MathUtil.applyDeadband(driverXbox.getLeftY(), OperatorConstants.LEFT_Y_DEADBAND), - () -> -MathUtil.applyDeadband(driverXbox.getLeftX(), OperatorConstants.LEFT_X_DEADBAND), - () -> -driverXbox.getRawAxis(2)); + () -> MathUtil.applyDeadband(driverXbox.getLeftY(), OperatorConstants.LEFT_Y_DEADBAND), + () -> MathUtil.applyDeadband(driverXbox.getLeftX(), OperatorConstants.LEFT_X_DEADBAND), + () -> driverXbox.getRawAxis(2)); drivebase.setDefaultCommand( !RobotBase.isSimulation() ? driveFieldOrientedDirectAngle : driveFieldOrientedDirectAngleSim);