def _return_home(self) -> None:
     logger.info('start return home')
     pos = cnc.position
     generate_linear_puls(pos.x.steps * -1, pos.y.steps * -1, PULS_DEVICE)
     self._run_loop()
     send_wss_event(self._q_msg_tx, self.running_action_id,
                    'print:return_to_home:succeeded')
Beispiel #2
0
 def head_image(self, msg: dict) -> None:
     """
     Process head image request.
     Sends related start and finish messages, and calls child class handler.
     :param msg: Incoming WSS Message
     :type msg: dict
     :return:
     """
     send_wss_event(self._q_msg_tx, msg['id'], 'head_image:starting')
     self._head_image(msg)
     send_wss_event(self._q_msg_tx, msg['id'], 'head_image:completed')
Beispiel #3
0
 def hunt(self, msg: dict) -> None:
     """
     Home the focus lens.
     Sends related start and finish messages, and calls child class handler.
     :param msg: Incoming WSS Message
     :type msg: dict
     :return:
     """
     send_wss_event(self._q_msg_tx, msg['id'], 'hunt:starting')
     self._hunt(msg)
     send_wss_event(self._q_msg_tx, msg['id'], 'hunt:completed')
Beispiel #4
0
 def lidar_image(self, msg: dict) -> None:
     """
     Process lidar image request.
     Sends related start and finish messages, and calls child class handler to capture
     head images with and without the distance measuring laser enabled.
     :param msg: Incoming WSS Message
     :type msg: dict
     :return:
     """
     send_wss_event(self._q_msg_tx, msg['id'], 'lidar_image:starting')
     self._head_image(msg, msg['settings'][0])
     send_wss_event(self._q_msg_tx, msg['id'], 'lidar_image:completed')
Beispiel #5
0
 def motion(self, msg: dict) -> None:
     """
     Process motion request.
     Sends related start and finish messages, and calls child class handler.
     :param msg: Incoming WSS Message
     :type msg: dict
     :return:
     """
     send_wss_event(self._q_msg_tx, msg['id'],
                    msg['action_type'] + ':starting')
     self._motion(msg)
     if self._running_action_cancelled:
         self._send_cancelled_message(msg['id'], msg['action_type'])
     else:
         send_wss_event(self._q_msg_tx, msg['id'],
                        msg['action_type'] + ':completed')
def send_report(q: Queue, msg: dict) -> None:
    """
    Send device settings report in the required format.
    :param q: {WSS message queue
    :type q: Queue
    :param msg: WSS Message
    :type msg: dict
    :return:
    """
    settings = ''
    logger.info("START")
    for item, setting in MACHINE_SETTINGS.items():
        value = '' if setting.default is None else str(setting.default)
        if setting.in_report:
            if item == 'SAid':
                value = msg['id']
            if item in _CONFIG_PROVIDERS:
                config_value = get_cfg(_CONFIG_PROVIDERS.get(item))
                if config_value is not None:
                    value = str(config_value)
            if item in _REGISTERED_PROVIDERS:
                value = str(_REGISTERED_PROVIDERS[item]())
            if setting.type is int:
                value = int(float(value))
            elif setting.type is str:
                value = '"{}"'.format(value)
            else:
                value = setting.type(value)
            settings += '"{}":{},'.format(item, value)

    # The service appears to bypass the homing process if we send it an empty settings value.
    # It is assumed that this prevents the machine from re-homing every time it loses and regains
    # the connection to the Glowforge service (a seemingly frequent occurrence).
    if not get_cfg('SETTINGS.SET') and not get_cfg('EMULATOR.BYPASS_HOMING'):
        send_wss_event(q, msg['id'], 'settings:completed',
                       data={'key': 'settings', 'value': '{"values":{%s}}' % settings[:-1]})
        set_cfg('SETTINGS.SET', True)
    else:
        send_wss_event(q, msg['id'], 'settings:completed', data={'key': 'settings', 'value': '{}'})
    logger.info("COMPLETE")
 def _switch_event(self, event: SwitchEvent) -> None:
     logger.debug('received switch event %s' % str(event))
     if event.code == InputSwitch.SW_BUTTON:
         if event.val:
             logger.info('button pushed')
             send_wss_event(self._q_msg_tx, None, 'button:pressed')
             self._button_pressed = True
         else:
             logger.info('button released')
             send_wss_event(self._q_msg_tx, None, 'button:released')
     elif event.code == InputSwitch.SW_DOORS:
         if event.val:
             logger.info('lid closed')
             send_wss_event(self._q_msg_tx, None, 'lid:closed')
         else:
             logger.info('lid opened')
             send_wss_event(self._q_msg_tx, None, 'lid:opened')
