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