update phytron driver
offset as storage only (after current draft specs) Change-Id: I1a005f149a8bd562124e2d40e49416957f66e851
This commit is contained in:
parent
3099c813d1
commit
c46947afd4
@ -43,8 +43,7 @@ class PhytronIO(StringIO):
|
|||||||
_, _, reply = super().communicate('\x02' + command).partition('\x02')
|
_, _, reply = super().communicate('\x02' + command).partition('\x02')
|
||||||
if reply[0] == '\x06': # ACK
|
if reply[0] == '\x06': # ACK
|
||||||
break
|
break
|
||||||
raise CommunicationFailedError('missing ACK %r (cmd: %r)'
|
raise CommunicationFailedError(f'missing ACK {reply!r} (cmd: {command!r})')
|
||||||
% (reply, command))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if itry < ntry - 1:
|
if itry < ntry - 1:
|
||||||
warn = e
|
warn = e
|
||||||
@ -70,13 +69,13 @@ class Motor(HasOffset, PersistentMixin, HasIO, Drivable):
|
|||||||
encoder_tolerance = Parameter('', FloatRange(unit='deg'), readonly=False, default=0.01)
|
encoder_tolerance = Parameter('', FloatRange(unit='deg'), readonly=False, default=0.01)
|
||||||
sign = PersistentParam('', IntRange(-1,1), readonly=False, default=1)
|
sign = PersistentParam('', IntRange(-1,1), readonly=False, default=1)
|
||||||
encoder = Parameter('encoder reading', FloatRange(unit='deg'))
|
encoder = Parameter('encoder reading', FloatRange(unit='deg'))
|
||||||
backlash = Parameter("""backlash compensation\n
|
backlash = PersistentParam("""backlash compensation\n
|
||||||
offset for always approaching from the same side""",
|
offset for always approaching from the same side""",
|
||||||
FloatRange(unit='deg'), readonly=False, default=0)
|
FloatRange(unit='deg'), readonly=False, default=0)
|
||||||
target_min = Limit()
|
target_min = Limit()
|
||||||
target_max = Limit()
|
target_max = Limit()
|
||||||
alive_time = PersistentParam('alive time for detecting restarts',
|
alive_time = PersistentParam('alive time for detecting restarts',
|
||||||
FloatRange(), default=0) # export=False
|
FloatRange(), default=0, export=False)
|
||||||
|
|
||||||
ioClass = PhytronIO
|
ioClass = PhytronIO
|
||||||
fast_poll = 0.1
|
fast_poll = 0.1
|
||||||
@ -86,19 +85,19 @@ class Motor(HasOffset, PersistentMixin, HasIO, Drivable):
|
|||||||
_reset_needed = False
|
_reset_needed = False
|
||||||
|
|
||||||
def get(self, cmd):
|
def get(self, cmd):
|
||||||
return self.communicate('%x%s%s' % (self.address, self.axis, cmd))
|
return self.communicate(f'{self.address:x}{self.axis}{cmd}')
|
||||||
|
|
||||||
def set(self, cmd, value):
|
def set(self, cmd, value):
|
||||||
# make sure e format is not used, max 8 characters
|
# make sure e format is not used, max 8 characters
|
||||||
strvalue = '%.6g' % value
|
strvalue = f'{value:.6g}'
|
||||||
if 'e' in strvalue:
|
if 'e' in strvalue:
|
||||||
if abs(value) <= 1: # very small number
|
if abs(value) <= 1: # very small number
|
||||||
strvalue = '%.7f' % value
|
strvalue = f'{value:.7f}'
|
||||||
elif abs(value) < 99999999: # big number
|
elif abs(value) < 99999999: # big number
|
||||||
strvalue = '%.0f' % value
|
strvalue = f'{value:.0f}'
|
||||||
else:
|
else:
|
||||||
raise ValueError('number (%g) must not have more than 8 digits' % value)
|
raise ValueError(f'number ({value}) must not have more than 8 digits')
|
||||||
self.communicate('%x%s%s%s' % (self.address, self.axis, cmd, strvalue))
|
self.communicate(f'{self.address:x}{self.axis}{cmd}{strvalue}')
|
||||||
|
|
||||||
def set_get(self, cmd, value, query):
|
def set_get(self, cmd, value, query):
|
||||||
self.set(cmd, value)
|
self.set(cmd, value)
|
||||||
@ -126,7 +125,7 @@ class Motor(HasOffset, PersistentMixin, HasIO, Drivable):
|
|||||||
enc = self.read_encoder()
|
enc = self.read_encoder()
|
||||||
else:
|
else:
|
||||||
enc = pos
|
enc = pos
|
||||||
status = self.communicate('%xSE' % self.address)
|
status = self.communicate(f'{self.address:x}SE')
|
||||||
status = status[0:4] if self.axis == 'X' else status[4:8]
|
status = status[0:4] if self.axis == 'X' else status[4:8]
|
||||||
self.log.debug('run %s enc %s end %s', status[1], status[2], status[3])
|
self.log.debug('run %s enc %s end %s', status[1], status[2], status[3])
|
||||||
status = self.get('=H')
|
status = self.get('=H')
|
||||||
@ -163,6 +162,7 @@ class Motor(HasOffset, PersistentMixin, HasIO, Drivable):
|
|||||||
self._mismatch_count = 0
|
self._mismatch_count = 0
|
||||||
self.status = IDLE, ''
|
self.status = IDLE, ''
|
||||||
self.value = pos
|
self.value = pos
|
||||||
|
self.read_encoder() # let encoder quickly match value
|
||||||
self.saveParameters()
|
self.saveParameters()
|
||||||
self.setFastPoll(False)
|
self.setFastPoll(False)
|
||||||
return pos
|
return pos
|
||||||
|
Loading…
x
Reference in New Issue
Block a user