From d4bf61262e6f78b5366fe368b3d4ec1dcbc82f60 Mon Sep 17 00:00:00 2001 From: David Smith Date: Sat, 28 Mar 2020 09:52:46 -0400 Subject: [PATCH] Extruder: Add g-code to set extruder step_distance (#2598) Signed off by: David Smith --- docs/G-Codes.md | 6 ++++++ klippy/kinematics/extruder.py | 17 +++++++++++++++++ klippy/stepper.py | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 076e31c6..c8edd792 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -162,6 +162,12 @@ The following standard commands are supported: [SMOOTH_TIME=]`: Set pressure advance parameters. If EXTRUDER is not specified, it defaults to the active extruder. +- `SET_EXTRUDER_STEP_DISTANCE [EXTRUDER=] [DISTANCE=]`: + Set a new value for the provided extruder's step_distance. Value is + not retained on Klipper reset. Use with caution, small changes can + 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. - `SET_STEPPER_ENABLE STEPPER= 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 diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index b4450596..f0264e1e 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -72,6 +72,9 @@ class PrinterExtruder: gcode.register_mux_command("ACTIVATE_EXTRUDER", "EXTRUDER", self.name, self.cmd_ACTIVATE_EXTRUDER, desc=self.cmd_ACTIVATE_EXTRUDER_help) + 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) def update_move_time(self, flush_time): self.trapq_free_moves(self.trapq, flush_time) def _set_pressure_advance(self, pressure_advance, smooth_time): @@ -185,6 +188,20 @@ class PrinterExtruder: pressure_advance, smooth_time)) self.printer.set_rollover_info(self.name, "%s: %s" % (self.name, msg)) gcode.respond_info(msg, log=False) + cmd_SET_E_STEP_DISTANCE_help = "Set extruder step distance" + def cmd_SET_E_STEP_DISTANCE(self, params): + gcode = self.printer.lookup_object('gcode') + toolhead = self.printer.lookup_object('toolhead') + if 'DISTANCE' not in params: + step_dist = self.stepper.get_step_dist() + gcode.respond_info("%s E step distance: %f" % (self.name, step_dist)) + return + dist = gcode.get_float('DISTANCE', params, 0.) + toolhead.flush_step_generation() + self.stepper.set_step_dist(self.sk_extruder, dist) + step_dist = self.stepper.get_step_dist() + gcode.respond_info("%s E step distance set: %f" % + (self.name, step_dist)) cmd_ACTIVATE_EXTRUDER_help = "Change the active extruder" def cmd_ACTIVATE_EXTRUDER(self, params): gcode = self.printer.lookup_object('gcode') diff --git a/klippy/stepper.py b/klippy/stepper.py index 747e74b3..bbe57ca5 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -94,6 +94,10 @@ class MCU_stepper: return self._oid def get_step_dist(self): return self._step_dist + def set_step_dist(self, sk, dist): + self._step_dist = dist + self.set_stepper_kinematics(sk) + logging.info("%s manually set to =%.6f", (self._name, dist)) def is_dir_inverted(self): return self._invert_dir def calc_position_from_coord(self, coord):