示例#1
0
    def move_to(self, c, channel=None, partial=0, now=False):
        '''Set stepper to move to the specified channel position.
        Inputs:
        channel - Channel position on stepper to move to
        partial - Partial channel increments (8 per channel)
        
        Returns:
        (channel, partial) - Currently set move
        '''
        if channel is None:
            returnValue(self.newPosn[0:2] if self.newPosn else None)

        newPosn = (channel, partial)
        if not calc.isValidCh(newPosn):
            raise InvalidPosition()

        steps = calc.ch2steps(calc.chdiff(newPosn, self.posn[:2]))
        positive = steps >= 0
        #XOR bits, if changing directions, add backlash
        if positive ^ self.posn[2]:
            sgn = 1 if positive else -1
            steps += sgn * 8

        self.newPosn = (channel, partial, positive)
        yield self._moveSetup(abs(steps), positive, now)
        returnValue(self.newPosn[0:2])
示例#2
0
    def position(self, c, channel=None, partial=0, direction=True):
        '''Get or set the current stepper position.
        Input:
        channel - The current channel position
        partial - Channel fraction (8 steps per channel)
        direction - Either 'forward' or 'backward' or
                    True/False for forward and backward
        Returns:
        Current position and direction as a tuple with
        direction as a string
        (channel, partial, direction)
        '''
        if channel is not None:
            #if we're setting the channel by string, validate and set
            #boolean value as forward/backward (true/false)
            if type(direction) is str:
                d = direction.lower()
                if d not in DIR_MAP.keys():
                    raise Error('Direction must be Forward or Backward')
                dval = d == 'forward'
            else:
                dval = direction

            if not calc.isValidCh((channel, partial)):
                raise InvalidPosition()

            self.posn = (channel, partial, dval)

        c, f, d = self.posn
        dStr = 'Forward' if d else 'Backward'
        return (c, f, dStr)
示例#3
0
    def move_to(self, c, channel=None, partial=0):
        '''Set or query the channel to move to on the next run.
        Inputs:
            channel - Stepper channel to move to
            partial - Partial position
        
        Returns: 
        The channel that current settings will move to. (current, partial)'''

        if channel is not None:
            if not calc.isValidCh((channel, partial)):
                raise InvalidPositionError()

            deltaCh = calc.chdiff((channel, partial), self.posn[0:2])
            steps = calc.ch2steps(deltaCh)

            #if not moving same direction, add hysteresis
            if (steps > 0) != self.posn[2]:
                sgn = 1 if (steps >= 0) else -1
                steps += sgn * calc.STEPS_PER_CH

            yield self._moveChannelSetup(steps)

        posn = yield self._movePosn()
        returnValue(posn[0:2])
示例#4
0
    def advance(self, c, steps=None, now=False):
        '''Set stepper to advance a given number of increments.
        NB: There are 8 increments per channel
        
        Inputs:
        steps - Number of steps to take. Negative moves backwards.
        
        Returns:
        steps - Current number of steps stepper set to take
        '''
        if steps is None:
            if not self.newPosn:
                returnValue(None)
            else:
                advs = calc.ch2steps(
                    calc.chdiff(self.newPosn[0:2], self.posn[0:2]))
                if self.newPosn[2] != self.posn[2]:
                    sgn = 1 if self.newPosn[2] else -1
                    advs += sgn * 8
                returnValue(advs)

        ch, frac, forward = self.posn
        goForward = steps >= 0

        #XOR the bits, if not equal, include backlash for direction change
        if goForward ^ forward:
            sgn = 1 if goForward else -1
            shift = steps - sgn * 8
        else:
            shift = steps

        mathFn = calc.chadd if goForward else calc.chdiff
        newCh, newFrac = mathFn((ch, frac), calc.steps2ch(abs(shift)))

        if not calc.isValidCh((newCh, newFrac)):
            raise InvalidPosition()

        self.newPosn = (newCh, newFrac, goForward)
        yield self._moveSetup(abs(steps), goForward, now)
        returnValue(steps)
示例#5
0
    def advance(self, c, steps=None):
        '''Set or query steps to advance stepper.
        NOTE: Will not account for stepper hysteresis.
        Inputs:
            steps - Number of steps to advance. Negative indicates backwards move
        Returns:
            Number of steps to advance.
        '''

        if steps is not None:
            #verify legitmate position
            newPos = yield self._movePosn(steps)
            if not calc.isValidCh(newPos[0:2]):
                raise InvalidPositionError()

            yield self._moveChannelSetup(steps)
            returnValue(steps)

        else:
            newPos = yield self._movePosn()
            delta = calc.chdiff(newPos[0:2], self.posn[0:2])
            returnValue(calc.ch2steps(delta))
示例#6
0
 def move_to(self, c, position=None):
     if position is not None:
         if not calc.isValidCh(position):
             raise InvalidPositionError()
         self.move_posn = position
     return self.move_posn
示例#7
0
 def position(self, c, posn=None):
     if posn is not None:
         if not calc.isValidCh(posn):
             raise InvalidPositionError()
         self.posn = posn
     return self.posn