forked from chopshop-166/chopshoplib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
core/src/main/java/com/chopshop166/chopshoplib/sensors/CSAnalogEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |