gcode: Remove explicit active extruder tracking
There's no need to have special logic in gcode.py to track the active extruder. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
0bf4ab66da
commit
0a39c339c7
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
import os, re, logging, collections, shlex
|
import os, re, logging, collections, shlex
|
||||||
import homing, kinematics.extruder
|
import homing
|
||||||
|
|
||||||
# Parse and handle G-Code commands
|
# Parse and handle G-Code commands
|
||||||
class GCodeParser:
|
class GCodeParser:
|
||||||
|
@ -56,7 +56,7 @@ class GCodeParser:
|
||||||
self.move_transform = self.move_with_transform = None
|
self.move_transform = self.move_with_transform = None
|
||||||
self.position_with_transform = (lambda: [0., 0., 0., 0.])
|
self.position_with_transform = (lambda: [0., 0., 0., 0.])
|
||||||
self.need_ack = False
|
self.need_ack = False
|
||||||
self.toolhead = self.fan = self.extruder = None
|
self.toolhead = self.fan = None
|
||||||
self.heaters = None
|
self.heaters = None
|
||||||
self.axis2pos = {'X': 0, 'Y': 1, 'Z': 2, 'E': 3}
|
self.axis2pos = {'X': 0, 'Y': 1, 'Z': 2, 'E': 3}
|
||||||
def register_command(self, cmd, func, when_not_ready=False, desc=None):
|
def register_command(self, cmd, func, when_not_ready=False, desc=None):
|
||||||
|
@ -171,10 +171,6 @@ class GCodeParser:
|
||||||
if self.move_transform is None:
|
if self.move_transform is None:
|
||||||
self.move_with_transform = self.toolhead.move
|
self.move_with_transform = self.toolhead.move
|
||||||
self.position_with_transform = self.toolhead.get_position
|
self.position_with_transform = self.toolhead.get_position
|
||||||
extruders = kinematics.extruder.get_printer_extruders(self.printer)
|
|
||||||
if extruders:
|
|
||||||
self.extruder = extruders[0]
|
|
||||||
self.toolhead.set_extruder(self.extruder)
|
|
||||||
self.fan = self.printer.lookup_object('fan', None)
|
self.fan = self.printer.lookup_object('fan', None)
|
||||||
if self.is_fileinput and self.fd_handle is None:
|
if self.is_fileinput and self.fd_handle is None:
|
||||||
self.fd_handle = self.reactor.register_fd(self.fd,
|
self.fd_handle = self.reactor.register_fd(self.fd,
|
||||||
|
@ -410,8 +406,8 @@ class GCodeParser:
|
||||||
extruder = self.printer.lookup_object(section, None)
|
extruder = self.printer.lookup_object(section, None)
|
||||||
if extruder is not None:
|
if extruder is not None:
|
||||||
heater = extruder.get_heater()
|
heater = extruder.get_heater()
|
||||||
elif self.extruder is not None:
|
else:
|
||||||
heater = self.extruder.get_heater()
|
heater = self.toolhead.get_extruder().get_heater()
|
||||||
if heater is None:
|
if heater is None:
|
||||||
if temp > 0.:
|
if temp > 0.:
|
||||||
self.respond_error("Heater not configured")
|
self.respond_error("Heater not configured")
|
||||||
|
@ -452,18 +448,25 @@ class GCodeParser:
|
||||||
self.respond_info('Unknown command:"%s"' % (cmd,))
|
self.respond_info('Unknown command:"%s"' % (cmd,))
|
||||||
def cmd_Tn(self, params):
|
def cmd_Tn(self, params):
|
||||||
# Select Tool
|
# Select Tool
|
||||||
extruders = kinematics.extruder.get_printer_extruders(self.printer)
|
index = self.get_int('T', params, minval=0)
|
||||||
index = self.get_int('T', params, minval=0, maxval=len(extruders)-1)
|
section = 'extruder'
|
||||||
e = extruders[index]
|
if index:
|
||||||
if self.extruder is e:
|
section = 'extruder%d' % (index,)
|
||||||
|
new_extruder = self.printer.lookup_object(section, None)
|
||||||
|
if new_extruder is None:
|
||||||
|
raise self.error("Unknown extruder %d on Tn command" % (index,))
|
||||||
|
old_extruder = self.toolhead.get_extruder()
|
||||||
|
if old_extruder is new_extruder:
|
||||||
return
|
return
|
||||||
self.run_script_from_command(self.extruder.get_activate_gcode(False))
|
self.run_script_from_command(old_extruder.get_activate_gcode(False))
|
||||||
self.toolhead.set_extruder(e)
|
print_time = self.toolhead.get_last_move_time()
|
||||||
self.extruder = e
|
old_extruder.set_active(print_time, False)
|
||||||
|
extrude_pos = new_extruder.set_active(print_time, True)
|
||||||
|
self.toolhead.set_extruder(new_extruder, extrude_pos)
|
||||||
self.reset_last_position()
|
self.reset_last_position()
|
||||||
self.extrude_factor = 1.
|
self.extrude_factor = 1.
|
||||||
self.base_position[3] = self.last_position[3]
|
self.base_position[3] = self.last_position[3]
|
||||||
self.run_script_from_command(self.extruder.get_activate_gcode(True))
|
self.run_script_from_command(new_extruder.get_activate_gcode(True))
|
||||||
def _cmd_mux(self, params):
|
def _cmd_mux(self, params):
|
||||||
key, values = self.mux_commands[params['#command']]
|
key, values = self.mux_commands[params['#command']]
|
||||||
if None in values:
|
if None in values:
|
||||||
|
|
|
@ -60,9 +60,10 @@ class PrinterExtruder:
|
||||||
self.stepper.set_trapq(self.trapq)
|
self.stepper.set_trapq(self.trapq)
|
||||||
toolhead.register_step_generator(self.stepper.generate_steps)
|
toolhead.register_step_generator(self.stepper.generate_steps)
|
||||||
toolhead.register_step_generator(self._free_moves)
|
toolhead.register_step_generator(self._free_moves)
|
||||||
# Setup SET_PRESSURE_ADVANCE command
|
# Register commands
|
||||||
gcode = self.printer.lookup_object('gcode')
|
gcode = self.printer.lookup_object('gcode')
|
||||||
if self.name == 'extruder':
|
if self.name == 'extruder':
|
||||||
|
toolhead.set_extruder(self, self.extrude_pos)
|
||||||
gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None,
|
gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None,
|
||||||
self.cmd_default_SET_PRESSURE_ADVANCE,
|
self.cmd_default_SET_PRESSURE_ADVANCE,
|
||||||
desc=self.cmd_SET_PRESSURE_ADVANCE_help)
|
desc=self.cmd_SET_PRESSURE_ADVANCE_help)
|
||||||
|
@ -236,6 +237,8 @@ class DummyExtruder:
|
||||||
return move.max_cruise_v2
|
return move.max_cruise_v2
|
||||||
def lookahead(self, moves, flush_count, lazy):
|
def lookahead(self, moves, flush_count, lazy):
|
||||||
return flush_count
|
return flush_count
|
||||||
|
def get_heater(self):
|
||||||
|
raise homing.CommandError("Extruder not configured")
|
||||||
|
|
||||||
def add_printer_objects(config):
|
def add_printer_objects(config):
|
||||||
printer = config.get_printer()
|
printer = config.get_printer()
|
||||||
|
@ -247,15 +250,3 @@ def add_printer_objects(config):
|
||||||
break
|
break
|
||||||
pe = PrinterExtruder(config.getsection(section), i)
|
pe = PrinterExtruder(config.getsection(section), i)
|
||||||
printer.add_object(section, pe)
|
printer.add_object(section, pe)
|
||||||
|
|
||||||
def get_printer_extruders(printer):
|
|
||||||
out = []
|
|
||||||
for i in range(99):
|
|
||||||
section = 'extruder'
|
|
||||||
if i:
|
|
||||||
section = 'extruder%d' % (i,)
|
|
||||||
extruder = printer.lookup_object(section, None)
|
|
||||||
if extruder is None:
|
|
||||||
break
|
|
||||||
out.append(extruder)
|
|
||||||
return out
|
|
||||||
|
|
|
@ -410,10 +410,7 @@ class ToolHead:
|
||||||
if not self.can_pause:
|
if not self.can_pause:
|
||||||
break
|
break
|
||||||
eventtime = self.reactor.pause(eventtime + 0.100)
|
eventtime = self.reactor.pause(eventtime + 0.100)
|
||||||
def set_extruder(self, extruder):
|
def set_extruder(self, extruder, extrude_pos):
|
||||||
last_move_time = self.get_last_move_time()
|
|
||||||
self.extruder.set_active(last_move_time, False)
|
|
||||||
extrude_pos = extruder.set_active(last_move_time, True)
|
|
||||||
self.extruder = extruder
|
self.extruder = extruder
|
||||||
self.move_queue.set_extruder(extruder)
|
self.move_queue.set_extruder(extruder)
|
||||||
self.commanded_pos[3] = extrude_pos
|
self.commanded_pos[3] = extrude_pos
|
||||||
|
|
Loading…
Reference in New Issue