Skip to content

Commit f9acb77

Browse files
authored
ConfigGen/Macros: use zero_reference_position when using beacon true zero (#31)
* Beacon: emit zero_reference_position for bed_mesh * Macros: port RatOS-configuration#315 to configurator * Macros: only apply scan compensation if not using contact meshing
1 parent ad9fe6d commit f9acb77

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

configuration/macros.cfg

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ gcode:
306306

307307
# beacon contact config
308308
{% set beacon_contact_start_print_true_zero = true if printer["gcode_macro RatOS"].beacon_contact_start_print_true_zero|default(false)|lower == 'true' else false %}
309+
{% set beacon_contact_calibrate_model_on_print = true if printer["gcode_macro RatOS"].beacon_contact_calibrate_model_on_print|default(false)|lower == 'true' else false %}
309310

310311
# get macro parameters
311312
{% set X0 = params.X0|default(-1)|float %}
@@ -597,6 +598,17 @@ gcode:
597598
G4 P{(bed_heat_soak_time * 1000)}
598599
{% endif %}
599600

601+
# Zero z via contact if enabled.
602+
{% if printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero %}
603+
_MOVE_TO_SAFE_Z_HOME
604+
# Calibrate a new beacon model if enabled. This adapts the beacon model to the current build plate.
605+
{% if beacon_contact_calibrate_model_on_print %}
606+
BEACON_AUTO_CALIBRATE
607+
{% else %}
608+
BEACON_AUTO_CALIBRATE SKIP_MODEL_CREATION=1
609+
{% endif %}
610+
{% endif %}
611+
600612
# Run the user created "AFTER_HEATING_BED" macro
601613
_USER_START_PRINT_AFTER_HEATING_BED { rawparams }
602614

configuration/macros/mesh.cfg

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@
1010
variable_calibrate_bed_mesh: True # True|False = enable bed meshing
1111
variable_adaptive_mesh: True # True|False = enable adaptive bed meshing
1212

13+
[gcode_macro _BED_MESH_SANITY_CHECK]
14+
gcode:
15+
{% set printable_x_max = printer["gcode_macro RatOS"].printable_x_max|float %}
16+
{% set printable_y_max = printer["gcode_macro RatOS"].printable_y_max|float %}
17+
{% set safe_home_x = printer["gcode_macro RatOS"].safe_home_x %}
18+
{% if safe_home_x is not defined or safe_home_x|lower == 'middle' %}
19+
{% set safe_home_x = printable_x_max / 2 %}
20+
{% endif %}
21+
{% set safe_home_y = printer["gcode_macro RatOS"].safe_home_y %}
22+
{% if safe_home_y is not defined or safe_home_y|lower == 'middle' %}
23+
{% set safe_home_y = printable_y_max / 2 %}
24+
{% endif %}
25+
{% set beacon_contact_start_print_true_zero = true if printer["gcode_macro RatOS"].beacon_contact_start_print_true_zero|default(false)|lower == 'true' else false %}
26+
27+
{% if printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero %}
28+
{% set zero_ref_pos = printer.configfile.settings.bed_mesh.zero_reference_position %}
29+
{% if zero_ref_pos is not defined or zero_ref_pos[0] != safe_home_x or zero_ref_pos[1] != safe_home_y %}
30+
CONSOLE_ECHO TYPE="error" TITLE="Zero reference position does not match safe home position" MSG="Please update your bed mesh zero reference position in printer.cfg, like so:_N__N_[bed_mesh]_N_zero_reference_position: {safe_home_x},{safe_home_y}_N_"
31+
_STOP_AND_RAISE_ERROR MSG="Zero reference position does not match safe home position"
32+
{% endif %}
33+
{% endif %}
1334

1435
[gcode_macro _START_PRINT_BED_MESH]
1536
gcode:
@@ -112,8 +133,8 @@ gcode:
112133
{% else %}
113134
BED_MESH_CALIBRATE PROFILE={default_profile}
114135
{% endif %}
136+
_BEACON_APPLY_SCAN_COMPENSATION
115137
{% endif %}
116-
_BEACON_APPLY_SCAN_COMPENSATION
117138
{% else %}
118139
BED_MESH_CALIBRATE PROFILE={default_profile}
119140
{% endif %}
@@ -145,8 +166,8 @@ gcode:
145166
{% else %}
146167
BED_MESH_CALIBRATE PROFILE={default_profile}
147168
{% endif %}
169+
_BEACON_APPLY_SCAN_COMPENSATION
148170
{% endif %}
149-
_BEACON_APPLY_SCAN_COMPENSATION
150171
{% else %}
151172
BED_MESH_CALIBRATE PROFILE={default_profile}
152173
{% endif %}
@@ -230,14 +251,14 @@ gcode:
230251
BED_MESH_CALIBRATE PROBE_METHOD=contact USE_CONTACT_AREA=1 SAMPLES={beacon_contact_bed_mesh_samples} PROFILE={default_profile} ALGORITHM={algorithm} MESH_MIN={mesh_x0},{mesh_y0} MESH_MAX={mesh_x1},{mesh_y1} PROBE_COUNT={mesh_count_x},{mesh_count_y} RELATIVE_REFERENCE_INDEX=-1
231252
{% else %}
232253
{% if beacon_scan_method_automatic %}
233-
BED_MESH_CALIBRATE METHOD=automatic PROFILE={default_profile} ALGORITHM={algorithm} MESH_MIN={mesh_x0},{mesh_y0} MESH_MAX={mesh_x1},{mesh_y1} PROBE_COUNT={mesh_count_x},{mesh_count_y} RELATIVE_REFERENCE_INDEX=-1
254+
BED_MESH_CALIBRATE METHOD=automatic PROFILE={default_profile} ALGORITHM={algorithm} MESH_MIN={mesh_x0},{mesh_y0} MESH_MAX={mesh_x1},{mesh_y1} PROBE_COUNT={mesh_count_x},{mesh_count_y}
234255
{% else %}
235-
BED_MESH_CALIBRATE PROFILE={default_profile} ALGORITHM={algorithm} MESH_MIN={mesh_x0},{mesh_y0} MESH_MAX={mesh_x1},{mesh_y1} PROBE_COUNT={mesh_count_x},{mesh_count_y} RELATIVE_REFERENCE_INDEX=-1
256+
BED_MESH_CALIBRATE PROFILE={default_profile} ALGORITHM={algorithm} MESH_MIN={mesh_x0},{mesh_y0} MESH_MAX={mesh_x1},{mesh_y1} PROBE_COUNT={mesh_count_x},{mesh_count_y}
236257
{% endif %}
237258
{% endif %}
238259
_BEACON_APPLY_SCAN_COMPENSATION
239260
{% else %}
240-
BED_MESH_CALIBRATE PROFILE={default_profile} ALGORITHM={algorithm} MESH_MIN={mesh_x0},{mesh_y0} MESH_MAX={mesh_x1},{mesh_y1} PROBE_COUNT={mesh_count_x},{mesh_count_y} RELATIVE_REFERENCE_INDEX=-1
261+
BED_MESH_CALIBRATE PROFILE={default_profile} ALGORITHM={algorithm} MESH_MIN={mesh_x0},{mesh_y0} MESH_MAX={mesh_x1},{mesh_y1} PROBE_COUNT={mesh_count_x},{mesh_count_y}
241262
{% endif %}
242263

243264
# probe for priming

src/server/helpers/klipper-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,9 @@ export const constructKlipperConfigHelpers = async (
908908
const reminder: string[] = [];
909909
reminder.push('# REMEMBER TO CALIBRATE YOUR BEACON!');
910910
reminder.push('# Run BEACON_RATOS_CALIBRATE for automatic calibration.');
911+
result.push('# Offset mesh relative to the z height at home position');
912+
result.push('[bed_mesh]');
913+
result.push(`zero_reference_position: ${config.size.x / 2},${config.size.y / 2}`);
911914
extrasGenerator.addReminder(reminder.join('\n'));
912915
}
913916
break;

0 commit comments

Comments
 (0)