Skip to content

Commit

Permalink
MACRO: implement better sanity checks for VAOC (#314)
Browse files Browse the repository at this point in the history
* MACRO: implement better sanity checks for VAOC

* MACRO: fix wrong error messages for _VAOC_ENSURE_TOOLHEAD_WITHIN_CONTROL_POINT

* MACRO: use gcode_position for _VAOC_SET_TOOL

* MACRO: M400 added to _VAOC_PROBE_Z_OFFSET

* MACRO: M400 added to _VAOC_CALIBRATE_NOZZLE_TEMP_OFFSET
  • Loading branch information
HelgeKeck authored Nov 9, 2024
1 parent dbed201 commit 6c974c9
Showing 1 changed file with 121 additions and 118 deletions.
239 changes: 121 additions & 118 deletions macros/idex/vaoc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,13 @@ gcode:
# vaoc calibration under real if needed parameters are specified
{% if t0_temp > 0 and t1_temp > 0 and bed_temp > 0 %}

# check if VAOC is fixed
# vaoc sanity check
{% if not is_fixed %}
_LED_START_PRINTING_ERROR
M84
{ action_raise_error("VAOC calibration at temp works only with a fixed installed VAOC device.") }
{% endif %}

# make sure filaments are not loaded
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"] is defined %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"].filament_detected|lower == "true" %}
_LED_START_PRINTING_ERROR
M84
{ action_raise_error("Filament detected in toolhead T0. Unload filament and make sure to clean the nozzle and the melting zone.") }
{% endif %}
{% endif %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t1"] is defined %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t1"].filament_detected|lower == "true" %}
_LED_START_PRINTING_ERROR
M84
{ action_raise_error("Filament detected in toolhead T1. Unload filament and make sure to clean the nozzle and the melting zone.") }
{% endif %}
{% endif %}
_VAOC_ENSURE_FILAMENTS_ARE_NOT_LOADED

# cache filament sensor states and disable filament sensors for the start print macro
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"] is defined %}
Expand Down Expand Up @@ -141,25 +126,13 @@ gcode:
{% set idex_xcontrolpoint = svv.idex_xcontrolpoint|default(printable_x_max/2)|float %}
{% set idex_ycontrolpoint = svv.idex_ycontrolpoint|default(printable_y_max/2)|float %}
{% set idex_zcontrolpoint = svv.idex_zcontrolpoint|default(50)|float %}
{% set idex_zoffsetcontrolpoint = svv.idex_zoffsetcontrolpoint|default(0)|float %}

# echo
DEBUG_ECHO PREFIX="VAOC_START" MSG={'"xcontrolpoint: %.6f, ycontrolpoint: %.6f, zcontrolpoint: %.6f, zoffsetcontrolpoint: %.6f, expected_camera_x_position: %.6f, expected_camera_y_position: %.6f"' % (idex_xcontrolpoint, idex_ycontrolpoint, idex_zcontrolpoint, idex_zoffsetcontrolpoint, expected_camera_x_position, expected_camera_y_position)}
DEBUG_ECHO PREFIX="VAOC_START" MSG={'"xcontrolpoint: %.6f, ycontrolpoint: %.6f, zcontrolpoint: %.6f, expected_camera_x_position: %.6f, expected_camera_y_position: %.6f"' % (idex_xcontrolpoint, idex_ycontrolpoint, idex_zcontrolpoint, expected_camera_x_position, expected_camera_y_position)}

# vaoc sanity check
{% if is_fixed %}
{% if (idex_xcontrolpoint - expected_camera_x_position)|abs > 5 %}
M84
{ action_raise_error("VAOC x-control coordinate is set to %.3f but is expected to be within 5mm of %.3f. Please run '_VAOC_RESET' to roll back to default values." % (idex_xcontrolpoint, expected_camera_x_position)) }
{% endif %}
{% if (idex_ycontrolpoint - expected_camera_y_position)|abs > 5 %}
M84
{ action_raise_error("VAOC y-control coordinate is set to %.3f but is expected to be within 5mm of %.3f. Please run '_VAOC_RESET' to roll back to default values." % (idex_ycontrolpoint, expected_camera_y_position)) }
{% endif %}
{% endif %}
{% if safe_z < idex_zcontrolpoint + 2 or safe_z < idex_zoffsetcontrolpoint + 2 %}
{action_raise_error("VAOC safe_z value (%.3f) is too low, it must be higher than %.3f" % (safe_z, [idex_zoffsetcontrolpoint + 2, idex_zcontrolpoint + 2]|max))}
{% endif %}
_VAOC_ENSURE_CONTROL_POINT_WITHIN_EXPECTED_CAMERA_POS
_VAOC_ENSURE_SAFE_Z_HEIGHT

