diff --git a/Macros_Standalone/btc_nudge/README.md b/Macros_Standalone/btc_nudge/README.md new file mode 100644 index 0000000..f8a67f6 --- /dev/null +++ b/Macros_Standalone/btc_nudge/README.md @@ -0,0 +1,52 @@ +# Overview + +btc_nudge.cfg provides macros to utilize this excellent tool by zruncho. These macros was developed as part of the [Lineux toolchanger](https://github.com/Bikin-Creative/Lineux-Toolchanger) +project. They are provided for users of toolchangers other than using viesturz excellent plugin. + +# Instructions + +Edit `btc_nudge.cfg` as below: + +``` +[gcode_button nudge_sensor_pin] +pin: ^PG15 +press_gcode: +release_gcode: +# Enter pin number your nudge tool is connected to. Leave the rest as is. +``` + +``` +[gcode_macro _nudge_variables] +variable_numoftool: [0, 1, 2, 3] # Installed tools +variable_nudge_resolution: 0.05 # Resolution should be between 0.01 - 0.1 +variable_nudge_travel_speed: 100 +# Installed tools. In case a tool is disabled, eg. for servicing, enter example [0, 1, 3], where tool 2 is disabled +# resolution must be between 0.01 - 0.1. Probing will be very very slow at highest resolution of 0.01. For faster probing, use lower resolution of 0.1. +# travel_speed, set at your usual travel speed +``` + +Save and restart firmware. + +Home All + +Z Tilt/Quad Gantry + +Home Z + +Move nozzle to a position about center of probe, and about 3mm above probe + +NUDGE_FIND_TOOL_OFFSETS + +When done, retrieve all tools offsets from console as describe below: + +![](https://github.com/Bikin-Creative/Lineux-Toolchanger/blob/main/Images/nudge_result.jpg) + +``` +Calculated offsets for this tool: +Z: -1.65 +X: -0.48 +Y: 0.45 +--- End Tool Offset Calibration --- +``` + +By using the numbers above, edit `tool_x.cfg` and enter these offsets. Scroll thru the console to get offsets for all tools. diff --git a/Macros_Standalone/btc_nudge/btc_nudge.cfg b/Macros_Standalone/btc_nudge/btc_nudge.cfg new file mode 100644 index 0000000..da9330c --- /dev/null +++ b/Macros_Standalone/btc_nudge/btc_nudge.cfg @@ -0,0 +1,218 @@ +# Nudge was created by Zruncho3d @ github.com/zruncho3d +# +# Set your nudge pin here +[gcode_button nudge_sensor_pin] +pin: ^PG15 +press_gcode: +release_gcode: + +########################################################################### +[gcode_macro _nudge_variables] +variable_numoftool: [0, 1, 2, 3] # Installed tools +variable_nudge_resolution: 0.05 # Resolution should be between 0.01 - 0.1 +variable_nudge_travel_speed: 100 +################################################################################ + +############################################################################# +# These variables are used by btc_nudge. Do not edit these +variable_nudge_last_value: -128 +variable_nudge_value_z: -128 +variable_nudge_value_x1: -128 +variable_nudge_value_x2: -128 +variable_nudge_value_y1: -128 +variable_nudge_value_y2: -128 +variable_nudge_cal_z: -128 +variable_nudge_cal_x1: -128 +variable_nudge_cal_x2: -128 +variable_nudge_cal_y1: -128 +variable_nudge_cal_y2: -128 +variable_nudge_probe_centerx: 0 +variable_nudge_probe_centery: 0 +variable_nudge_probe_centerz: 0 +gcode: +############################################################################ + +################################################################################# +# Start of btc_nudge +[gcode_macro NUDGE_FIND_TOOL_OFFSETS] +gcode: + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_probe_centerx VALUE={printer.toolhead.position.x} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_probe_centery VALUE={printer.toolhead.position.y} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_probe_centerz VALUE={printer.toolhead.position.z} + {% set numoftool = printer["gcode_macro _nudge_variables"].numoftool %} + {% for toolnumber in numoftool %} + M104 S150 T{toolnumber} + {% endfor %} + {% for tool in numoftool %} + T{tool} + _NUDGE_MOVE_OVER_PROBE + M109 T{tool} S150 + {% if tool == 0 %} + _TOOL_LOCATE_SENSOR + {% else %} + _TOOL_CALIBRATE_TOOL_OFFSET + {% endif %} + M104 T{tool} S0 + {% endfor %} + +[gcode_macro _NUDGE_MOVE_OVER_PROBE] +gcode: + {% set nudge_probe_centerx = printer["gcode_macro _nudge_variables"].nudge_probe_centerx %} + {% set nudge_probe_centery = printer["gcode_macro _nudge_variables"].nudge_probe_centery %} + {% set nudge_probe_centerz = printer["gcode_macro _nudge_variables"].nudge_probe_centerz %} + {% set nudge_travel_speed = printer["gcode_macro _nudge_variables"].nudge_travel_speed * 60 %} + G0 X{nudge_probe_centerx} Y{nudge_probe_centery} Z{nudge_probe_centerz} F{nudge_travel_speed} + +[gcode_macro _TOOL_CALIBRATE_TOOL_OFFSET] +gcode: + _TOOL_LOCATE_SENSOR CALIBRATE=True + +[gcode_macro _TOOL_LOCATE_SENSOR] +gcode: + {% set do_calibrate = params.CALIBRATE %} + G91 + {% for thisfind in ["z", "x1", "x2", "y1", "y2"] %} + _locate_sensor FINDING={thisfind} + {% endfor %} + _prn_res CALIBRATE={do_calibrate} + G90 + +[gcode_macro _locate_sensor] +gcode: + {% set finding = params.FINDING %} + {% set nudge_travel_speed = printer["gcode_macro _nudge_variables"].nudge_travel_speed * 60 %} + {% if finding == "x1" %} + G0 X-7 F{nudge_travel_speed} + G0 Z-4 + {% elif finding == "x2" %} + G0 Z4 F{nudge_travel_speed} + G0 X11 + G0 Z-4 + {% elif finding == "y1" %} + G0 Z4 F{nudge_travel_speed} + G0 X-6 Y8 + G0 Z-4 + {% elif finding == "y2" %} + G0 Z4 F{nudge_travel_speed} + G0 Y-11 + G0 Z-4 + {% endif %} + {% for moves in range(1000) %} + _do_nudge_move FINDING={finding} + {% endfor %} + {% if finding == "z" %} + {% set move_direction = "Z3" %} + {% elif finding == "x1" %} + {% set move_direction = "X-3" %} + {% elif finding == "x2" %} + {% set move_direction = "X3" %} + {% elif finding == "y1" %} + {% set move_direction = "Y3" %} + {% else %} + {% set move_direction = "Y-3" %} + {% endif %} + G0 {move_direction} F{nudge_travel_speed} + {% if finding == "y2" %} + G0 Z20 F{600} + {% endif %} + M400 + _locate_sensor_second FINDING={finding} + +[gcode_macro _locate_sensor_second] +gcode: + {% set finding = params.FINDING %} + {% set thistrigpos = printer["gcode_macro _nudge_variables"].nudge_last_value|float %} + {% set check_got_base = printer["gcode_macro _nudge_variables"].nudge_value_y2|float %} + { action_respond_info("BTC_Nudge: %s move, probe made contact at %.2f" % (finding, thistrigpos)) } + {% if check_got_base == -128 %} + {% if finding == "z" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_value_z VALUE={thistrigpos} + {% elif finding == "x1" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_value_x1 VALUE={thistrigpos} + {% elif finding == "x2" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_value_x2 VALUE={thistrigpos} + {% elif finding == "y1" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_value_y1 VALUE={thistrigpos} + {% else %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_value_y2 VALUE={thistrigpos} + {% endif %} + {% else %} + {% if finding == "z" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_cal_z VALUE={thistrigpos} + {% elif finding == "x1" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_cal_x1 VALUE={thistrigpos} + {% elif finding == "x2" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_cal_x2 VALUE={thistrigpos} + {% elif finding == "y1" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_cal_y1 VALUE={thistrigpos} + {% else %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_cal_y2 VALUE={thistrigpos} + {% endif %} + {% endif %} + +[gcode_macro _do_nudge_move] +gcode: + {% set finding = params.FINDING %} + {% set nudge_state = printer['gcode_button nudge_sensor_pin'].state %} + {% if nudge_state == "RELEASED" %} + {% set nudge_speed = printer["gcode_macro _nudge_variables"].nudge_travel_speed * 60 %} + {% set nudge_resolution = printer["gcode_macro _nudge_variables"].nudge_resolution %} + {% if finding == "z" %} + {% set move_direction = "Z-%f" % (nudge_resolution) %} + {% elif finding == "x1" %} + {% set move_direction = "X%f" % (nudge_resolution) %} + {% elif finding == "x2" %} + {% set move_direction = "X-%f" % (nudge_resolution) %} + {% elif finding == "y1" %} + {% set move_direction = "Y-%f" % (nudge_resolution) %} + {% else %} + {% set move_direction = "Y%f" % (nudge_resolution) %} + {% endif %} + G0 {move_direction} F{nudge_speed} + M400 + {% else %} + {% if finding == "z" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_last_value VALUE={printer.toolhead.position.z} + {% elif finding == "x1" or finding == "x2" %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_last_value VALUE={printer.toolhead.position.x} + {% else %} + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_last_value VALUE={printer.toolhead.position.y} + {% endif %} + {% endif %} + +[gcode_macro _prn_res] +gcode: + {% set do_calibrate = params.CALIBRATE %} + {% set refz = printer["gcode_macro _nudge_variables"].nudge_value_z|float + 3 %} + {% set refx = (printer["gcode_macro _nudge_variables"].nudge_value_x2|float - printer["gcode_macro _nudge_variables"].nudge_value_x1|float) / 2 + printer["gcode_macro _nudge_variables"].nudge_value_x1|float %} + {% set refy = (printer["gcode_macro _nudge_variables"].nudge_value_y1|float - printer["gcode_macro _nudge_variables"].nudge_value_y2|float) / 2 + printer["gcode_macro _nudge_variables"].nudge_value_y2|float %} + {% if not do_calibrate %} + { action_respond_info("BTC_Nudge: Edit macro NUDGE_MOVE_OVER_PROBE to update positions of:") } + { action_respond_info("BTC_Nudge: Z: %.2f - Safe Z" % (refz)) } + { action_respond_info("BTC_Nudge: X: %.2f - Calculated center of nozzle" % (refx)) } + { action_respond_info("BTC_Nudge: Y: %.2f - Calculated center of nozzle" % (refy)) } + { action_respond_info("BTC_Nudge: Firmware restart and repeat procedure") } + {% else %} + {% set check_got_base = printer["gcode_macro _nudge_variables"].nudge_cal_y2|float %} + { action_respond_info("BTC_Nudge: Positions of base tool0:") } + { action_respond_info("BTC_Nudge: Z: %.2f" % (refz - 3)) } + { action_respond_info("BTC_Nudge: X: %.2f" % (refx)) } + { action_respond_info("BTC_Nudge: Y: %.2f" % (refy)) } + { action_respond_info("BTC_Nudge: ------------") } + {% if check_got_base != -128 %} + {% set calz = printer["gcode_macro _nudge_variables"].nudge_cal_z|float %} + {% set calx = (printer["gcode_macro _nudge_variables"].nudge_cal_x2|float - printer["gcode_macro _nudge_variables"].nudge_cal_x1|float) / 2 + printer["gcode_macro _nudge_variables"].nudge_cal_x1|float %} + {% set caly = (printer["gcode_macro _nudge_variables"].nudge_cal_y1|float - printer["gcode_macro _nudge_variables"].nudge_cal_y2|float) / 2 + printer["gcode_macro _nudge_variables"].nudge_cal_y2|float %} + { action_respond_info("BTC_Nudge: Positions of next tool:") } + { action_respond_info("BTC_Nudge: Z: %.2f" % (calz)) } + { action_respond_info("BTC_Nudge: X: %.2f" % (calx)) } + { action_respond_info("BTC_Nudge: Y: %.2f" % (caly)) } + { action_respond_info("BTC_Nudge: ------------") } + SET_GCODE_VARIABLE MACRO=_nudge_variables VARIABLE=nudge_cal_y2 VALUE=-128 + { action_respond_info("BTC_Nudge: Calculated offsets for this tool:") } + { action_respond_info("BTC_Nudge: Z: %.2f" % (calz + 3 - refz)) } + { action_respond_info("BTC_Nudge: X: %.2f" % (calx - refx)) } + { action_respond_info("BTC_Nudge: Y: %.2f" % (caly - refy)) } + { action_respond_info("BTC_Nudge: --- End Tool Offset Calibration ---") } + {% endif %} + {% endif %} \ No newline at end of file