Skip to content

Commit 28acb48

Browse files
committed
Mesh/Beacon: remove runtime multiplier, add runtime offset
1 parent 0161a01 commit 28acb48

File tree

3 files changed

+18
-91
lines changed

3 files changed

+18
-91
lines changed

configuration/macros/overrides.cfg

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,6 @@ gcode:
217217
RATOS_ECHO PREFIX="TEMPERATURE_WAIT" MSG="Temperature for toolhead T{t} reached."
218218

219219

220-
[gcode_macro SET_GCODE_OFFSET]
221-
rename_existing: SET_GCODE_OFFSET_ORG
222-
gcode:
223-
SET_GCODE_OFFSET_ORG { rawparams }
224-
{% if printer.configfile.settings.beacon is defined and (params.Z_ADJUST is defined or params.Z is defined) %}
225-
_BEACON_APPLY_RUNTIME_MULTIPLIER
226-
{% endif %}
227-
228-
229220
[gcode_macro SDCARD_PRINT_FILE]
230221
rename_existing: SDCARD_PRINT_FILE_BASE
231222
gcode:

configuration/macros/util.cfg

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,6 @@ gcode:
375375
gcode:
376376
M118 Click <a class="command text--blue">SAVE_CONFIG</a> to save the settings to your printer.cfg.
377377

378-
379-
[gcode_macro SAVE_Z_OFFSET]
380-
gcode:
381-
{% if printer.configfile.settings.beacon is defined %}
382-
_BEACON_SAVE_MULTIPLIER
383-
{% else %}
384-
Z_OFFSET_APPLY_PROBE
385-
{% endif %}
386-
387-
388378
[gcode_macro _LOAD_RATOS_SKEW_PROFILE]
389379
gcode:
390380
{% set ratos_skew_profile = printer["gcode_macro RatOS"].skew_profile|default("") %}

configuration/z-probe/beacon.cfg

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ variable_beacon_contact_wipe_before_true_zero: True # enables a nozzle wipe
4141
variable_beacon_contact_true_zero_temp: 150 # nozzle temperature for true zeroing
4242
# WARNING: if you're using a smooth PEI sheet, be careful with the temperature
4343

44-
variable_beacon_contact_calibrate_model_on_print: False # Calibrate a new beacon model every print, it's recommended to enable this
45-
# if you're often swapping build plates with different surface types.
44+
variable_beacon_contact_calibrate_model_on_print: True # Calibrate a new beacon model every print, it's recommended to enable this
45+
# especially if you're often swapping build plates with different surface types.
4646
# NOTE: this effectively disables z_offset on the beacon model, since a new one
4747
# will be calibrated every print, however True Zero replaces the model offset anyway.
4848

@@ -1007,82 +1007,28 @@ gcode:
10071007
BEACON_AUTO_CALIBRATE SKIP_MODEL_CREATION=1
10081008
{% endif %}
10091009

1010-
[gcode_macro _BEACON_SAVE_MULTIPLIER]
1010+
[gcode_macro _BEACON_SET_RUNTIME_OFFSET]
10111011
gcode:
1012-
# parameters
1013-
{% 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 %}
1014-
{% set beacon_contact_expansion_compensation = true if printer["gcode_macro RatOS"].beacon_contact_expansion_compensation|default(false)|lower == 'true' else false %}
1015-
{% set multiplier = printer["gcode_macro _BEACON_APPLY_RUNTIME_MULTIPLIER"].runtime_multiplier|default(-1.0)|float %}
1016-
1017-
DEBUG_ECHO PREFIX="_BEACON_SAVE_MULTIPLIER" MSG="multiplier: {multiplier}, beacon_contact_start_print_true_zero: {beacon_contact_start_print_true_zero}, beacon_contact_expansion_compensation: {beacon_contact_expansion_compensation}"
1012+
# Get the current gcode_offset, call it new_runtime_offset
1013+
{% set new_runtime_offset = printer.gcode_move.homing_origin.z %}
1014+
# Get applied expansion offset
1015+
{% set applied_expansion_offset = printer.save_variables.variables.nozzle_expansion_applied_offset|default(0)|float %}
1016+
# Subtract the applied expansion compensation offset, this needs to be calculated from the
1017+
{% set new_runtime_offset = new_runtime_offset - applied_expansion_offset %}
10181018

1019-
{% if multiplier > 0 and beacon_contact_start_print_true_zero and beacon_contact_expansion_compensation %}
1020-
SAVE_VARIABLE VARIABLE=nozzle_expansion_coefficient_multiplier VALUE={multiplier}
1021-
SET_GCODE_VARIABLE MACRO=_BEACON_APPLY_RUNTIME_MULTIPLIER VARIABLE=runtime_multiplier VALUE=-1.0
1022-
CONSOLE_ECHO TITLE="Hotend thermal expansion compensation" TYPE="success" MSG={'"New value is: %.6f_N_The new multiplier value has been saved to the configuration."' % multiplier}
1023-
{% else %}
1024-
Z_OFFSET_APPLY_PROBE
1025-
{% endif %}
1019+
# Save the result as beacon_saved_runtime_offset via SAVE_VARIABLE
1020+
SAVE_VARIABLE VARIABLE=beacon_saved_runtime_offset VALUE={new_runtime_offset}
10261021

1022+
DEBUG_ECHO PREFIX="_BEACON_SET_RUNTIME_OFFSET" MSG="Saved new runtime_offset: {new_runtime_offset}, current z_offset: {printer.gcode_move.homing_origin.z}, applied expansion offset: {applied_expansion_offset}"
10271023

