Skip to content

Commit

Permalink
Merge branch 'develop' into STEAPP-734
Browse files Browse the repository at this point in the history
  • Loading branch information
frylock34 authored Feb 12, 2024
2 parents 0613ae4 + 4dd0354 commit 592c787
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 25 deletions.
41 changes: 32 additions & 9 deletions klippy/extras/c_axis_align.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Helper script to automate a axis offset calculation

import math
import logging


RAD_TO_DEG = 57.295779513

Expand All @@ -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)
Expand All @@ -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)
18 changes: 7 additions & 11 deletions stereotech_config/calibrate/probe_5d_template.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions stereotech_config/calibrate/probe_5d_tool.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions stereotech_config/common/filament_control.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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 %}

Expand Down
4 changes: 3 additions & 1 deletion stereotech_config/common/homing_macros.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 592c787

Please sign in to comment.