## KCNC Probe with endstop pin - this is used by KCNC_PROBE_* macros, not directly [gcode_macro kcnc_probee] variable_axis_endstop: "x" variable_setup_pin: "SET_PIN PIN=relay_x value=0" variable_teardown_pin: "SET_PIN PIN=relay_x value=1" variable_endstop_value_ok: 1 variable_endstop_value_hit: 0 variable_move_delay: 1 variable_move_speed: 5 variable_move_axis: "x" variable_move_offset: 0 variable_moves_left: 10 variable_run_gcode_end: "-" variable_run_delayed_gcode_end: "-" variable_move_until: "contact" variable_last_hit_found: 0 variable_last_hit_position: "-" variable_last_hit_axis: "x" variable_last_hit_axis_move_offset: 1 gcode: RESPOND PREFIX="info" MSG="KCNC Probe settings" [gcode_macro KCNC_PROBEE_RUN] gcode: {printer['gcode_macro kcnc_probee'].setup_pin} G4 P1 QUERY_ENDSTOPS KCNC_PROBEE_RUN_PRECHECK [gcode_macro KCNC_PROBEE_RUN_END] gcode: {printer['gcode_macro kcnc_probee'].teardown_pin} G4 P1 [gcode_macro KCNC_PROBEE_RUN_PRECHECK] gcode: {% if printer.query_endstops.last_query[''~printer['gcode_macro kcnc_probee'].axis_endstop] == printer['gcode_macro kcnc_probee'].endstop_value_ok %} RESPOND PREFIX="info" MSG="Probe OK, starting probing..." UPDATE_DELAYED_GCODE ID=KCNC_PROBEE_STEP DURATION=0.1 {% endif %} {% if printer.query_endstops.last_query[''~printer['gcode_macro kcnc_probee'].axis_endstop] == printer['gcode_macro kcnc_probee'].endstop_value_hit %} RESPOND PREFIX="error" MSG="Probe is engaged, please jog the probe so it does not touch anything" KCNC_PROBEE_END_NOT_FOUND {% endif %} {% if printer.query_endstops.last_query[''~printer['gcode_macro kcnc_probee'].axis_endstop] != printer['gcode_macro kcnc_probee'].endstop_value_hit and printer.query_endstops.last_query[''~printer['gcode_macro kcnc_probee'].axis_endstop] != printer['gcode_macro kcnc_probee'].endstop_value_ok %} RESPOND PREFIX="error" MSG="Error: Probe status unknown" KCNC_PROBEE_END_NOT_FOUND {% endif %} [delayed_gcode KCNC_PROBEE_STEP] initial_duration: 0 gcode: {% if printer['gcode_macro kcnc_probee'].moves_left|int > 0 %} RESPOND prefix="info" MSG="Steps left: {printer['gcode_macro kcnc_probee'].moves_left|int}" G91 G0 {printer['gcode_macro kcnc_probee'].move_axis}{printer['gcode_macro kcnc_probee'].move_offset} F{printer['gcode_macro kcnc_probee'].move_speed} G90 {% set moves_left = printer['gcode_macro kcnc_probee'].moves_left-1 %} SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=moves_left VALUE={moves_left} QUERY_ENDSTOPS G4 P{printer['gcode_macro kcnc_probee'].move_delay} KCNC_PROBEE_STEP_2 {% else %} KCNC_PROBEE_STEP_2 NOMOVE=1 {% endif %} [gcode_macro KCNC_PROBEE_STEP_2] gcode: {% set found = 0 %} {% if printer.query_endstops.last_query[''~printer['gcode_macro kcnc_probee'].axis_endstop] == printer['gcode_macro kcnc_probee'].endstop_value_hit %} {% if params.NOMOVE is defined %} RESPOND PREFIX="info" MSG="Probe finished: found something" KCNC_PROBEE_END_FOUND {% else %} RESPOND PREFIX="info" MSG="Probe hit something while moving" KCNC_PROBEE_END_FOUND {% endif %} {% endif %} {% if printer.query_endstops.last_query[''~printer['gcode_macro kcnc_probee'].axis_endstop] == printer['gcode_macro kcnc_probee'].endstop_value_ok %} {% if params.NOMOVE is defined %} RESPOND PREFIX="info" MSG="Probe finished: found nothing" KCNC_PROBEE_END_NOT_FOUND {% else %} RESPOND PREFIX="info" MSG="Probe still fine, continuing to probe" UPDATE_DELAYED_GCODE ID=KCNC_PROBEE_STEP DURATION=0.1 {% endif %} {% endif %} [gcode_macro KCNC_PROBEE_END_FOUND] gcode: {printer['gcode_macro kcnc_probee'].teardown_pin} SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_found VALUE=1 SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_axis VALUE="'{printer['gcode_macro kcnc_probee'].move_axis}'" SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_axis_move_offset VALUE="{printer['gcode_macro kcnc_probee'].move_offset}" {% if printer['gcode_macro kcnc_probee'].move_axis=='x' %} SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_position VALUE="'{printer.gcode.gcode_position.x}'" {% endif %} {% if printer['gcode_macro kcnc_probee'].move_axis=='y' %} SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_position VALUE="'{printer.gcode.gcode_position.y}'" {% endif %} {% if printer['gcode_macro kcnc_probee'].move_axis=='z' %} SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_position VALUE="'{printer.gcode.gcode_position.z}'" {% endif %} {% if printer['gcode_macro kcnc_probee'].run_gcode_end!="-" %} {printer['gcode_macro kcnc_probee'].run_gcode_end} {% endif %} {% if printer['gcode_macro kcnc_probee'].run_delayed_gcode_end!="-" %} {printer['gcode_macro kcnc_probee'].run_delayed_gcode_end} {% endif %} [gcode_macro KCNC_PROBEE_END_NOT_FOUND] gcode: {printer['gcode_macro kcnc_probee'].teardown_pin} SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_found VALUE=0 SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_position VALUE="-" SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_axis VALUE="{printer['gcode_macro kcnc_probee'].move_axis}" SET_GCODE_VARIABLE MACRO=kcnc_probee VARIABLE=last_hit_axis_move_offset VALUE="{printer['gcode_macro kcnc_probee'].move_offset}" {% if printer['gcode_macro kcnc_probee'].run_gcode_end!="-" %} {printer['gcode_macro kcnc_probee'].run_gcode_end} {% endif %} {% if printer['gcode_macro kcnc_probee'].run_delayed_gcode_end!="-" %} {printer['gcode_macro kcnc_probee'].run_delayed_gcode_end} {% endif %}