diff --git a/docs/G-Codes.md b/docs/G-Codes.md index 893993e85..e1ab0b955 100644 --- a/docs/G-Codes.md +++ b/docs/G-Codes.md @@ -459,6 +459,13 @@ parameters of an extruder stepper (as defined in an If EXTRUDER is not specified, it defaults to the stepper defined in the active hotend. +#### SET_NOZZLE_DIAMETER +`SET_NOZZLE_DIAMETER [EXTRUDER=] DIAMETER=`: +Set a new value for the nozzle diameter of the specified extruder +(as defined in an [extruder](Config_Reference.md#extruder) config section). +If EXTRUDER is not specified, it defaults to the active hotend. +Changed settings are not retained on Klipper reset. + #### SET_EXTRUDER_ROTATION_DISTANCE `SET_EXTRUDER_ROTATION_DISTANCE EXTRUDER= [DISTANCE=]`: Set a new value for the provided extruder diff --git a/klippy/kinematics/extruder.py b/klippy/kinematics/extruder.py index 684f4be71..34aa84b41 100644 --- a/klippy/kinematics/extruder.py +++ b/klippy/kinematics/extruder.py @@ -186,9 +186,15 @@ class PrinterExtruder: toolhead.set_extruder(self, 0.) gcode.register_command("M104", self.cmd_M104) gcode.register_command("M109", self.cmd_M109) + gcode.register_mux_command("SET_NOZZLE_DIAMETER", "EXTRUDER", None, + self.cmd_default_SET_NOZZLE_DIAMETER, + desc=self.cmd_SET_NOZZLE_DIAMETER_help) gcode.register_mux_command("ACTIVATE_EXTRUDER", "EXTRUDER", self.name, self.cmd_ACTIVATE_EXTRUDER, desc=self.cmd_ACTIVATE_EXTRUDER_help) + gcode.register_mux_command("SET_NOZZLE_DIAMETER", "EXTRUDER", + self.name, self.cmd_SET_NOZZLE_DIAMETER, + desc=self.cmd_SET_NOZZLE_DIAMETER_help) def get_status(self, eventtime): sts = self.heater.get_status(eventtime) sts['can_extrude'] = self.heater.can_extrude @@ -287,6 +293,25 @@ class PrinterExtruder: toolhead.flush_step_generation() toolhead.set_extruder(self, self.last_position) self.printer.send_event("extruder:activate_extruder") + cmd_SET_NOZZLE_DIAMETER_help = "Set nozzle diameter" + def cmd_default_SET_NOZZLE_DIAMETER(self, gcmd): + extruder = self.printer.lookup_object('toolhead').get_extruder() + extruder.cmd_SET_NOZZLE_DIAMETER(gcmd) + def cmd_SET_NOZZLE_DIAMETER(self, gcmd): + diameter = gcmd.get_float('DIAMETER', above=.0) + + toolhead = self.printer.lookup_object('toolhead') + toolhead.flush_step_generation() + + self.nozzle_diameter = diameter + def_max_cross_section = 4. * self.nozzle_diameter**2 + self.max_extrude_ratio = def_max_cross_section / self.filament_area + + logging.info("Nozzle diameter changed to %.2f, max_extrude_ratio=%.6f", + self.nozzle_diameter, self.max_extrude_ratio) + gcmd.respond_info("Nozzle diameter set to %.2fmm\n" + "Max extrude ratio: %.6f" + % (diameter, self.max_extrude_ratio)) # Dummy extruder class used when a printer has no extruder at all class DummyExtruder: