diff --git a/klippy/extras/c_axis_align.py b/klippy/extras/c_axis_align.py index fb580505a12b..ae188d8ff325 100644 --- a/klippy/extras/c_axis_align.py +++ b/klippy/extras/c_axis_align.py @@ -1,6 +1,8 @@ # Helper script to automate a axis offset calculation import math +import logging + RAD_TO_DEG = 57.295779513 @@ -10,16 +12,23 @@ def __init__(self, config): self.printer = config.get_printer() self.gcode_move = self.printer.load_object(config, 'gcode_move') self.gcode = self.printer.lookup_object('gcode') + self.max_repeat_probe = config.getint('max_repeat_probe', 5) + self.threshold_value = config.getfloat('threshold_value', 0.02) self.point_coords = [ [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.] ] - self.gcode.register_command('CALC_C_AXIS_ALIGN', - self.cmd_CALC_C_AXIS_ALIGN, - desc=self.cmd_CALC_C_AXIS_ALIGN_help) + self.gcode.register_command( + 'ALIGN_C_AXIS', self.cmd_ALIGN_C_AXIS, + desc=self.cmd_ALIGN_C_AXIS_help) self.gcode.register_command( 'SAVE_C_AXIS_POINT', self.cmd_SAVE_C_AXIS_POINT, desc=self.cmd_SAVE_C_AXIS_POINT_help) + self.gcode.register_command( + 'MOVE_ALIGN_C_AXIS', self.cmd_MOVE_ALIGN_C_AXIS, + desc=self.cmd_MOVE_ALIGN_C_AXIS_help) + + cmd_SAVE_C_AXIS_POINT_help = "Save point for C axis align" def cmd_SAVE_C_AXIS_POINT(self, gcmd): point_idx = gcmd.get_int('POINT', 0) @@ -37,23 +46,37 @@ def cmd_SAVE_C_AXIS_POINT(self, gcmd): for axis, coord in enumerate(coords): self.point_coords[point_idx][axis] = coord - cmd_SAVE_C_AXIS_POINT_help = "Save point for C axis align" + cmd_ALIGN_C_AXIS_help = "Calculate and apply correction for align the C axis" + + def cmd_ALIGN_C_AXIS(self, gcmd): + for i in range(self.max_repeat_probe): + self.gcode.run_script_from_command("MOVE_ALIGN_C_AXIS") + offset = self._calc_c_axis_align( + self.point_coords[0], self.point_coords[1]) + if abs(offset) <= self.threshold_value: + logging.info("align the axis C completed") + break + else: + self._apply_offset_c(offset) + + cmd_MOVE_ALIGN_C_AXIS_help = "By default, it returns the offset of the\ + axis, if necessary, perform rename_existing of this command in the macro" + def cmd_MOVE_ALIGN_C_AXIS(self, gcmd): + gcmd.respond_info("the MOVE_ALIGN_C_AXIS command is not supported") def _calc_c_axis_align(self, point_0, point_1): offset = math.atan((point_1[1] - point_0[1]) / 90) * RAD_TO_DEG / 3 + logging.info("calculate offset for the axis C: %f." % offset) return offset - def cmd_CALC_C_AXIS_ALIGN(self, gcmd): - offset = self._calc_c_axis_align( - self.point_coords[0], self.point_coords[1]) + def _apply_offset_c(self, offset): + logging.info("an offset has been applied to correct the C axis") align_gcmd = self.gcode.create_gcode_command( 'G0', 'G0', {'C': offset}) self.gcode_move.cmd_G1(align_gcmd) self.gcode_move.cmd_G92(self.gcode.create_gcode_command( 'G92', 'G92', {'C': 0})) - cmd_CALC_C_AXIS_ALIGN_help = "Calculate C axis align" - def load_config(config): CAxisAlignCalculation(config) diff --git a/stereotech_config/calibrate/probe_5d_template.cfg b/stereotech_config/calibrate/probe_5d_template.cfg index 938469c9ab2b..e6179bfd9e44 100644 --- a/stereotech_config/calibrate/probe_5d_template.cfg +++ b/stereotech_config/calibrate/probe_5d_template.cfg @@ -31,18 +31,14 @@ gcode: {% set v = 'v_' if a == 90 else '' %} SET_GCODE_VARIABLE MACRO=PROBE_TEMPLATE_POINT VARIABLE={"a_" ~ v ~"probe_z"} VALUE={printer.probe.last_result[2] - printer.gcode_move.homing_origin.z} -[gcode_macro ALIGN_C_AXIS] -description: align template along axis x -variable_repeat: 2 +[gcode_macro MOVE_ALIGN_C_AXIS] +description: moves for align template along axis X +rename_existing: MOVE_ALIGN_C_AXIS_OLD gcode: - {% set repeat = printer["gcode_macro ALIGN_C_AXIS"].repeat %} - {% for idx in range(repeat) %} - PROBE_TEMPLATE_POINT POINT=D_Y - SET_POINT MACRO=SAVE_C_AXIS_POINT POINT=1 - PROBE_TEMPLATE_POINT POINT=C_Y - SET_POINT MACRO=SAVE_C_AXIS_POINT POINT=0 - CALC_C_AXIS_ALIGN - {% endfor %} + PROBE_TEMPLATE_POINT POINT=D_Y + SET_POINT MACRO=SAVE_C_AXIS_POINT POINT=1 + PROBE_TEMPLATE_POINT POINT=C_Y + SET_POINT MACRO=SAVE_C_AXIS_POINT POINT=0 [gcode_macro MOVE_TO_AUTO_WCS] gcode: diff --git a/stereotech_config/calibrate/probe_5d_tool.cfg b/stereotech_config/calibrate/probe_5d_tool.cfg index e1be8a96a7f3..cd7e70ca93d2 100644 --- a/stereotech_config/calibrate/probe_5d_tool.cfg +++ b/stereotech_config/calibrate/probe_5d_tool.cfg @@ -160,6 +160,7 @@ gcode: {% set y = wcs_offsets[1] - offsets[1] %} {% set z = wcs_offsets[2] + offsets[2] %} {% set a = '0' if wcs == 0 else '90' %} + {% set y = y if wcs == 0 else (y - 35) %} G28 A G0 A{a} F3600 G0 Z{max_z / 2} F3600 diff --git a/stereotech_config/common/filament_control.cfg b/stereotech_config/common/filament_control.cfg index 8422e0731841..a0d4df938163 100644 --- a/stereotech_config/common/filament_control.cfg +++ b/stereotech_config/common/filament_control.cfg @@ -10,11 +10,12 @@ runout_gcode: [gcode_macro RUNOUT_GCODE_MOTION_SENSOR] gcode: {% set extruder = params.EXTRUDER|default('extruder') %} - {% set extruder_for_msg = 'extruder' if extruder == 'extruder' else 'extruder' ~ (extruder[8]|int + 1 ) %} + {% set extruder_index = 0 if extruder == 'extruder' else extruder[-1]|int %} + {% set extruder_for_msg = 'extruder' if extruder == 'extruder' else 'extruder' ~ (extruder_index + 1) %} {% if printer.virtual_sdcard.is_active %} - M117 triggered_filament_sensor{" " ~ extruder_for_msg} - {action_respond_warning('411: The filament has run out or there is a problem with its supply at the %s' % extruder_for_msg)} - RECOVER_EXTRUSION SENSOR={extruder ~ '_sensor'} + M117 {"triggered_filament_sensor" ~ extruder_index} + {action_respond_warning('411: The filament has run out or there is a problem with its supply at the %s' % extruder_for_msg)} + RECOVER_EXTRUSION SENSOR={extruder ~ '_sensor'} {% else %} {action_raise_error('401: Filament error on %s' % extruder_for_msg)} {% endif %} @@ -88,6 +89,7 @@ gcode: SET_GCODE_VARIABLE MACRO=RECOVER_EXTRUSION VARIABLE=count_triggered_sensor VALUE={printer["gcode_macro RECOVER_EXTRUSION"].count_triggered_sensor + 1} {% if not printer.pause_resume.is_paused %} PAUSE TURN_OFF_EXTRUDERS=1 E=0 STATUS_LED=error_paused + M117 all_attempt_extrude_failed {% endif %} {% endif %} diff --git a/stereotech_config/common/homing_macros.cfg b/stereotech_config/common/homing_macros.cfg index f4c61e57dc40..739f995475c1 100644 --- a/stereotech_config/common/homing_macros.cfg +++ b/stereotech_config/common/homing_macros.cfg @@ -41,7 +41,9 @@ gcode: SAVE_VARIABLES SAVE_STATE_MODULE {% else %} - ABORT + {% if (printer.manual_probe and printer.manual_probe.is_active) or (printer.bed_screws and printer.bed_screws.is_active) %} + ABORT + {% endif %} {% endif %} {% if printer.probe %} CANCEL_TEST_PROBE