Skip to content

Commit

Permalink
Merge pull request #35 from wildstang/main
Browse files Browse the repository at this point in the history
Stu's absolute encoder fixes
  • Loading branch information
fruzyna authored Jan 16, 2025
2 parents b080806 + c7e8811 commit ad48778
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,12 @@ public void initClosedLoop(double P, double I, double D, double FF){
* @param FF the feed forward constant
* @param absEncoder absolute encoder used to provided PID feedback
*/
public void initClosedLoop(double P, double I, double D, double FF, SparkAbsoluteEncoder absEncoder, boolean isEncoderFlipped){
public void initClosedLoop(double P, double I, double D, double FF, boolean isEncoderFlipped){
config.closedLoop.pidf(P, I, D, FF, ClosedLoopSlot.kSlot0);
absEncoderConfig.positionConversionFactor(360.0);
absEncoderConfig.velocityConversionFactor(360.0/60.0);
absEncoderConfig.inverted(isEncoderFlipped);
config.apply(absEncoderConfig);
config.closedLoop.feedbackSensor(FeedbackSensor.kAbsoluteEncoder);
config.closedLoop.positionWrappingEnabled(true);
config.closedLoop.positionWrappingMaxInput(360.0);
Expand All @@ -304,11 +305,12 @@ public void initClosedLoop(double P, double I, double D, double FF, SparkAbsolut
* @param absEncoder absolute encoder used to provided PID feedback
* @param isWrapped whether wrapping should be enabled
*/
public void initClosedLoop(double P, double I, double D, double FF, SparkAbsoluteEncoder absEncoder, boolean isEncoderFlipped, boolean isWrapped){
public void initClosedLoop(double P, double I, double D, double FF, boolean isEncoderFlipped, boolean isWrapped){
config.closedLoop.pidf(P, I, D, FF, ClosedLoopSlot.kSlot0);
absEncoderConfig.positionConversionFactor(360.0);
absEncoderConfig.velocityConversionFactor(360.0/60.0);
absEncoderConfig.inverted(isEncoderFlipped);
config.apply(absEncoderConfig);
config.closedLoop.feedbackSensor(FeedbackSensor.kAbsoluteEncoder);
config.closedLoop.positionWrappingEnabled(isWrapped);
config.closedLoop.positionWrappingMaxInput(360.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SwerveModule(WsSpark driveMotor, WsSpark angleMotor, double offset) {

//set up angle and drive with pid and kpid respectively
driveMotor.initClosedLoop(DriveConstants.DRIVE_P, DriveConstants.DRIVE_I, DriveConstants.DRIVE_D, 0);
angleMotor.initClosedLoop(DriveConstants.ANGLE_P, DriveConstants.ANGLE_I, DriveConstants.ANGLE_D, 0, this.absEncoder, true);
angleMotor.initClosedLoop(DriveConstants.ANGLE_P, DriveConstants.ANGLE_I, DriveConstants.ANGLE_D, 0, true);

driveMotor.setCurrentLimit(DriveConstants.DRIVE_CURRENT_LIMIT, DriveConstants.DRIVE_CURRENT_LIMIT, 0);
angleMotor.setCurrentLimit(DriveConstants.ANGLE_CURRENT_LIMIT, DriveConstants.ANGLE_CURRENT_LIMIT, 0);
Expand Down

0 comments on commit ad48778

Please sign in to comment.