Skip to content

Commit

Permalink
ChopShop wrapper for analog encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Finn6360 committed Jan 2, 2025
1 parent a647999 commit 9141f41
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.chopshop166.chopshoplib.sensors;

import edu.wpi.first.wpilibj.AnalogEncoder;

// Wrapper class for AnalogEncoder implementing IAbsolutePosition interface
public class CSAnalogEncoder extends AnalogEncoder implements IAbsolutePosition {
private double offset;

// Constructor that initializes the AnalogEncoder with the specified channel
public CSAnalogEncoder(final int channel) {
super(channel);
}

public CSAnalogEncoder(final int channel, final double distancePerRotation) {
super(channel);
setDistancePerRotation(distancePerRotation);
}

public CSAnalogEncoder(final int channel, final double distancePerRotation,
final double offset) {
super(channel);
setDistancePerRotation(distancePerRotation);
setOffset(offset);
}

// Override method to get the absolute position from the encoder
@Override
public double getAbsolutePosition() {
return get() + offset;
}

// Method to set the offset
public void setOffset(double offset) {
this.offset = offset;
}
}

0 comments on commit 9141f41

Please sign in to comment.