From e2d9168bba4830a67a864f9127d15c7670339699 Mon Sep 17 00:00:00 2001 From: Colin Wong Date: Sat, 5 Feb 2022 21:26:58 -0600 Subject: [PATCH] Expose motors and steer encoders Fix #3, fix #4 --- .../swervelib/DriveController.java | 2 ++ .../swervelib/Mk3SwerveModuleHelper.java | 4 +--- .../swervelib/Mk4SwerveModuleHelper.java | 4 +--- .../swervelib/SteerController.java | 4 ++++ .../swervelib/SwerveModule.java | 6 ++++++ .../swervelib/SwerveModuleFactory.java | 15 +++++++++++++++ .../Falcon500DriveControllerFactoryBuilder.java | 5 +++++ .../Falcon500SteerControllerFactoryBuilder.java | 10 ++++++++++ .../rev/NeoDriveControllerFactoryBuilder.java | 5 +++++ .../rev/NeoSteerControllerFactoryBuilder.java | 12 +++++++++++- 10 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/swervedrivespecialties/swervelib/DriveController.java b/src/main/java/com/swervedrivespecialties/swervelib/DriveController.java index 82d3f789..998786f2 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/DriveController.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/DriveController.java @@ -1,6 +1,8 @@ package com.swervedrivespecialties.swervelib; public interface DriveController { + Object getDriveMotor(); + void setReferenceVoltage(double voltage); double getStateVelocity(); diff --git a/src/main/java/com/swervedrivespecialties/swervelib/Mk3SwerveModuleHelper.java b/src/main/java/com/swervedrivespecialties/swervelib/Mk3SwerveModuleHelper.java index 0cb38e88..6e4fe6c5 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/Mk3SwerveModuleHelper.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/Mk3SwerveModuleHelper.java @@ -1,9 +1,7 @@ package com.swervedrivespecialties.swervelib; import com.swervedrivespecialties.swervelib.ctre.*; -import com.swervedrivespecialties.swervelib.rev.NeoDriveControllerFactoryBuilder; -import com.swervedrivespecialties.swervelib.rev.NeoSteerConfiguration; -import com.swervedrivespecialties.swervelib.rev.NeoSteerControllerFactoryBuilder; +import com.swervedrivespecialties.swervelib.rev.*; import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; public final class Mk3SwerveModuleHelper { diff --git a/src/main/java/com/swervedrivespecialties/swervelib/Mk4SwerveModuleHelper.java b/src/main/java/com/swervedrivespecialties/swervelib/Mk4SwerveModuleHelper.java index 8086b760..8e64b9eb 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/Mk4SwerveModuleHelper.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/Mk4SwerveModuleHelper.java @@ -1,9 +1,7 @@ package com.swervedrivespecialties.swervelib; import com.swervedrivespecialties.swervelib.ctre.*; -import com.swervedrivespecialties.swervelib.rev.NeoDriveControllerFactoryBuilder; -import com.swervedrivespecialties.swervelib.rev.NeoSteerConfiguration; -import com.swervedrivespecialties.swervelib.rev.NeoSteerControllerFactoryBuilder; +import com.swervedrivespecialties.swervelib.rev.*; import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardLayout; public final class Mk4SwerveModuleHelper { diff --git a/src/main/java/com/swervedrivespecialties/swervelib/SteerController.java b/src/main/java/com/swervedrivespecialties/swervelib/SteerController.java index f3570df4..ebea5906 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/SteerController.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/SteerController.java @@ -1,6 +1,10 @@ package com.swervedrivespecialties.swervelib; public interface SteerController { + Object getSteerMotor(); + + AbsoluteEncoder getSteerEncoder(); + double getReferenceAngle(); void setReferenceAngle(double referenceAngleRadians); diff --git a/src/main/java/com/swervedrivespecialties/swervelib/SwerveModule.java b/src/main/java/com/swervedrivespecialties/swervelib/SwerveModule.java index 85aabe40..e5761194 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/SwerveModule.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/SwerveModule.java @@ -1,6 +1,12 @@ package com.swervedrivespecialties.swervelib; public interface SwerveModule { + Object getDriveMotor(); + + Object getSteerMotor(); + + AbsoluteEncoder getSteerEncoder(); + double getDriveVelocity(); double getSteerAngle(); diff --git a/src/main/java/com/swervedrivespecialties/swervelib/SwerveModuleFactory.java b/src/main/java/com/swervedrivespecialties/swervelib/SwerveModuleFactory.java index 097761d9..959e5de3 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/SwerveModuleFactory.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/SwerveModuleFactory.java @@ -46,6 +46,21 @@ private ModuleImplementation(DriveController driveController, SteerController st this.steerController = steerController; } + @Override + public Object getDriveMotor() { + return driveController.getDriveMotor(); + } + + @Override + public Object getSteerMotor() { + return steerController.getSteerMotor(); + } + + @Override + public AbsoluteEncoder getSteerEncoder() { + return steerController.getSteerEncoder(); + } + @Override public double getDriveVelocity() { return driveController.getStateVelocity(); diff --git a/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500DriveControllerFactoryBuilder.java b/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500DriveControllerFactoryBuilder.java index 2e118abe..8fa548a9 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500DriveControllerFactoryBuilder.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500DriveControllerFactoryBuilder.java @@ -95,6 +95,11 @@ private ControllerImplementation(TalonFX motor, double sensorVelocityCoefficient this.sensorVelocityCoefficient = sensorVelocityCoefficient; } + @Override + public Object getDriveMotor() { + return this.motor; + } + @Override public void setReferenceVoltage(double voltage) { motor.set(TalonFXControlMode.PercentOutput, voltage / nominalVoltage); diff --git a/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500SteerControllerFactoryBuilder.java b/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500SteerControllerFactoryBuilder.java index 0bf6d2ae..fb9d3f37 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500SteerControllerFactoryBuilder.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/ctre/Falcon500SteerControllerFactoryBuilder.java @@ -172,6 +172,16 @@ private ControllerImplementation(TalonFX motor, this.absoluteEncoder = absoluteEncoder; } + @Override + public Object getSteerMotor() { + return this.motor; + } + + @Override + public AbsoluteEncoder getSteerEncoder() { + return this.absoluteEncoder; + } + @Override public double getReferenceAngle() { return referenceAngleRadians; diff --git a/src/main/java/com/swervedrivespecialties/swervelib/rev/NeoDriveControllerFactoryBuilder.java b/src/main/java/com/swervedrivespecialties/swervelib/rev/NeoDriveControllerFactoryBuilder.java index a89a8c40..f015fd3f 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/rev/NeoDriveControllerFactoryBuilder.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/rev/NeoDriveControllerFactoryBuilder.java @@ -75,6 +75,11 @@ private ControllerImplementation(CANSparkMax motor, RelativeEncoder encoder) { this.encoder = encoder; } + @Override + public Object getDriveMotor() { + return this.motor; + } + @Override public void setReferenceVoltage(double voltage) { motor.setVoltage(voltage); diff --git a/src/main/java/com/swervedrivespecialties/swervelib/rev/NeoSteerControllerFactoryBuilder.java b/src/main/java/com/swervedrivespecialties/swervelib/rev/NeoSteerControllerFactoryBuilder.java index 41e6fa63..ecdb4ca8 100644 --- a/src/main/java/com/swervedrivespecialties/swervelib/rev/NeoSteerControllerFactoryBuilder.java +++ b/src/main/java/com/swervedrivespecialties/swervelib/rev/NeoSteerControllerFactoryBuilder.java @@ -99,7 +99,7 @@ public static class ControllerImplementation implements SteerController { private static final int ENCODER_RESET_ITERATIONS = 500; private static final double ENCODER_RESET_MAX_ANGULAR_VELOCITY = Math.toRadians(0.5); - @SuppressWarnings({"FieldCanBeLocal", "unused"}) + @SuppressWarnings("FieldCanBeLocal") private final CANSparkMax motor; private final SparkMaxPIDController controller; private final RelativeEncoder motorEncoder; @@ -116,6 +116,16 @@ public ControllerImplementation(CANSparkMax motor, AbsoluteEncoder absoluteEncod this.absoluteEncoder = absoluteEncoder; } + @Override + public Object getSteerMotor() { + return this.motor; + } + + @Override + public AbsoluteEncoder getSteerEncoder() { + return this.absoluteEncoder; + } + @Override public double getReferenceAngle() { return referenceAngleRadians;