# cache toolchange config
SET_GCODE_VARIABLE MACRO=_VAOC VARIABLE=cache_toolchange_travel_speed VALUE={printer["gcode_macro RatOS"].toolchange_travel_speed|int}
Expand All @@ -186,8 +159,6 @@ gcode:
{% set parking_position_t1 = idex_xcontrolpoint + safe_distance + additional_safe_distance %}
{% endif %}

M118 10

# echo
RATOS_ECHO PREFIX="VAOC" MSG={'"START X_REFERENCE:%.6f Y_REFERENCE:%.6f Z_REFERENCE:%.6f PARK_T0:%.6f PARK_T1:%.6f"' % (idex_xcontrolpoint, idex_ycontrolpoint, idex_zcontrolpoint, parking_position_t0, parking_position_t1)}

Expand Down Expand Up @@ -426,17 +397,13 @@ gcode:
{% set idex_mode = printer["dual_carriage"].carriage_1|lower %}
{% set toolhead = 1 if idex_mode=='primary' else 0 %}

# config
{% set speed = printer["gcode_macro RatOS"].toolchange_travel_speed * 60 %}
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}

{% if toolhead == printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}
# set control point for primary toolhead

# get current toolhead position
{% set x = printer.toolhead.position.x|float %}
{% set y = printer.toolhead.position.y|float %}
{% set z = printer.toolhead.position.z|float %}
{% set x = printer.gcode_move.gcode_position.x|float %}
{% set y = printer.gcode_move.gcode_position.y|float %}
{% set z = printer.gcode_move.gcode_position.z|float %}

# save current toolhead position
SAVE_VARIABLE VARIABLE=idex_xcontrolpoint VALUE={x}
Expand Down Expand Up @@ -509,38 +476,12 @@ gcode:
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}

# vaoc config
{% set is_fixed = true if printer["gcode_macro _VAOC"].is_fixed|default(true)|lower == 'true' else false %}
{% set expected_camera_x_position = printer["gcode_macro _VAOC"].expected_camera_x_position|default(0)|float %}
{% set expected_camera_y_position = printer["gcode_macro _VAOC"].expected_camera_y_position|default(0)|float %}

# ratos variables file
{% set svv = printer.save_variables.variables %}

# get reference point coordinates
{% set idex_xcontrolpoint = svv.idex_xcontrolpoint|default(0)|float %}
{% set idex_ycontrolpoint = svv.idex_ycontrolpoint|default(0)|float %}
{% set idex_zcontrolpoint = svv.idex_zcontrolpoint|default(50)|float %}
{% set idex_zoffsetcontrolpoint = svv.idex_zoffsetcontrolpoint|default(0)|float %}

# echo
DEBUG_ECHO PREFIX="_VAOC_CALIBRATE_Z_OFFSET" MSG={'"xcontrolpoint: %.6f, ycontrolpoint: %.6f, zcontrolpoint: %.6f, zoffsetcontrolpoint: %.6f, expected_camera_x_position: %.6f, expected_camera_y_position: %.6f"' % (idex_xcontrolpoint, idex_ycontrolpoint, idex_zcontrolpoint, idex_zoffsetcontrolpoint, expected_camera_x_position, expected_camera_y_position)}

