class DigitalLineDirectionStepperMotor(DirectionStepperMotor): def __init__(self, direction_channel, enable_channel=None, backlash=0, direction=DirectionStepperMotor.FORWARDS, tasks=None): self.direction_task = DOTask() self.direction_task.createChannel(direction_channel) DirectionStepperMotor.__init__( self, enable_channel=enable_channel, backlash=backlash, direction=direction, tasks=((tasks if tasks is not None else []) + [self.direction_task])) def _setDirection(self, direction): self.direction_task.writeState({ self.FORWARDS: True, self.BACKWARDS: False }[direction]) self.direction = direction def _getDirection(self): return self.direction
class DigitalLineDirectionStepperMotor(DirectionStepperMotor): def __init__( self, direction_channel, enable_channel=None, backlash=0, direction=DirectionStepperMotor.FORWARDS, tasks=None ): self.direction_task = DOTask() self.direction_task.createChannel(direction_channel) DirectionStepperMotor.__init__( self, enable_channel=enable_channel, backlash=backlash, direction=direction, tasks = ((tasks if tasks is not None else []) + [self.direction_task]) ) def _setDirection(self,direction): self.direction_task.writeState( { self.FORWARDS:True, self.BACKWARDS:False }[direction] ) self.direction = direction def _getDirection(self): return self.direction
class EnabledStepperMotor(BaseStepperMotor): ENABLED = 1 DISABLED = 0 def __init__(self, enable_channel=None, tasks=None): self.enable_channel = enable_channel self.enabled = self.DISABLED if enable_channel is not None: self.enable_task = DOTask() self.enable_task.createChannel(enable_channel) elif enable_channel is None: self.enable() tasks = (tasks if tasks is not None else []) + ( [self.enable_task] if self.enable_channel is not None else []) BaseStepperMotor.__init__(self, tasks=tasks) def getEnableStatus(self): enb_str = { self.ENABLED: 'enabled', self.DISABLED: 'disabled' }[self._getEnableStatus()] return enb_str def enable(self): self._setEnableStatus(self.ENABLED) def disable(self): self._setEnableStatus(self.DISABLED) def toggleStatus(self): if self._getEnableStatus() == self.ENABLED: self.disable() elif self._getEnableStatus() == self.DISABLED: self.enable() def _getEnableStatus(self): return self.enabled def _setEnableStatus(self, state): if self.enable_channel is None: self.enabled = True return elif self.enable_channel is not None: self.enable_task.writeState({ self.ENABLED: True, self.DISABLED: False }[state]) self.enabled = state def _setPosition(self, position, callback): if self._getEnableStatus() == self.ENABLED: BaseStepperMotor._setPosition(self, position, callback) else: print 'not enabled!' def destroy(self): self.disable() BaseStepperMotor.destroy(self)
def __init__(self, enable_channel=None, tasks=None): self.enable_channel = enable_channel self.enabled = self.DISABLED if enable_channel is not None: self.enable_task = DOTask() self.enable_task.createChannel(enable_channel) elif enable_channel is None: self.enable() tasks = (tasks if tasks is not None else []) + ( [self.enable_task] if self.enable_channel is not None else []) BaseStepperMotor.__init__(self, tasks=tasks)
def __init__(self, direction_channel, enable_channel=None, backlash=0, direction=DirectionStepperMotor.FORWARDS, tasks=None): self.direction_task = DOTask() self.direction_task.createChannel(direction_channel) DirectionStepperMotor.__init__( self, enable_channel=enable_channel, backlash=backlash, direction=direction, tasks=((tasks if tasks is not None else []) + [self.direction_task]))
def __init__( self, step_channel, counter_channel, direction_channel, log_file=None, enable_channel=None, step_rate=500.0, backlash=0, tasks=None ): self.step_task = DOTask() self.step_task.createChannel(step_channel) self.setStepRate(step_rate) self.step_task.writeState(False) tasks=(tasks if tasks is not None else []) + [self.step_task] LoggedStepperMotor.__init__( self, counter_channel, direction_channel, log_file, enable_channel, backlash, tasks )
def __init__(self, step_channel, counter_channel, direction_channel, log_file=None, enable_channel=None, step_rate=500.0, backlash=0, tasks=None): self.step_task = DOTask() self.step_task.createChannel(step_channel) self.setStepRate(step_rate) self.step_task.writeState(False) tasks = (tasks if tasks is not None else []) + [self.step_task] LoggedStepperMotor.__init__(self, counter_channel, direction_channel, log_file, enable_channel, backlash, tasks)
class DigitalLineStepperMotor(LoggedStepperMotor): import threading def __init__( self, step_channel, counter_channel, direction_channel, log_file=None, enable_channel=None, step_rate=500.0, backlash=0, tasks=None ): self.step_task = DOTask() self.step_task.createChannel(step_channel) self.setStepRate(step_rate) self.step_task.writeState(False) tasks=(tasks if tasks is not None else []) + [self.step_task] LoggedStepperMotor.__init__( self, counter_channel, direction_channel, log_file, enable_channel, backlash, tasks ) def run(self,steps,callback): for i in range(steps): for state in (True,False): self.step_task.writeState(state) sleep(.5 / self.step_rate) callback() def _generateSteps(self,steps,callback): thread = Thread(target=self.run, args=(steps,callback)) thread.start() # def _generateSteps(self,steps,callback): # this = self # class GenerateSteps(Thread): # def run(self): # for i in range(steps): # for state in (True,False): # this.step_task.writeState(state) # sleep(.5 / this.step_rate) # callback() # GenerateSteps().start() def setStepRate(self,step_rate): self.step_rate = step_rate def getStepRate(self): return self.step_rate
def __init__( self, enable_channel=None, tasks=None ): self.enable_channel = enable_channel self.enabled = self.DISABLED if enable_channel is not None: self.enable_task = DOTask() self.enable_task.createChannel(enable_channel) elif enable_channel is None: self.enable() tasks = (tasks if tasks is not None else []) + ([self.enable_task] if self.enable_channel is not None else []) BaseStepperMotor.__init__( self, tasks=tasks )
def __init__( self, direction_channel, enable_channel=None, backlash=0, direction=DirectionStepperMotor.FORWARDS, tasks=None ): self.direction_task = DOTask() self.direction_task.createChannel(direction_channel) DirectionStepperMotor.__init__( self, enable_channel=enable_channel, backlash=backlash, direction=direction, tasks = ((tasks if tasks is not None else []) + [self.direction_task]) )
class DigitalLineStepperMotor(LoggedStepperMotor): import threading def __init__(self, step_channel, counter_channel, direction_channel, log_file=None, enable_channel=None, step_rate=500.0, backlash=0, tasks=None): self.step_task = DOTask() self.step_task.createChannel(step_channel) self.setStepRate(step_rate) self.step_task.writeState(False) tasks = (tasks if tasks is not None else []) + [self.step_task] LoggedStepperMotor.__init__(self, counter_channel, direction_channel, log_file, enable_channel, backlash, tasks) def run(self, steps, callback): for i in range(steps): for state in (True, False): self.step_task.writeState(state) sleep(.5 / self.step_rate) callback() def _generateSteps(self, steps, callback): thread = Thread(target=self.run, args=(steps, callback)) thread.start() # def _generateSteps(self,steps,callback): # this = self # class GenerateSteps(Thread): # def run(self): # for i in range(steps): # for state in (True,False): # this.step_task.writeState(state) # sleep(.5 / this.step_rate) # callback() # GenerateSteps().start() def setStepRate(self, step_rate): self.step_rate = step_rate def getStepRate(self): return self.step_rate
class EnabledStepperMotor(BaseStepperMotor): ENABLED = 1 DISABLED = 0 def __init__( self, enable_channel=None, tasks=None ): self.enable_channel = enable_channel self.enabled = self.DISABLED if enable_channel is not None: self.enable_task = DOTask() self.enable_task.createChannel(enable_channel) elif enable_channel is None: self.enable() tasks = (tasks if tasks is not None else []) + ([self.enable_task] if self.enable_channel is not None else []) BaseStepperMotor.__init__( self, tasks=tasks ) def getEnableStatus(self): enb_str = {self.ENABLED:'enabled',self.DISABLED:'disabled'}[self._getEnableStatus()] return enb_str def enable(self): self._setEnableStatus(self.ENABLED) def disable(self): self._setEnableStatus(self.DISABLED) def toggleStatus(self): if self._getEnableStatus() == self.ENABLED: self.disable() elif self._getEnableStatus() == self.DISABLED: self.enable() def _getEnableStatus(self): return self.enabled def _setEnableStatus(self,state): if self.enable_channel is None: self.enabled = True return elif self.enable_channel is not None: self.enable_task.writeState( { self.ENABLED:True, self.DISABLED:False }[state] ) self.enabled = state def _setPosition(self,position,callback): if self._getEnableStatus() == self.ENABLED: BaseStepperMotor._setPosition(self,position,callback) else: print 'not enabled!' def destroy(self): self.disable() BaseStepperMotor.destroy(self)