Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion XRPLib/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Encoder:
_counts_per_motor_shaft_revolution = 12
resolution = _counts_per_motor_shaft_revolution * _gear_ratio # 585

def __init__(self, index, encAPin: int|str, encBPin: int|str):
def __init__(self, index, encAPin: int|str, encBPin: int|str, flip_dir:bool=False):
"""
Uses the on board PIO State Machine to keep track of encoder positions.
Only 4 encoders can be instantiated this way.
Expand All @@ -28,6 +28,7 @@ def __init__(self, index, encAPin: int|str, encBPin: int|str):
self.sm = rp2.StateMachine(index, self._encoder, in_base=basePin)
self.reset_encoder_position()
self.sm.active(1)
self.flip_dir = flip_dir

def reset_encoder_position(self):
"""
Expand All @@ -52,6 +53,10 @@ def get_position_counts(self):
counts = self.sm.get()
if(counts > 2**31):
counts -= 2**32

if self.flip_dir:
counts *= -1

return counts

def get_position(self):
Expand Down