# vaoc sanity check
{% if printer.toolhead.position.y|float != idex_ycontrolpoint %}
M84
{ action_raise_error("Unexpected y-coordinate detected, VAOC aborted. Expected %.3f but got %.3f." % (idex_ycontrolpoint, printer.toolhead.position.y|float)) }
{% endif %}
{% if is_fixed %}
{% if (idex_xcontrolpoint - expected_camera_x_position)|abs > 5 %}
M84
{ action_raise_error("VAOC x-control coordinate is set to %.3f but is expected to be within 5mm of %.3f. Please run '_VAOC_RESET' to roll back to default values." % (idex_xcontrolpoint, expected_camera_x_position)) }
{% endif %}
{% if (idex_ycontrolpoint - expected_camera_y_position)|abs > 5 %}
M84
{ action_raise_error("VAOC y-control coordinate is set to %.3f but is expected to be within 5mm of %.3f. Please run '_VAOC_RESET' to roll back to default values." % (idex_ycontrolpoint, expected_camera_y_position)) }
{% endif %}
{% endif %}
_VAOC_ENSURE_TOOLHEAD_WITHIN_CONTROL_POINT
_VAOC_ENSURE_CONTROL_POINT_WITHIN_EXPECTED_CAMERA_POS

# save current toolhead position in case user has changed it
_VAOC_SET_TOOL

# automated toolhead z-offset calibration
{% set act_z = printer.toolhead.position.z|float %}
Expand Down Expand Up @@ -586,16 +527,18 @@ gcode:
{% set idex_ycontrolpoint = svv.idex_ycontrolpoint|default(30)|float %}
{% set idex_zcontrolpoint = svv.idex_zcontrolpoint|default(50)|float %}

# mave to control point
# move to control point
G1 Z{idex_zcontrolpoint} F{z_speed}
G1 X{idex_xcontrolpoint + z_offset_probe_x_offset} Y{idex_ycontrolpoint + z_offset_probe_y_offset} F{speed}
M400

# probe z-offset
_VAOC_Z_OFFSET_PROBE_CURRENT_POSITION
G0 Z{idex_zcontrolpoint} F{z_speed}
{% if not auto_z_offset %}
G1 X{idex_xcontrolpoint} Y{idex_ycontrolpoint} F{speed}
{% endif %}
M400
_VAOC_Z_OFFSET_PROBE_SAVE_PROBE_RESULT


Expand Down Expand Up @@ -693,53 +636,13 @@ gcode:
{% set z_speed = printer["gcode_macro RatOS"].macro_z_speed|float * 60 %}
{% set default_toolhead = printer["gcode_macro RatOS"].default_toolhead|default(0)|int %}

# vaoc config
{% set expected_camera_x_position = printer["gcode_macro _VAOC"].expected_camera_x_position|default(0)|float %}
{% set expected_camera_y_position = printer["gcode_macro _VAOC"].expected_camera_y_position|default(0)|float %}

# ratos variables file
{% set svv = printer.save_variables.variables %}

# get reference point coordinates
{% set idex_xcontrolpoint = svv.idex_xcontrolpoint|default(0)|float %}
{% set idex_ycontrolpoint = svv.idex_ycontrolpoint|default(0)|float %}
{% set idex_zcontrolpoint = svv.idex_zcontrolpoint|default(50)|float %}
{% set idex_zoffsetcontrolpoint = svv.idex_zoffsetcontrolpoint|default(0)|float %}

# echo
DEBUG_ECHO PREFIX="_VAOC_CALIBRATE_TEMP_OFFSET" MSG={'"xcontrolpoint: %.6f, ycontrolpoint: %.6f, zcontrolpoint: %.6f, zoffsetcontrolpoint: %.6f, expected_camera_x_position: %.6f, expected_camera_y_position: %.6f"' % (idex_xcontrolpoint, idex_ycontrolpoint, idex_zcontrolpoint, idex_zoffsetcontrolpoint, expected_camera_x_position, expected_camera_y_position)}

