-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package frc.lib.util.swerve; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
import com.ctre.phoenix.motorcontrol.ControlMode; | ||
import com.ctre.phoenix.motorcontrol.DemandType; | ||
|
||
public interface SwerveModuleIO { | ||
Check warning on line 7 in src/main/java/frc/lib/util/swerve/SwerveModuleIO.java GitHub Actions / testtool[testtool] src/main/java/frc/lib/util/swerve/SwerveModuleIO.java#L7 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
|
||
@AutoLog | ||
Check warning on line 9 in src/main/java/frc/lib/util/swerve/SwerveModuleIO.java GitHub Actions / testtool[testtool] src/main/java/frc/lib/util/swerve/SwerveModuleIO.java#L9 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
public static class SwerveModuleInputs { | ||
public double angleEncoderValue; | ||
public double driveMotorSelectedPosition; | ||
public double driveMotorSelectedSensorVelocity; | ||
public double angleMotorSelectedPosition; | ||
} | ||
|
||
public default void updateInputs(SwerveModuleInputs inputs) {} | ||
|
||
public default void setDriveMotor(ControlMode mode, double outputValue) { | ||
|
||
} | ||
|
||
public default void setDriveMotorWithFF(ControlMode mode, double demand0, | ||
DemandType demand1Type, double demand1) {} | ||
|
||
public default void setAngleMotor(ControlMode mode, double outputValue) {} | ||
|
||
public default void setAngleSelectedSensorPosition(double angle) {} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package frc.lib.util.swerve; | ||
|
||
import com.ctre.phoenix.motorcontrol.ControlMode; | ||
import com.ctre.phoenix.motorcontrol.DemandType; | ||
import com.ctre.phoenix.motorcontrol.can.TalonFX; | ||
import com.ctre.phoenix.sensors.CANCoder; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import frc.lib.math.Conversions; | ||
import frc.robot.Constants; | ||
import frc.robot.Robot; | ||
|
||
public class SwerveModuleReal implements SwerveModuleIO { | ||
Check warning on line 12 in src/main/java/frc/lib/util/swerve/SwerveModuleReal.java GitHub Actions / testtool[testtool] src/main/java/frc/lib/util/swerve/SwerveModuleReal.java#L12 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck>
Raw output
|
||
|
||
private TalonFX angleMotor; // Output | ||
private TalonFX driveMotor; // Output | ||
private CANCoder angleEncoder; // Input | ||
|
||
private SwerveModuleConstants constants; | ||
|
||
public SwerveModuleReal(SwerveModuleConstants constants) { | ||
Check warning on line 20 in src/main/java/frc/lib/util/swerve/SwerveModuleReal.java GitHub Actions / testtool[testtool] src/main/java/frc/lib/util/swerve/SwerveModuleReal.java#L20 <com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck>
Raw output
|
||
this.constants = constants; | ||
|
||
/* Angle Encoder Config */ | ||
angleEncoder = new CANCoder(constants.cancoderID, "canivore"); | ||
configAngleEncoder(); | ||
|
||
/* Angle Motor Config */ | ||
angleMotor = new TalonFX(constants.angleMotorID, "canivore"); | ||
configAngleMotor(); | ||
|
||
/* Drive Motor Config */ | ||
driveMotor = new TalonFX(constants.driveMotorID, "canivore"); | ||
configDriveMotor(); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
private void resetToAbsolute() { | ||
double absolutePosition = Conversions | ||
.degreesToFalcon(Rotation2d.fromDegrees(angleEncoder.getAbsolutePosition()).getDegrees() | ||
- constants.angleOffset, Constants.Swerve.ANGLE_GEAR_RATIO); | ||
angleMotor.setSelectedSensorPosition(absolutePosition); | ||
} | ||
|
||
/** | ||
* Configure the Angle motor CANCoder | ||
*/ | ||
private void configAngleEncoder() { | ||
angleEncoder.configFactoryDefault(); | ||
angleEncoder.configAllSettings(Robot.ctreConfigs.swerveCanCoderConfig); | ||
} | ||
|
||
/** | ||
* Configure the Angle motor | ||
*/ | ||
private void configAngleMotor() { | ||
angleMotor.configFactoryDefault(); | ||
angleMotor.configAllSettings(Robot.ctreConfigs.swerveAngleFXConfig); | ||
angleMotor.setInverted(Constants.Swerve.ANGLE_MOTOT_INVERT); | ||
angleMotor.setNeutralMode(Constants.Swerve.ANGLE_NEUTRAL_MODE); | ||
resetToAbsolute(); | ||
} | ||
|
||
/** | ||
* Configure the Drive motor | ||
*/ | ||
private void configDriveMotor() { | ||
driveMotor.configFactoryDefault(); | ||
driveMotor.configAllSettings(Robot.ctreConfigs.swerveDriveFXConfig); | ||
driveMotor.setInverted(Constants.Swerve.DRIVE_MOTOR_INVERT); | ||
driveMotor.setNeutralMode(Constants.Swerve.DRIVE_NEUTRAL_MODE); | ||
driveMotor.setSelectedSensorPosition(0); | ||
} | ||
|
||
@Override | ||
public void updateInputs(SwerveModuleInputs inputs) { | ||
inputs.angleEncoderValue = angleEncoder.getAbsolutePosition(); | ||
inputs.angleMotorSelectedPosition = angleMotor.getSelectedSensorPosition(); | ||
inputs.driveMotorSelectedPosition = driveMotor.getSelectedSensorPosition(); | ||
inputs.driveMotorSelectedSensorVelocity = driveMotor.getSelectedSensorVelocity(); | ||
} | ||
|
||
@Override | ||
public void setAngleMotor(ControlMode mode, double outputValue) { | ||
angleMotor.set(mode, outputValue); | ||
} | ||
|
||
@Override | ||
public void setAngleSelectedSensorPosition(double angle) { | ||
angleMotor.setSelectedSensorPosition(angle); | ||
} | ||
|
||
@Override | ||
public void setDriveMotor(ControlMode mode, double outputValue) { | ||
driveMotor.set(mode, outputValue); | ||
} | ||
|
||
@Override | ||
public void setDriveMotorWithFF(ControlMode mode, double demand0, DemandType demand1Type, | ||
double demand1) { | ||
driveMotor.set(mode, demand0, demand1Type, demand1); | ||
} | ||
|
||
} |