Implement a turn counter for wrap-around rotary encoders

This commit is contained in:
Douglas Clowes
2014-05-20 12:26:44 +10:00
parent 1a28faabbf
commit 4f7fe09f35
2 changed files with 143 additions and 79 deletions

View File

@@ -32,6 +32,7 @@ class GalilMotor(object):
self.stopCallback = None
self.moveCallback = None
self.trace = False
self.rotary_bits = 0
def doTrace(self, arg):
print "Trace %s: %s" % (self.axis, arg),
@@ -80,6 +81,9 @@ class GalilMotor(object):
elif lh == "NAM":
self.name = rh[1:-1]
self.configDone = True
elif lh == "ROT":
self.rotary_bits = int(rh)
self.configDone = True
else:
print "Unrecognized config item \"%s\" in \"%s\"" % (lh, arg)
if self.configDone and not configDoneAlready:
@@ -228,6 +232,8 @@ class GalilMotor(object):
response = self.getPosition()
elif arg == "TP":
response = self.getEncoder()
if self.rotary_bits > 0:
response = response & ((1 << self.rotary_bits) - 1)
elif arg == "SP":
response = self.speed
elif arg == "AC":