# vaoc sanity check
{% if printer.toolhead.position.y|float != idex_ycontrolpoint %}
M84
{ action_raise_error("Unexpected y-coordinate detected, VAOC aborted. Expected %.3f but got %.3f." % (idex_ycontrolpoint, printer.toolhead.position.y|float)) }
{% endif %}
{% if is_fixed %}
{% if (idex_xcontrolpoint - expected_camera_x_position)|abs > 5 %}
M84
{ action_raise_error("VAOC x-control coordinate is set to %.3f but is expected to be within 5mm of %.3f. Please run '_VAOC_RESET' to roll back to default values." % (idex_xcontrolpoint, expected_camera_x_position)) }
{% endif %}
{% if (idex_ycontrolpoint - expected_camera_y_position)|abs > 5 %}
M84
{ action_raise_error("VAOC y-control coordinate is set to %.3f but is expected to be within 5mm of %.3f. Please run '_VAOC_RESET' to roll back to default values." % (idex_ycontrolpoint, expected_camera_y_position)) }
{% endif %}
{% endif %}
_VAOC_ENSURE_TOOLHEAD_WITHIN_CONTROL_POINT
_VAOC_ENSURE_CONTROL_POINT_WITHIN_EXPECTED_CAMERA_POS
_VAOC_ENSURE_FILAMENTS_ARE_NOT_LOADED

# make sure filaments are not loaded
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"] is defined %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"].filament_detected|lower == "true" %}
_LED_START_PRINTING_ERROR
M84
{ action_raise_error("Filament detected in toolhead T0. Unload filament and make sure to clean the nozzle and the melting zone.") }
{% endif %}
{% endif %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t1"] is defined %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t1"].filament_detected|lower == "true" %}
_LED_START_PRINTING_ERROR
M84
{ action_raise_error("Filament detected in toolhead T1. Unload filament and make sure to clean the nozzle and the melting zone.") }
{% endif %}
{% endif %}
# save current toolhead position in case user has changed it
_VAOC_SET_TOOL

# automated toolhead z-offset calibration
{% set act_z = printer.toolhead.position.z|float %}
Expand Down Expand Up @@ -780,6 +683,7 @@ gcode:
# move to control point
G1 Z{idex_zcontrolpoint} F{z_speed}
G1 X{idex_xcontrolpoint + z_offset_probe_x_offset} Y{idex_ycontrolpoint + z_offset_probe_y_offset} F{speed}
M400

# get and set start temperature offset
_VAOC_PROBE_NOZZLE_TEMP_OFFSET TEMP=150
Expand All @@ -802,6 +706,7 @@ gcode:

# move back to control point
G1 X{idex_xcontrolpoint} Y{idex_ycontrolpoint} F{speed}
M400


[gcode_macro _VAOC_PROBE_NOZZLE_TEMP_OFFSET]
Expand Down Expand Up @@ -873,6 +778,104 @@ gcode:
CONSOLE_ECHO TITLE="Nozzle expansion coefficients:" MSG={msg} TYPE="success"


#####
# VAOC SANITY CHECKS
#####
[gcode_macro _VAOC_ENSURE_CONTROL_POINT_WITHIN_EXPECTED_CAMERA_POS]
gcode:
# vaoc config
{% set is_fixed = true if printer["gcode_macro _VAOC"].is_fixed|default(true)|lower == 'true' else false %}
{% set expected_camera_x_position = printer["gcode_macro _VAOC"].expected_camera_x_position|default(0)|float %}
{% set expected_camera_y_position = printer["gcode_macro _VAOC"].expected_camera_y_position|default(0)|float %}

# ratos variables file
{% set svv = printer.save_variables.variables %}

# get reference point coordinates
{% set idex_xcontrolpoint = svv.idex_xcontrolpoint|default(0)|float %}
{% set idex_ycontrolpoint = svv.idex_ycontrolpoint|default(0)|float %}

# echo
DEBUG_ECHO PREFIX="_VAOC_ENSURE_CONTROL_POINT_WITHIN_EXPECTED_CAMERA_POS" MSG={'"xcontrolpoint: %.6f, ycontrolpoint: %.6f, expected_camera_x_position: %.6f, expected_camera_y_position: %.6f"' % (idex_xcontrolpoint, idex_ycontrolpoint, expected_camera_x_position, expected_camera_y_position)}

