Example #1
0
    def __encode(self, block):
        type, id = block['type'], block['id']

        if type != 'set': log.info('Cmd:' + log_json(block))

        if type == 'line':
            self._enqueue_line_time(block)
            return Cmd.line(block['target'], block['exit-vel'],
                            block['max-accel'], block['max-jerk'],
                            block['times'], block.get('speeds', []))

        if type == 'set':
            name, value = block['name'], block['value']

            if name == 'message':
                msg = dict(message=value)
                self.cmdq.enqueue(id, self.ctrl.msgs.broadcast, msg)

            if name in ['line', 'tool']: self._enqueue_set_cmd(id, name, value)
            if name == 'speed': return Cmd.speed(value)

            if len(name) and name[0] == '_':
                # Don't queue axis positions, can be triggered by new position
                if len(name) != 2 or name[1] not in 'xyzabc':
                    self._enqueue_set_cmd(id, name[1:], value)

            if name == '_feed':  # Must come after _enqueue_set_cmd() above
                return Cmd.set_sync('if', 1 / value if value else 0)

            if name[0:1] == '_' and name[1:2] in 'xyzabc':
                if name[2:] == '_home': return Cmd.set_axis(name[1], value)

                if name[2:] == '_homed':
                    motor = self.ctrl.state.find_motor(name[1])
                    if motor is not None:
                        return Cmd.set_sync('%dh' % motor, value)

            return

        if type == 'input':
            # TODO handle timeout
            self.planner.synchronize(0)  # TODO Fix this
            return Cmd.input(block['port'], block['mode'], block['timeout'])

        if type == 'output':
            return Cmd.output(block['port'], int(float(block['value'])))

        if type == 'dwell':
            self._enqueue_dwell_time(block)
            return Cmd.dwell(block['seconds'])

        if type == 'pause': return Cmd.pause(block['pause-type'])

        if type == 'seek':
            return Cmd.seek(block['switch'], block['active'], block['error'])

        if type == 'end': return ''  # Sends id

        raise Exception('Unknown planner command "%s"' % type)
Example #2
0
    def __encode(self, block):
        log.info('Cmd:' + json.dumps(block))

        type, id = block['type'], block['id']

        if type == 'line':
            return Cmd.line(block['target'], block['exit-vel'],
                            block['max-accel'], block['max-jerk'],
                            block['times'])

        if type == 'set':
            name, value = block['name'], block['value']

            if name == 'message':
                self.cmdq.enqueue(id, True, self.ctrl.msgs.broadcast,
                                  {'message': value})

            if name in ['line', 'tool']:
                self._enqueue_set_cmd(id, name, value)

            if name == 'speed': return Cmd.speed(value)

            if len(name) and name[0] == '_':
                self._enqueue_set_cmd(id, name[1:], value)

            if name[0:1] == '_' and name[1:2] in 'xyzabc':
                if name[2:] == '_home': return Cmd.set_axis(name[1], value)

                if name[2:] == '_homed':
                    motor = self.ctrl.state.find_motor(name[1])
                    if motor is not None: return Cmd.set('%dh' % motor, value)

            return

        if type == 'input':
            # TODO handle timeout
            self.planner.synchronize(0)  # TODO Fix this
            return Cmd.input(block['port'], block['mode'], block['timeout'])

        if type == 'output':
            return Cmd.output(block['port'], int(float(block['value'])))

        if type == 'dwell': return Cmd.dwell(block['seconds'])
        if type == 'pause': return Cmd.pause(block['pause-type'])
        if type == 'seek':
            return Cmd.seek(block['switch'], block['active'], block['error'])

        raise Exception('Unknown planner command "%s"' % type)
Example #3
0
    def _update_vars(self, msg):
        try:
            self.ctrl.state.machine_vars(msg['variables'])
            self.queue_command(Cmd.DUMP)  # Refresh all vars

            # Set axis positions
            for axis in 'xyzabc':
                position = self.ctrl.state.get(axis + 'p', 0)
                self.queue_command(Cmd.set_axis(axis, position))

        except Exception as e:
            log.warning('AVR reload failed: %s', traceback.format_exc())
            self.ctrl.ioloop.call_later(1, self.connect)
Example #4
0
    def set_position(self, axis, position):
        axis = axis.lower()

        if self.ctrl.state.is_axis_homed(axis):
            self.mdi('G92 %s%f' % (axis, position))

        else:
            if self._get_cycle() not in ['idle', 'mdi']:
                raise Exception('Cannot zero position during ' +
                                self._get_cycle())

            self._begin_cycle('mdi')
            self.planner.set_position({axis: position})
            super().queue_command(Cmd.set_axis(axis, position))
Example #5
0
    def set_position(self, axis, position):
        axis = axis.lower()

        if self.ctrl.state.is_axis_homed(axis):
            # If homed, change the offset rather than the absolute position
            self.mdi('G92%s%f' % (axis, position))

        elif self.ctrl.state.is_axis_enabled(axis):
            if self._get_cycle() != 'idle' and not self._is_paused():
                raise Exception('Cannot set position during ' +
                                self._get_cycle())

            # Set the absolute position both locally and via the AVR
            self.ctrl.state.set(axis + 'p', position)
            super().queue_command(Cmd.set_axis(axis, position))
Example #6
0
    def _encode(self, block):
        cmd = self.__encode(block)

        if cmd is not None:
            self.cmdq.enqueue(block['id'], None)
            return Cmd.set_sync('id', block['id']) + '\n' + cmd
Example #7
0
 def modbus_write(self, addr, value):
     self._i2c_block(Cmd.modbus_write(addr, value))
Example #8
0
    def modbus_read(self, addr): self._i2c_block(Cmd.modbus_read(addr))


    def modbus_write(self, addr, value):
Example #9
0
 def jog(self, axes):
     self._begin_cycle('jogging')
     super().queue_command(Cmd.jog(axes))
Example #10
0
    def _i2c_set(self, name, value): self._i2c_block(Cmd.set(name, value))


    @overrides(Comm)
Example #11
0
 def modbus_read(self, addr):
     self._i2c_block(Cmd.modbus_read(addr))
Example #12
0
 def jog(self, axes):
     self._begin_cycle('jogging')
     self.planner.position_change()
     super().queue_command(Cmd.jog(axes))
Example #13
0
 def _i2c_set(self, name, value):
     self._i2c_block(Cmd.set(name, value))