def test_abs_mode(self):
        logger.setLevel(logging.DEBUG)
        print 'goto direction'
        a = AbsModeBusMode('x', 'com5')
        direction = 35000

        a.goto(direction)
        readed = a.location()
        while abs(readed - direction) > 3:
            time.sleep(0.01)
            readed = a.location()
            logger.info('get readed ' + str(readed))
Пример #2
0
 def test_live_mode(self):
     logger.setLevel(logging.ERROR)
     slave = AbsSlave()
     slave.start()
     a = AbsModeBusMode('x', 'com13')
     print 'init direction', a.direction
     direction = 2500
     a.goto(direction)
     readed = a.location()
     while abs(readed - direction) > 100:
         time.sleep(0.01)
         readed = a.location()
         logger.info('get readed ' + str(readed))
     slave.close()
 def test_abs_mode(self):
     slave = Slave()
     slave.start()
     logger.setLevel(logging.WARN)  #设置日志级别
     a = AbsModeBusMode('x', 'com13')
     direction = 31000
     a.goto(direction)
     readed = a.location()
     while abs(readed - direction) > 100:
         time.sleep(0.01)
         readed = a.location()
         logger.info('get readed ' + str(readed))
     slave.close()
     slave.ser.close()
     a.ser.close()
Пример #4
0
class YieldAbsFocuser(object):
    def __init__(self, axis='x', port="com4", sharp=0):
        super(YieldAbsFocuser, self).__init__()
        self.mode = AbsModeBusMode(axis, port)
        self.BORDER = (0, 25000, 50000)
        self.forward = {True: 1, False: 50000}
        self.forward_to = self.forward[True]
        self.queue = deque(maxlen=15)
        self.new_sharp = [0, 0]
        self.sharps = deque(maxlen=2)

    def start(self):
        _ = threading.Thread(target=self.run)
        _.start()
        # self.run()

    def run(self):
        logger.error('go_on_random_for_init_forward')
        direction = self.go_on_random_for_init_forward()
        logger.error('live_focus_with_abs_direction ' + str(direction))
        finall = self.live_focus_with_abs_direction(direction)
        logger.error('move_direct' + str(finall))
        self.move_direct(finall)

    def gen_queue_full(self, call_back=None, returned=None, *arg, **kwargs):
        while True:
            data = yield
            self.queue.append((data, self.mode.location()))
            if len(self.queue) == 15:
                returned = call_back(*arg, **kwargs)

    def go_on_random_for_init_forward(self):
        now = self.mode.location()
        forward = True if now - self.BORDER[1] > 0 else False
        direction = self.forward[forward]
        self.mode.goto(direction)
        self.queue.clear()
        while len(self.queue) < 15:
            logger.debug('15 len queue' + str(len(self.queue)))
            time.sleep(0.1)
            while True:
                logger.debug('15 len queue' + str(self.new_sharp) +
                             str(len(self.queue)))
                if self.new_sharp[0] == self.new_sharp[1]:
                    time.sleep(0.1)
                else:
                    self.new_sharp[0] = self.new_sharp[1]
                    break
            self.queue.append((self.new_sharp[0], self.mode.location()))

        def call_back(self):
            self.mode.scram()
            sharps = [x[0] for x in list(self.queue)]
            begin = midfilter(sharps[:5])
            mid = midfilter(sharps[5:-5])
            end = midfilter(sharps[-5:])
            cmd = "begin,mid,end {} {} {}".format(begin, mid, end)
            logger.warning(cmd)
            if begin <= end:
                forward = not forward

        return self.forward[forward]
        # logger.info('get readed ' + str(readed))

    def get_sharp(self, sharp):
        # self.new_sharp[1] = list(self.sharp
        self.new_sharp[1] = float(sharp)

    def live_focus_with_abs_direction(self, direction):
        self.mode.goto(direction)
        self.queue.clear()
        while True:
            time.sleep(0.1)
            while True:
                if self.new_sharp[0] == self.new_sharp[1]:
                    time.sleep(0.01)
                else:
                    self.new_sharp[0] = self.new_sharp[1]
                    break
            self.queue.append((self.new_sharp[0], self.mode.location()))
            if len(self.queue) == 15:
                sharps = [x[0] for x in list(self.queue)]
                begin = midfilter(sharps[:5])
                mid = midfilter(sharps[5:-5])
                end = midfilter(sharps[-5:])
                cmd = "BME {} {} {}".format(begin, mid, end)
                logger.warning(cmd)
                if (begin > mid) and (end > mid):
                    cmd = "return backe begin,mid,end {} {} {}".format(
                        begin, mid, end)
                    logger.warning(cmd)
                    self.mode.scram()
                    break
        return list(self.queue)[-1][1]

    def move_direct(self, finall):
        self.mode.goto(finall)
        readed = self.mode.location()
        while abs(readed - finall) > 10:
            time.sleep(0.01)
            readed = self.mode.location()
            logger.info('get readed ' + str(readed))