1028-
[gcode_macro _BEACON_APPLY_RUNTIME_MULTIPLIER]
1029-
variable_runtime_multiplier: -1.0
1024+
[gcode_macro _BEACON_RESTORE_RUNTIME_OFFSET]
10301025
gcode:
1031-
# config
1032-
{% set toolhead = 0 %}
1033-
{% if printer["dual_carriage"] is defined %}
1034-
{% set idex_mode = printer["dual_carriage"].carriage_1|lower %}
1035-
{% set toolhead = 1 if idex_mode == 'primary' else 0 %}
1036-
{% endif %}
1037-
1038-
# beacon config
1039-
{% set beacon_contact_true_zero_temp = printer["gcode_macro RatOS"].beacon_contact_true_zero_temp|default(150)|int %}
1040-
{% 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 %}
1041-
{% set beacon_contact_expansion_compensation = true if printer["gcode_macro RatOS"].beacon_contact_expansion_compensation|default(false)|lower == 'true' else false %}
1042-
1043-
# get current layer number
1044-
{% set layer_number = printer["gcode_macro _ON_LAYER_CHANGE"].layer_number|default(0)|int %}
1026+
# Get the current GCODE_OFFSET, call it NEW_RUNTIME_OFFSET
1027+
{% set runtime_offset = printer.save_variables.variables.beacon_saved_runtime_offset|default(0) %}
1028+
{% set offset_before = printer.gcode_move.homing_origin.z %}
1029+
SET_GCODE_OFFSET Z_ADJUST={runtime_offset}
10451030

1046-
# get is printing gcode state
1047-
{% set is_printing_gcode = true if printer["gcode_macro START_PRINT"].is_printing_gcode|default(true)|lower == 'true' else false %}
1048-
1049-
{% if layer_number == 0 and is_printing_gcode %}
1050-
{% set link_url = "https://os.ratrig.com/docs/slicers" %}
1051-
{% set link_text = "RatOS Slicer Documentation" %}
1052-
{% set line_1 = '"Your slicer is not correctly reporting layer information. See the layer change custom g-code in the <a href="%s" target="_blank" >%s</a>".' % (link_url, link_text) %}
1053-
CONSOLE_ECHO TITLE="Missing layer information" TYPE="warning" MSG={line_1}
1054-
{% endif %}
1055-
1056-
DEBUG_ECHO PREFIX="_BEACON_APPLY_RUNTIME_MULTIPLIER" MSG="layer_number: {layer_number}, is_printing_gcode: {is_printing_gcode}, beacon_contact_start_print_true_zero: {beacon_contact_start_print_true_zero}, beacon_contact_expansion_compensation: {beacon_contact_expansion_compensation}"
1057-
1058-
{% if layer_number == 1 and is_printing_gcode and printer.configfile.settings.beacon is defined and beacon_contact_start_print_true_zero and beacon_contact_expansion_compensation %}
1059-
1060-
# ratos variables file
1061-
{% set svv = printer.save_variables.variables %}
1062-
1063-
# get coefficient
1064-
{% set nozzle_expansion_coefficient = svv.nozzle_expansion_coefficient_t0|default(0)|float %}
1065-
{% if toolhead == 1 %}
1066-
{% set nozzle_expansion_coefficient = svv.nozzle_expansion_coefficient_t1|default(0)|float %}
1067-
{% endif %}
1068-
1069-
# calculate new multiplier
1070-
{% set beacon_contact_expansion_multiplier = svv.nozzle_expansion_coefficient_multiplier|default(1.0)|float %}
1071-
{% set print_temp = printer["gcode_macro _BEACON_SET_NOZZLE_TEMP_OFFSET"].runtime_temp|default(0)|int %}
1072-
1073-
{% if print_temp > 0 %}
1074-
{% set z_offset = printer.gcode_move.homing_origin.z|float %}
1075-
{% set temp_delta = print_temp - beacon_contact_true_zero_temp %}
1076-
{% set coefficient_per_degree = nozzle_expansion_coefficient / 100 %}
1077-
{% set z_offset_per_degree = z_offset / temp_delta %}
1078-
{% set new_multiplier = z_offset_per_degree / coefficient_per_degree %}
1079-
1080-
DEBUG_ECHO PREFIX="_BEACON_APPLY_RUNTIME_MULTIPLIER" MSG="print_temp: {print_temp}, z_offset: {z_offset}, temp_delta: {temp_delta}, nozzle_expansion_coefficient: {nozzle_expansion_coefficient}, coefficient_per_degree: {coefficient_per_degree}, z_offset_per_degree: {z_offset_per_degree}, old_multiplier: {beacon_contact_expansion_multiplier}, new_multiplier: {new_multiplier}"
1081-
SET_GCODE_VARIABLE MACRO=_BEACON_APPLY_RUNTIME_MULTIPLIER VARIABLE=runtime_multiplier VALUE={new_multiplier}
1082-
1083-
{% endif %}
1084-
1085-
{% endif %}
1031+
DEBUG_ECHO PREFIX="_BEACON_RESTORE_RUNTIME_OFFSET" MSG="runtime_offset restored: {runtime_offset}, z offset before: {offset_before}, z offset after: {printer.gcode_move.homing_origin.z}"
10861032

10871033

10881034
[gcode_macro _BEACON_OFFSET_COMPARE]

0 commit comments

Comments
 (0)