{% if is_fixed %}
{% if (idex_xcontrolpoint - expected_camera_x_position)|abs > 5 %}
M84
{ action_raise_error("VAOC x-control coordinate is set to %.3f but is expected to be within 5mm of %.3f. Please run '_VAOC_RESET' to roll back to default values." % (idex_xcontrolpoint, expected_camera_x_position)) }
{% endif %}
{% if (idex_ycontrolpoint - expected_camera_y_position)|abs > 5 %}
M84
{ action_raise_error("VAOC y-control coordinate is set to %.3f but is expected to be within 5mm of %.3f. Please run '_VAOC_RESET' to roll back to default values." % (idex_ycontrolpoint, expected_camera_y_position)) }
{% endif %}
{% endif %}


[gcode_macro _VAOC_ENSURE_TOOLHEAD_WITHIN_CONTROL_POINT]
gcode:
# vaoc config
{% set is_fixed = true if printer["gcode_macro _VAOC"].is_fixed|default(true)|lower == 'true' else false %}

# ratos variables file
{% set svv = printer.save_variables.variables %}

# get reference point coordinates
{% set idex_xcontrolpoint = svv.idex_xcontrolpoint|default(0)|float %}
{% set idex_ycontrolpoint = svv.idex_ycontrolpoint|default(0)|float %}

# echo
DEBUG_ECHO PREFIX="_VAOC_ENSURE_TOOLHEAD_WITHIN_CONTROL_POINT" MSG={'"xcontrolpoint: %.6f, ycontrolpoint: %.6f"' % (idex_xcontrolpoint, idex_ycontrolpoint)}

{% if is_fixed %}
{% if (idex_xcontrolpoint - printer.gcode_move.gcode_position.x|float)|abs > 3 %}
M84
{ action_raise_error("Unexpected x-coordinate detected, VAOC aborted. Expected %.3f but got %.3f." % (idex_xcontrolpoint, printer.gcode_move.gcode_position.x|float)) }
{% endif %}
{% if (idex_ycontrolpoint - printer.gcode_move.gcode_position.y|float)|abs > 3 %}
M84
{ action_raise_error("Unexpected y-coordinate detected, VAOC aborted. Expected %.3f but got %.3f." % (idex_ycontrolpoint, printer.gcode_move.gcode_position.y|float)) }
{% endif %}
{% endif %}


[gcode_macro _VAOC_ENSURE_SAFE_Z_HEIGHT]
gcode:
# vaoc config
{% set safe_z = printer["gcode_macro _VAOC"].safe_z|float %}

# ratos variables file
{% set svv = printer.save_variables.variables %}

# get reference point coordinates
{% set idex_zcontrolpoint = svv.idex_zcontrolpoint|default(50)|float %}
{% set idex_zoffsetcontrolpoint = svv.idex_zoffsetcontrolpoint|default(0)|float %}

# echo
DEBUG_ECHO PREFIX="_VAOC_ENSURE_SAFE_Z_HEIGHT" MSG={'"idex_zcontrolpoint: %.6f, idex_zoffsetcontrolpoint: %.6f"' % (idex_zcontrolpoint, idex_zoffsetcontrolpoint)}

{% if safe_z < idex_zcontrolpoint + 2 or safe_z < idex_zoffsetcontrolpoint + 2 %}
{action_raise_error("VAOC safe_z value (%.3f) is too low, it must be higher than %.3f" % (safe_z, [idex_zoffsetcontrolpoint + 2, idex_zcontrolpoint + 2]|max))}
{% endif %}


[gcode_macro _VAOC_ENSURE_FILAMENTS_ARE_NOT_LOADED]
gcode:
# make sure filaments are not loaded
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"] is defined %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t0"].filament_detected|lower == "true" %}
_LED_START_PRINTING_ERROR
M84
{ action_raise_error("Filament detected in toolhead T0. Unload filament and make sure to clean the nozzle and the melting zone.") }
{% endif %}
{% endif %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t1"] is defined %}
{% if printer["filament_switch_sensor toolhead_filament_sensor_t1"].filament_detected|lower == "true" %}
_LED_START_PRINTING_ERROR
M84
{ action_raise_error("Filament detected in toolhead T1. Unload filament and make sure to clean the nozzle and the melting zone.") }
{% endif %}
{% endif %}


#####
# VAOC UTILS
#####
Expand Down

0 comments on commit 6c974c9

Please sign in to comment.