extruder: Support SYNC_STEPPER_TO_EXTRUDER on extruder objects

Refactor the extruder_stepper support so that it uses the
ExtruderStepper class defined in extruder.py.

Support the SYNC_STEPPER_TO_EXTRUDER command on steppers defined in
either extruder_stepper or extruder config sections.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-01-11 15:00:36 -05:00
parent ffbd2698fe
commit eb2a67cb95
3 changed files with 33 additions and 42 deletions

View File

@ -182,6 +182,11 @@ The following standard commands are supported:
result in excessive pressure between extruder and hot end. Do proper result in excessive pressure between extruder and hot end. Do proper
calibration steps with filament before use. If 'DISTANCE' value is calibration steps with filament before use. If 'DISTANCE' value is
not included command will return current step distance. not included command will return current step distance.
- `SYNC_STEPPER_TO_EXTRUDER STEPPER=<name> [EXTRUDER=<name>]`: This
command will cause the given extruder STEPPER (as specified in an
[extruder](Config_Reference#extruder) or
[extruder stepper](Config_Reference#extruder_stepper) config
section) to become synchronized to the given EXTRUDER.
- `SET_STEPPER_ENABLE STEPPER=<config_name> ENABLE=[0|1]`: Enable or - `SET_STEPPER_ENABLE STEPPER=<config_name> ENABLE=[0|1]`: Enable or
disable only the given stepper. This is a diagnostic and debugging disable only the given stepper. This is a diagnostic and debugging
tool and must be used with care. Disabling an axis motor does not tool and must be used with care. Disabling an axis motor does not
@ -344,16 +349,6 @@ enabled:
future G-Code movement commands may run in parallel with the stepper future G-Code movement commands may run in parallel with the stepper
movement. movement.
### Extruder stepper Commands
The following command is available when an
[extruder_stepper config section](Config_Reference.md#extruder_stepper)
is enabled:
- `SYNC_STEPPER_TO_EXTRUDER STEPPER=<extruder_stepper config_name>
[EXTRUDER=<extruder config_name>]`: This command will cause the given
STEPPER to become synchronized to the given EXTRUDER, overriding
the extruder defined in the "extruder_stepper" config section.
### Probe ### Probe
The following commands are available when a The following commands are available when a

View File

@ -4,36 +4,17 @@
# #
# 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 logging import logging
import stepper from kinematics import extruder
class ExtruderStepper: class PrinterExtruderStepper:
def __init__(self, config): def __init__(self, config):
self.printer = config.get_printer() self.printer = config.get_printer()
stepper_name = config.get_name().split()[1] self.extruder_stepper = extruder.ExtruderStepper(config)
self.extruder_name = config.get('extruder', 'extruder') self.extruder_name = config.get('extruder', 'extruder')
self.stepper = stepper.PrinterStepper(config)
self.stepper.setup_itersolve('extruder_stepper_alloc')
self.printer.register_event_handler("klippy:connect", self.printer.register_event_handler("klippy:connect",
self.handle_connect) self.handle_connect)
gcode = self.printer.lookup_object('gcode')
gcode.register_mux_command("SYNC_STEPPER_TO_EXTRUDER", "STEPPER",
stepper_name,
self.cmd_SYNC_STEPPER_TO_EXTRUDER,
desc=self.cmd_SYNC_STEPPER_TO_EXTRUDER_help)
def handle_connect(self): def handle_connect(self):
extruder = self.printer.lookup_object(self.extruder_name) self.extruder_stepper.sync_to_extruder(self.extruder_name)
extruder.sync_stepper(self.stepper)
toolhead = self.printer.lookup_object('toolhead')
toolhead.register_step_generator(self.stepper.generate_steps)
cmd_SYNC_STEPPER_TO_EXTRUDER_help = "Set extruder stepper"
def cmd_SYNC_STEPPER_TO_EXTRUDER(self, gcmd):
ename = gcmd.get('EXTRUDER')
extruder = self.printer.lookup_object(ename, None)
if extruder is None:
raise gcmd.error("'%s' is not a valid extruder." % (ename,))
extruder.sync_stepper(self.stepper)
self.extruder_name = ename
gcmd.respond_info("Extruder stepper now syncing with '%s'" % (ename,))
def load_config_prefix(config): def load_config_prefix(config):
return ExtruderStepper(config) return PrinterExtruderStepper(config)

View File

@ -9,7 +9,7 @@ import stepper, chelper
class ExtruderStepper: class ExtruderStepper:
def __init__(self, config): def __init__(self, config):
self.printer = config.get_printer() self.printer = config.get_printer()
self.name = config.get_name() self.name = config.get_name().split()[-1]
self.pressure_advance = self.pressure_advance_smooth_time = 0. self.pressure_advance = self.pressure_advance_smooth_time = 0.
# Setup stepper # Setup stepper
self.stepper = stepper.PrinterStepper(config) self.stepper = stepper.PrinterStepper(config)
@ -17,9 +17,9 @@ class ExtruderStepper:
self.sk_extruder = ffi_main.gc(ffi_lib.extruder_stepper_alloc(), self.sk_extruder = ffi_main.gc(ffi_lib.extruder_stepper_alloc(),
ffi_lib.free) ffi_lib.free)
self.stepper.set_stepper_kinematics(self.sk_extruder) self.stepper.set_stepper_kinematics(self.sk_extruder)
toolhead = self.printer.lookup_object('toolhead')
toolhead.register_step_generator(self.stepper.generate_steps)
# Register commands # Register commands
self.printer.register_event_handler("klippy:connect",
self._handle_connect)
gcode = self.printer.lookup_object('gcode') gcode = self.printer.lookup_object('gcode')
if self.name == 'extruder': if self.name == 'extruder':
gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None, gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None,
@ -31,12 +31,27 @@ class ExtruderStepper:
gcode.register_mux_command("SET_EXTRUDER_STEP_DISTANCE", "EXTRUDER", gcode.register_mux_command("SET_EXTRUDER_STEP_DISTANCE", "EXTRUDER",
self.name, self.cmd_SET_E_STEP_DISTANCE, self.name, self.cmd_SET_E_STEP_DISTANCE,
desc=self.cmd_SET_E_STEP_DISTANCE_help) desc=self.cmd_SET_E_STEP_DISTANCE_help)
gcode.register_mux_command("SYNC_STEPPER_TO_EXTRUDER", "STEPPER",
self.name, self.cmd_SYNC_STEPPER_TO_EXTRUDER,
desc=self.cmd_SYNC_STEPPER_TO_EXTRUDER_help)
def _handle_connect(self):
toolhead = self.printer.lookup_object('toolhead')
toolhead.register_step_generator(self.stepper.generate_steps)
def get_status(self, eventtime): def get_status(self, eventtime):
return {'pressure_advance': self.pressure_advance, return {'pressure_advance': self.pressure_advance,
'smooth_time': self.pressure_advance_smooth_time} 'smooth_time': self.pressure_advance_smooth_time}
def find_past_position(self, print_time): def find_past_position(self, print_time):
mcu_pos = self.stepper.get_past_mcu_position(print_time) mcu_pos = self.stepper.get_past_mcu_position(print_time)
return self.stepper.mcu_to_commanded_position(mcu_pos) return self.stepper.mcu_to_commanded_position(mcu_pos)
def sync_to_extruder(self, extruder_name):
extruder = self.printer.lookup_object(extruder_name, None)
if extruder is None or not isinstance(extruder, PrinterExtruder):
raise self.printer.command_error("'%s' is not a valid extruder."
% (extruder_name,))
toolhead = self.printer.lookup_object('toolhead')
toolhead.flush_step_generation()
self.stepper.set_position([extruder.last_position, 0., 0.])
self.stepper.set_trapq(extruder.get_trapq())
def _set_pressure_advance(self, pressure_advance, smooth_time): def _set_pressure_advance(self, pressure_advance, smooth_time):
old_smooth_time = self.pressure_advance_smooth_time old_smooth_time = self.pressure_advance_smooth_time
if not self.pressure_advance: if not self.pressure_advance:
@ -81,6 +96,11 @@ class ExtruderStepper:
self.stepper.set_step_dist(dist) self.stepper.set_step_dist(dist)
gcmd.respond_info("Extruder '%s' step distance set to %0.6f" gcmd.respond_info("Extruder '%s' step distance set to %0.6f"
% (self.name, dist)) % (self.name, dist))
cmd_SYNC_STEPPER_TO_EXTRUDER_help = "Set extruder stepper"
def cmd_SYNC_STEPPER_TO_EXTRUDER(self, gcmd):
ename = gcmd.get('EXTRUDER')
self.sync_to_extruder(ename)
gcmd.respond_info("Extruder stepper now syncing with '%s'" % (ename,))
# Tracking for hotend heater, extrusion motion queue, and extruder stepper # Tracking for hotend heater, extrusion motion queue, and extruder stepper
class PrinterExtruder: class PrinterExtruder:
@ -153,11 +173,6 @@ class PrinterExtruder:
return self.heater return self.heater
def get_trapq(self): def get_trapq(self):
return self.trapq return self.trapq
def sync_stepper(self, stepper):
toolhead = self.printer.lookup_object('toolhead')
toolhead.flush_step_generation()
stepper.set_position([self.last_position, 0., 0.])
stepper.set_trapq(self.trapq)
def stats(self, eventtime): def stats(self, eventtime):
return self.heater.stats(eventtime) return self.heater.stats(eventtime)
def check_move(self, move): def check_move(self, move):