mirror of https://github.com/Desuuuu/klipper.git
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:
parent
ffbd2698fe
commit
eb2a67cb95
|
@ -182,6 +182,11 @@ The following standard commands are supported:
|
|||
result in excessive pressure between extruder and hot end. Do proper
|
||||
calibration steps with filament before use. If 'DISTANCE' value is
|
||||
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
|
||||
disable only the given stepper. This is a diagnostic and debugging
|
||||
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
|
||||
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
|
||||
|
||||
The following commands are available when a
|
||||
|
|
|
@ -4,36 +4,17 @@
|
|||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import logging
|
||||
import stepper
|
||||
from kinematics import extruder
|
||||
|
||||
class ExtruderStepper:
|
||||
class PrinterExtruderStepper:
|
||||
def __init__(self, config):
|
||||
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.stepper = stepper.PrinterStepper(config)
|
||||
self.stepper.setup_itersolve('extruder_stepper_alloc')
|
||||
self.printer.register_event_handler("klippy: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):
|
||||
extruder = self.printer.lookup_object(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,))
|
||||
self.extruder_stepper.sync_to_extruder(self.extruder_name)
|
||||
|
||||
def load_config_prefix(config):
|
||||
return ExtruderStepper(config)
|
||||
return PrinterExtruderStepper(config)
|
||||
|
|
|
@ -9,7 +9,7 @@ import stepper, chelper
|
|||
class ExtruderStepper:
|
||||
def __init__(self, config):
|
||||
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.
|
||||
# Setup stepper
|
||||
self.stepper = stepper.PrinterStepper(config)
|
||||
|
@ -17,9 +17,9 @@ class ExtruderStepper:
|
|||
self.sk_extruder = ffi_main.gc(ffi_lib.extruder_stepper_alloc(),
|
||||
ffi_lib.free)
|
||||
self.stepper.set_stepper_kinematics(self.sk_extruder)
|
||||
toolhead = self.printer.lookup_object('toolhead')
|
||||
toolhead.register_step_generator(self.stepper.generate_steps)
|
||||
# Register commands
|
||||
self.printer.register_event_handler("klippy:connect",
|
||||
self._handle_connect)
|
||||
gcode = self.printer.lookup_object('gcode')
|
||||
if self.name == 'extruder':
|
||||
gcode.register_mux_command("SET_PRESSURE_ADVANCE", "EXTRUDER", None,
|
||||
|
@ -31,12 +31,27 @@ class ExtruderStepper:
|
|||
gcode.register_mux_command("SET_EXTRUDER_STEP_DISTANCE", "EXTRUDER",
|
||||
self.name, self.cmd_SET_E_STEP_DISTANCE,
|
||||
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):
|
||||
return {'pressure_advance': self.pressure_advance,
|
||||
'smooth_time': self.pressure_advance_smooth_time}
|
||||
def find_past_position(self, print_time):
|
||||
mcu_pos = self.stepper.get_past_mcu_position(print_time)
|
||||
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):
|
||||
old_smooth_time = self.pressure_advance_smooth_time
|
||||
if not self.pressure_advance:
|
||||
|
@ -81,6 +96,11 @@ class ExtruderStepper:
|
|||
self.stepper.set_step_dist(dist)
|
||||
gcmd.respond_info("Extruder '%s' step distance set to %0.6f"
|
||||
% (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
|
||||
class PrinterExtruder:
|
||||
|
@ -153,11 +173,6 @@ class PrinterExtruder:
|
|||
return self.heater
|
||||
def get_trapq(self):
|
||||
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):
|
||||
return self.heater.stats(eventtime)
|
||||
def check_move(self, move):
|
||||
|
|
Loading…
Reference in New Issue