Beispiel #8
0
    def _motion(self, msg: dict) -> None:
        # Download puls file from service
        self._motion_download(msg)
        if msg['action_type'] == 'print':
            send_wss_event(self._q_msg_tx, msg['id'],
                           'print:download:completed')
            self._button_wait(msg)
            if not self._running_action_cancelled:
                send_wss_event(self._q_msg_tx, msg['id'],
                               'print:warmup:starting')
        # Run motion job
        if not self._running_action_cancelled:
            if msg['action_type'] == 'print':
                send_wss_event(self._q_msg_tx, msg['id'], 'print:running')
                send_wss_event(self._q_msg_tx, msg['id'],
                               'print:return_to_home:succeeded')

        self._last_action = msg['action_type']
    def _motion(self, msg: dict) -> None:
        logger.info('start motion')
        if self._safe_to_move:
            cnc.clear_all()
            # Download puls file from service
            logger.info('loading motion file from %s' % msg['motion_url'])
            self._motion_stats = load_motion(self._session, msg['motion_url'],
                                             PULS_DEVICE)
            logger.info('motion stats: %s' % self._motion_stats)
            if msg['action_type'] == 'print':
                send_wss_event(self._q_msg_tx, msg['id'],
                               'print:download:completed')
                cnc.laser_latch(0)
                self._button_wait(msg)
                if not self._running_action_cancelled:
                    send_wss_event(self._q_msg_tx, msg['id'],
                                   'print:warmup:starting')

            # Configure for print, and wait for warm up
            if not self._running_action_cancelled:
                self._config_from_pulse('run',
                                        self._motion_stats['header_data'])
                if msg['action_type'] == 'print':
                    if get_cfg('MOTION.WARM_UP_DELAY'):
                        sleep(int(get_cfg('MOTION.WARM_UP_DELAY')))

            # Run motion job
            if not self._running_action_cancelled:
                if msg['action_type'] == 'print':
                    logger.info('start temps: %s' % str(temp_sensor.all))
                    send_wss_event(self._q_msg_tx, msg['id'], 'print:running')
                self._run_loop()
                cnc.laser_latch(1)
                pos = cnc.position
                logger.info(
                    'end positions (actual/expected): X (%s/%s), Y (%s/%s), Z (%s/%s)'
                    % (
                        pos.x.steps,
                        self._motion_stats['stats']['XEND'],
                        pos.y.steps,
                        self._motion_stats['stats']['YEND'],
                        pos.z.steps,
                        self._motion_stats['stats']['ZEND'],
                    ))
                logger.info('motion bytes actual:%s, expected: %s' %
                            (pos.bytes.processed, self._motion_stats['size']))
                if msg['action_type'] == 'print':
                    logger.info('end print temps: %s' % str(temp_sensor.all))

            # Cool down for prints
            if msg['action_type'] == 'print':
                self._return_home()
                logger.info('start cool down')
                self._config_from_pulse('cool_down',
                                        self._motion_stats['header_data'])
                if get_cfg('MOTION.COOL_DOWN_DELAY'):
                    sleep(int(get_cfg('MOTION.COOL_DOWN_DELAY')))
                logger.info('end cool-down temps: %s' % str(temp_sensor.all))

            # Config for idle
            logger.info('start idle')
            self._config_from_pulse('idle', self._motion_stats['header_data'])
            pos = cnc.position
            logger.info('end positions (%s, %s, %s)' %
                        (pos.x.steps, pos.y.steps, pos.z.steps))
        logger.info('end motion')
Beispiel #10
0
 def _send_cancelled_message(self, action_id: int, action_type: str):
     send_wss_event(self._q_msg_tx, action_id, '%s:cancelled' % action_type)