further work on needle valve, pump and lakeshore
This commit is contained in:
@ -26,7 +26,8 @@ import struct
|
||||
|
||||
from frappy.core import BoolType, Command, EnumType, FloatRange, IntRange, \
|
||||
HasIO, Parameter, Property, Drivable, PersistentMixin, PersistentParam, Done, \
|
||||
IDLE, BUSY, ERROR, Limit
|
||||
IDLE, BUSY, ERROR, Limit, nopoll, ArrayOf
|
||||
from frappy.properties import HasProperties
|
||||
from frappy.io import BytesIO
|
||||
from frappy.errors import CommunicationFailedError, HardwareError, RangeError, IsBusyError
|
||||
from frappy.rwhandler import ReadHandler, WriteHandler
|
||||
@ -119,9 +120,6 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
||||
move_status = Parameter('', EnumType(ok=0, stalled=1, encoder_deviation=2, stalled_and_encoder_deviation=3),
|
||||
group='hwstatus')
|
||||
error_bits = Parameter('', IntRange(0, 255), group='hwstatus')
|
||||
home = Parameter('state of home switch (input 3)', BoolType(), group='more')
|
||||
has_home = Parameter('enable home and activate pullup resistor', BoolType(),
|
||||
default=True, group='more')
|
||||
auto_reset = Parameter('automatic reset after failure', BoolType(), group='more', readonly=False, default=False)
|
||||
free_wheeling = writable('', FloatRange(0, 60., unit='sec', fmtstr='%.2f'),
|
||||
value=0.1, group='motorparam')
|
||||
@ -132,6 +130,20 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
||||
readonly=False, default=0, visibility=3, group='more')
|
||||
max_retry = Parameter('maximum number of retries', IntRange(0, 99), readonly=False, default=0)
|
||||
stall_thr = Parameter('stallGuard threshold', IntRange(-64, 63), readonly=False, value=0)
|
||||
input_bits = Parameter('input bits', IntRange(0, 255), group='more', export=False)
|
||||
input1 = Parameter('input 1', BoolType(), export=False, group='more')
|
||||
input2 = Parameter('input 2', BoolType(), export=False, group='more')
|
||||
input3 = Parameter('input 3', BoolType(), export=False, group='more')
|
||||
output0 = Parameter('output 0', BoolType(), readonly=False, export=False, group='more', default=0)
|
||||
output1 = Parameter('output 1', BoolType(), readonly=False, export=False, group='more', default=0)
|
||||
home = Parameter('state of home switch (input 3)', BoolType(), group='more', export=False)
|
||||
has_home = Property('enable home and activate pullup resistor', BoolType(), export=False,
|
||||
default=True)
|
||||
has_inputs = Property('inputs are polled', BoolType(), export=False,
|
||||
default=False)
|
||||
with_pullup = Property('activate pullup', BoolType(), export=False,
|
||||
default=True)
|
||||
|
||||
pollinterval = Parameter(group='more')
|
||||
target_min = Limit()
|
||||
target_max = Limit()
|
||||
@ -145,6 +157,18 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
||||
_loading = False # True when loading parameters
|
||||
_drv_try = 0
|
||||
|
||||
def checkProperties(self):
|
||||
super().checkProperties()
|
||||
if self.has_home:
|
||||
self.parameters['home'].export = '_home'
|
||||
self.setProperty('has_inputs', True)
|
||||
if not self.has_inputs:
|
||||
self.setProperty('with_pullup', False)
|
||||
|
||||
def writeInitParams(self):
|
||||
super().writeInitParams()
|
||||
self.comm(SET_IO, 0, self.with_pullup)
|
||||
|
||||
def comm(self, cmd, adr, value=0, bank=0):
|
||||
"""set or get a parameter
|
||||
|
||||
@ -402,13 +426,6 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
||||
def read_steppos(self):
|
||||
return self._read_axispar(STEPPOS_ADR, ANGLE_SCALE) + self.zero
|
||||
|
||||
def read_home(self):
|
||||
return not self.comm(GET_IO, 255) & 8
|
||||
|
||||
def write_has_home(self, value):
|
||||
"""activate pullup resistor"""
|
||||
return bool(self.comm(SET_IO, 0, value))
|
||||
|
||||
@Command(FloatRange())
|
||||
def set_zero(self, value):
|
||||
"""adapt zero to make current position equal to given value"""
|
||||
@ -459,3 +476,47 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
||||
def set_axis_par(self, adr, value):
|
||||
"""set arbitrary motor parameter"""
|
||||
return self.comm(SET_AXIS_PAR, adr, value)
|
||||
|
||||
def read_input_bits(self):
|
||||
if not self.has_inputs:
|
||||
return 0
|
||||
bits = self.comm(GET_IO, 255)
|
||||
self.input1 = bool(bits & 2)
|
||||
self.input2 = bool(bits & 4)
|
||||
self.input3 = bool(bits & 8)
|
||||
self.home = not self.input3
|
||||
return bits
|
||||
|
||||
@nopoll
|
||||
def read_home(self):
|
||||
self.read_input_bits()
|
||||
return self.home
|
||||
|
||||
@nopoll
|
||||
def read_input1(self):
|
||||
self.read_input_bits()
|
||||
return self.input1
|
||||
|
||||
@nopoll
|
||||
def read_input2(self):
|
||||
self.read_input_bits()
|
||||
return self.input2
|
||||
|
||||
@nopoll
|
||||
def read_input3(self):
|
||||
self.read_input_bits()
|
||||
return self.input3
|
||||
|
||||
def write_output0(self, value):
|
||||
return self.comm(SET_IO, 0, value, bank=2)
|
||||
|
||||
@nopoll
|
||||
def read_output0(self):
|
||||
return self.comm(GET_IO, 0, bank=2)
|
||||
|
||||
def write_output1(self, value):
|
||||
return self.comm(SET_IO, 1, value, bank=2)
|
||||
|
||||
@nopoll
|
||||
def read_output1(self):
|
||||
return self.comm(GET_IO, 1, bank=2)
|
||||
|
Reference in New Issue
Block a user