From 551b79bc748759e1c726b297b757f8d2a97ce197 Mon Sep 17 00:00:00 2001 From: Clogged_nozzl3 <99679894+Bad-Hackerman@users.noreply.github.com> Date: Wed, 15 Jul 2026 13:42:40 +0200 Subject: [PATCH 1/2] added manual level and check bed level macros --- .../klipper/files/calibration.cfg | 95 ++++++++++++++++ .../recipes-apps/klipper/files/machine.cfg | 3 +- .../recipes-apps/klipper/files/macros.cfg | 106 ++++++++++++++++-- 3 files changed, 195 insertions(+), 9 deletions(-) diff --git a/meta-opencentauri/recipes-apps/klipper/files/calibration.cfg b/meta-opencentauri/recipes-apps/klipper/files/calibration.cfg index 05cf425e..0b8889a2 100644 --- a/meta-opencentauri/recipes-apps/klipper/files/calibration.cfg +++ b/meta-opencentauri/recipes-apps/klipper/files/calibration.cfg @@ -97,6 +97,101 @@ gcode: RESPOND TYPE=command MSG="action:prompt_footer_button Ready|_CALIBRATE_ALL_STEP_2|primary" RESPOND TYPE=command MSG="action:prompt_show" +[gcode_macro _MEASURE_BED_TILT] +gcode: + {% if "xyz" not in printer.toolhead.homed_axes %} + G28 + {% endif %} + + CLEAN_NOZZLE + SCREWS_TILT_CALCULATE_BASE + _MEASURE_BED_TILT_PROMPT + +[gcode_macro _MEASURE_BED_TILT_PROMPT] +variable_tilt_mm: 0.0 +variable_tilt_deg: 0.0 +variable_max_screw_name: '' +variable_min_screw_name: '' +variable_avg_z: 0.0 +variable_target_diff: 0.0 +gcode: + {% set stc = printer['screws_tilt_adjust'] %} + {% set stc_cfg = printer.configfile.settings['screws_tilt_adjust'] %} + {% set global = printer['gcode_macro _global_var'] %} + {% set bed_z = global.z_bed_level|float %} + {% set settings = printer['gcode_macro _COSMOS_SETTINGS']|default({}) %} + {% set endstop_z = printer.configfile.settings['stepper_z'].position_endstop|default(4)|float %} + {% set target_z = bed_z + endstop_z - 4 %} + {% set pi = 3.14159265359 %} + + {% set tilt_warn = 0.05 %} + {% set target_diff_warn = 0.20 %} + + {% set ns = namespace(zs=[], max_z=-999999.0, min_z=999999.0, max_name='', min_name='', max_x=0.0, max_y=0.0, min_x=0.0, min_y=0.0) %} + {% for n in [1, 2, 3, 4] %} + {% set key = 'screw' ~ n %} + {% set result = stc.results[key] %} + {% set coords = stc_cfg[key] %} + {% set sx = coords[0]|float %} + {% set sy = coords[1]|float %} + {% set name = stc_cfg[key ~ '_name']|default(key) %} + + {% set ns.zs = ns.zs + [result.z] %} + {% if result.z > ns.max_z %} + {% set ns.max_z = result.z %} + {% set ns.max_name = name %} + {% set ns.max_x = sx %} + {% set ns.max_y = sy %} + {% endif %} + + {% if result.z < ns.min_z %} + {% set ns.min_z = result.z %} + {% set ns.min_name = name %} + {% set ns.min_x = sx %} + {% set ns.min_y = sy %} + {% endif %} + {% endfor %} + + {% set tilt = ns.max_z - ns.min_z %} + {% set dx = ns.max_x - ns.min_x %} + {% set dy = ns.max_y - ns.min_y %} + {% set dist = (dx**2 + dy**2) ** 0.5 %} + {% set tilt_deg = (tilt / dist) * (180 / pi) if dist > 0 else 0.0 %} + {% set avg_z = (ns.zs|sum) / (ns.zs|length) %} + {% set target_diff = ((avg_z - target_z)|abs) %} + + SET_GCODE_VARIABLE MACRO=_MEASURE_BED_TILT_REPORT VARIABLE=tilt_mm VALUE={tilt} + SET_GCODE_VARIABLE MACRO=_MEASURE_BED_TILT_REPORT VARIABLE=tilt_deg VALUE={tilt_deg} + SET_GCODE_VARIABLE MACRO=_MEASURE_BED_TILT_REPORT VARIABLE=max_screw_name VALUE="'{ns.max_name}'" + SET_GCODE_VARIABLE MACRO=_MEASURE_BED_TILT_REPORT VARIABLE=min_screw_name VALUE="'{ns.min_name}'" + SET_GCODE_VARIABLE MACRO=_MEASURE_BED_TILT_REPORT VARIABLE=avg_z VALUE={avg_z} + SET_GCODE_VARIABLE MACRO=_MEASURE_BED_TILT_REPORT VARIABLE=target_diff VALUE={target_diff} + + RESPOND TYPE=command MSG="action:prompt_begin Checking Bed Level" + + {% if tilt_warn < tilt %} + RESPOND TYPE=command MSG="action:prompt_text Bed is tilted by {tilt_deg|round(3)} degrees ({tilt|round(3)}mm) between {ns.max_name} and {ns.min_name}. This can lead to prints having a tilted bottom" + {% endif %} + + {% if target_diff_warn < target_diff and avg_z > target_z %} + RESPOND TYPE=command MSG="action:prompt_text Bed is {target_diff|round(3)} too high and could cause probing issues" + {% elif target_diff_warn < target_diff and avg_z < target_z %} + RESPOND TYPE=command MSG="action:prompt_text Bed is {target_diff|round(3)} too low and could cause probing issues" + {% endif %} + + {% if tilt_warn < tilt or target_diff_warn < target_diff %} + RESPOND TYPE=command MSG="action:prompt_text It is strongly recommended that you manually level your bed, for that you will need a pair of 2.5mm hex keys" + RESPOND TYPE=command MSG="action:prompt_footer_button Skip|_CLOSE_PROMPT" + RESPOND TYPE=command MSG="action:prompt_footer_button Level Bed|MANUAL_LEVELING CALIBRATION=TRUE|warning" + RESPOND TYPE=command MSG="action:prompt_show" + {% else %} + RESPOND TYPE=command MSG="action:prompt_text Bed is flat and at the right height!" + RESPOND TYPE=command MSG="action:prompt_text If you still want to level it further you need a pair of 2.5mm hex keys" + RESPOND TYPE=command MSG="action:prompt_footer_button Level Bed|MANUAL_LEVELING CALIBRATION=TRUE" + RESPOND TYPE=command MSG="action:prompt_footer_button Continue|_CLOSE_PROMPT|warning" + RESPOND TYPE=command MSG="action:prompt_show" + {% endif %} + [gcode_macro _CALIBRATE_ALL_STEP_2] gcode: {% set settings = printer["gcode_macro _COSMOS_SETTINGS"]|default({}) %} diff --git a/meta-opencentauri/recipes-apps/klipper/files/machine.cfg b/meta-opencentauri/recipes-apps/klipper/files/machine.cfg index cf82b8f9..09f7fd2b 100644 --- a/meta-opencentauri/recipes-apps/klipper/files/machine.cfg +++ b/meta-opencentauri/recipes-apps/klipper/files/machine.cfg @@ -298,7 +298,6 @@ pid_Kp: 2 pid_Ki: 5 pid_Kd: 0.5 - [screws_tilt_adjust] screw1: 231, 25 screw1_name: front right screw @@ -310,4 +309,4 @@ screw4: 31, 25 screw4_name: front left screw horizontal_move_z: 5 speed: 300 -screw_thread: CCW-M3 +screw_thread: CCW-M4 \ No newline at end of file diff --git a/meta-opencentauri/recipes-apps/klipper/files/macros.cfg b/meta-opencentauri/recipes-apps/klipper/files/macros.cfg index 03ea49c9..1c1b7f92 100644 --- a/meta-opencentauri/recipes-apps/klipper/files/macros.cfg +++ b/meta-opencentauri/recipes-apps/klipper/files/macros.cfg @@ -10,6 +10,7 @@ variable_extruder_temp:{'probing': 140, 'cleaning': 180, 'loading': 230, 'purgin variable_fan_state:{'p1': 0.0, 'p2': 0.0, 'p3': 0.0} variable_z_maximum_lifting_distance: 256 variable_pause_resume_travel_speed: 150 +variable_z_bed_level: -2 gcode: [gcode_macro PRINT_START] @@ -585,24 +586,115 @@ gcode: LOAD_CELL_CALIBRATE TARE=TRUE PROBE_BASE {rawparams} -[gcode_macro SCREWS_TILT_CALCULATE] -rename_existing: SCREWS_TILT_CALCULATE_BASE +[gcode_macro MANUAL_LEVELING] gcode: {% set global = printer['gcode_macro _global_var'] %} {% set bed_temp = params.BED_TEMP|default(60)|int %} + {% set calibration = params.CALIBRATION|default(false)|lower == "true" %} + {% set settings = printer['gcode_macro _COSMOS_SETTINGS']|default({}) %} + {% set heatsoak = settings.heatsoak|default(1)|float %} + + M140 S{bed_temp} + M104 S{global.extruder_temp.probing} {% if "xyz" not in printer.toolhead.homed_axes %} G28 ; Home if necessary {% endif %} - + BED_MESH_CLEAR - M190 S{bed_temp} - M109 S{global.extruder_temp.probing} M400 - G28 - CLEAN_NOZZLE + {% if calibration %} + TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={bed_temp-2} MAXIMUM={bed_temp+5} + {% else %} + CLEAN_NOZZLE + TEMPERATURE_WAIT SENSOR=heater_bed MINIMUM={bed_temp-2} MAXIMUM={bed_temp+5} + SET_DISPLAY_TEXT MSG="Heatsoak: {heatsoak}m" + G4 P{(heatsoak * 60 * 1000)|int} + {% endif %} + + SCREWS_TILT_CALCULATE {rawparams} + +[gcode_macro SCREWS_TILT_CALCULATE] +rename_existing: SCREWS_TILT_CALCULATE_BASE +gcode: + {% set calibration = params.CALIBRATION|default(false)|lower == "true" %} + {% set bed_temp = params.BED_TEMP|default(60)|int %} + + _CLOSE_PROMPT + LOAD_CELL_CALIBRATE TARE=TRUE SAVE=TRUE SCREWS_TILT_CALCULATE_BASE + G1 X128 Y220 Z20 F6000 + + _SCREWS_TILT_PROMPT {rawparams} + +[gcode_macro _SCREWS_TILT_PROMPT] +gcode: + {% set stc = printer['screws_tilt_adjust'] %} + {% set calibration = params.CALIBRATION|default(false)|lower == "true" %} + {% set global = printer['gcode_macro _global_var'] %} + {% set bed_z = global.z_bed_level|float %} + {% set settings = printer['gcode_macro _COSMOS_SETTINGS']|default({}) %} + {% set endstop_z = printer.configfile.settings['stepper_z'].position_endstop|default(4)|float %} + {% set target_z = bed_z + endstop_z - 4 %} + {% set bed_temp = params.BED_TEMP|default(60)|int %} + + {% set pitch = 0.7 %} + {% set cw_raises_bed = false %} + + {% set s1 = stc.results.screw1 %}{% set d1 = s1.z - target_z %} + {% set s2 = stc.results.screw2 %}{% set d2 = s2.z - target_z %} + {% set s3 = stc.results.screw3 %}{% set d3 = s3.z - target_z %} + {% set s4 = stc.results.screw4 %}{% set d4 = s4.z - target_z %} + + {%- macro adjust(diff) -%} + {%- set need_raise = diff < 0 -%} + {%- set dir = "CW" if (need_raise == cw_raises_bed) else "CCW" -%} + {%- set turns = (diff|abs) / pitch -%} + {%- set full = turns|int -%} + {%- set mins = ((turns - full) * 60)|round|int -%} + {dir} {"%02d:%02d"|format(full, mins)} + {%- endmacro -%} + + RESPOND TYPE=command MSG="action:prompt_begin Manual Leveling" + RESPOND TYPE=command MSG="action:prompt_text Adjust screws from the top while holding the bottom with 2.5mm hex, then retry. 01:20 means 1 full turn and 20 minutes, CW=clockwise, CCW=counter-clockwise." + RESPOND TYPE=command MSG="action:prompt_text Front right screw : adjust {adjust(d1)}, z = {s1.z|round(3)}" + RESPOND TYPE=command MSG="action:prompt_text Rear right screw : adjust {adjust(d2)}, z = {s2.z|round(3)}" + RESPOND TYPE=command MSG="action:prompt_text Rear left screw : adjust {adjust(d3)}, z = {s3.z|round(3)}" + RESPOND TYPE=command MSG="action:prompt_text Front left screw : adjust {adjust(d4)}, z = {s4.z|round(3)}" + {% if calibration %} + RESPOND TYPE=command MSG="action:prompt_footer_button Done|_CLOSE_PROMPT" + {% else %} + RESPOND TYPE=command MSG="action:prompt_footer_button Done|_SCREWS_TILT_MESH" + {% endif %} + RESPOND TYPE=command MSG="action:prompt_footer_button Retry|SCREWS_TILT_CALCULATE {rawparams}|warning" + RESPOND TYPE=command MSG="action:prompt_show" + +[gcode_macro _SCREWS_TILT_MESH] +gcode: + {% set bed_temp = params.BED_TEMP|default(60)|int %} + + _CLOSE_PROMPT + LOAD_CELL_CALIBRATE TARE=TRUE SAVE=TRUE + + RESPOND TYPE=command MSG="action:prompt_begin Done Leveling" + RESPOND TYPE=command MSG="action:prompt_text With the bed now manually leveled, the printer needs to make a new bed mesh in order to print correctly." + RESPOND TYPE=command MSG="action:prompt_footer_button Skip|_SCREWS_TILT_CLOSE" + RESPOND TYPE=command MSG="action:prompt_footer_button Bed Mesh|_SCREWS_TILT_CLOSE BED_TEMP={bed_temp} MESH=TRUE|warning" + RESPOND TYPE=command MSG="action:prompt_show" + +[gcode_macro _SCREWS_TILT_CLOSE] +gcode: + {% set bed_temp = params.BED_TEMP|default(60)|int %} + {% set mesh = params.MESH|default(false)|lower == "true" %} + + _CLOSE_PROMPT + {% if mesh %} + SET_DISPLAY_TEXT MSG="Performing probe z-offset & bed mesh calibration" + BED_MESH_CALIBRATE BED_TEMP={bed_temp} + {% endif %} + TURN_OFF_HEATERS + _SAVE_CONFIG_PROMPT [gcode_macro _IDLE_TIMEOUT] gcode: From 3d23fd4080be5daa24396ff0e3ab59956ef8509c Mon Sep 17 00:00:00 2001 From: Clogged_nozzl3 <99679894+Bad-Hackerman@users.noreply.github.com> Date: Wed, 15 Jul 2026 13:46:17 +0200 Subject: [PATCH 2/2] removed 0 that stayed from testing --- meta-opencentauri/recipes-apps/klipper/files/calibration.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta-opencentauri/recipes-apps/klipper/files/calibration.cfg b/meta-opencentauri/recipes-apps/klipper/files/calibration.cfg index 0b8889a2..d01c424f 100644 --- a/meta-opencentauri/recipes-apps/klipper/files/calibration.cfg +++ b/meta-opencentauri/recipes-apps/klipper/files/calibration.cfg @@ -124,7 +124,7 @@ gcode: {% set target_z = bed_z + endstop_z - 4 %} {% set pi = 3.14159265359 %} - {% set tilt_warn = 0.05 %} + {% set tilt_warn = 0.5 %} {% set target_diff_warn = 0.20 %} {% set ns = namespace(zs=[], max_z=-999999.0, min_z=999999.0, max_name='', min_name='', max_x=0.0, max_y=0.0, min_x=0.0, min_y=0.0) %}