Thoughts on an auto-z offsett macro
-
My current workhorse is a Voron trident powered by a Duet Mini 5+ with a 1LC running RRF 3.4.4 and with that also using both a bed probe (klicky probe), and a nozzle probe located next to the bed.
The RRF macro's avalible for Voron printers don't get much work done if any at all, and the exisisting versions of the "auto-z" macro were somewhat outdated. Not using a much of the newer conditional commands we have to our disposition now.
So i sat out to make a new one, would be cool to get some input on what the hivemind thinks about it. And PLEASE come with hints on improvements or more importantly any errors/bugs!
I would say most sub-macros are quite self explanatory, but if you(?) want me to add them to see what they contain just say so
; /sys/lib/z_cal.g (v2.2) ; Called when "M98 P"/sys/lib/z_cal.g" is sent ; Used to calibrate the Z offsett between the Nozzle and buildplate. ; report whats going on M291 R"Z Offset Calibration" P"Please wait..." T0 ; leveling bed message ; ==================== ; preparation before probing ; ==================== ; the distance from the body of the klicky probe to it's own trigger point var base_Hot_offset = global.klicky_offset var add_Cold_offset = 0.06 ; remember the old offsets var old_k0_offset = sensors.probes[0].triggerHeight ; old klicky offset var old_k1_offset = sensors.probes[1].triggerHeight ; old z-pin offset ; reset existing calibration G31 K0 Z7.50 ; reset klicky G31 K1 Z0.00 ; reset z-pin ; variables for klicky calculation var temp0 = 0 ; placeholder value var temp1 = 5 ; placeholder value var temp2 = 10 ; set value above target value ; variables for z-pin calculation var temp3 = 0 ; placeholder value var temp4 = 2.5 ; placeholder value var temp5 = 5 ; set value above target value ; Make sure all axes are Homed if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed ; if axes aren't homed G28 ; home all axes else G28 Z ; probe nozzle to make Z is correct anyways ; LED status set global.sb_leds = "homing" ; Lower currents, speed & accel M98 P"/sys/lib/current/xy_current_low.g" ; set low XY currents M98 P"/sys/lib/current/z_current_low.g" ; Set low Z currents M98 P"/sys/lib/speed/speed_probing.g" ; set low speed & accel if move.axes[2].userPosition < 20 G1 Z20 F2400 ; lower Z M401 P0 ; load the klicky probe ; ====================--------------------------------------------------------- ; calibrate klicky ; ==================== ; position for probing G1 X{global.z_pin_x - 4} Y{global.z_pin_y - 23.5} F18000 ; move the klicky body over the Z-pin G1 Z10 F2400 ; move probe closer to z-pin ; lower probing speed for accuracy M558 K1 F100:50 ; lower probing speed ; probe klicky body on Z-pin, minimum 0.004mm accuracy while var.temp2 >= 0.004 G30 K1 S-1 ; probe the klicky body with the Z-pin and report value M400 ; wait for moves to finish ; lift from z-pin G91 ; relative pos G1 Z2 F500 ; quickly move up 2mm G90 ; absolute pos M400 ; wait for moves to finish ; save first probe result set var.temp0 = sensors.probes[1].lastStopHeight ;probe klicky body on Z-pin again G30 K1 S-1 ; probe the klicky body with the Z-pin and report value M400 ; wait for moves to finish ; lift from z-pin G91 ; relative pos G1 Z2 F500 ; quickly move up 2mm G90 ; absolute pos M400 ; wait for moves to finish ; save second probe result set var.temp1 = sensors.probes[1].lastStopHeight ;calculate deviation set var.temp2 = (var.temp0-var.temp1) ; calculate the new klicky offset var new_k0_offset = {((var.temp0 + var.temp1) / 2) + var.base_Hot_offset} ; compensate for cold extruder if heat.heaters[1].current < 160 set var.new_k0_offset = {var.new_k0_offset + var.add_Cold_offset} ; enable the new klicky offset G31 K0 Z{var.new_k0_offset} ; apply the new Z offsett value ; return standard probing speed M558 K1 F600:180 ; reset probing speed to normal values ;echo the klicky offset echo "Old Klicky offset " ^ var.old_k0_offset ^ " New Klicky offset " ^ var.new_k0_offset ; ====================--------------------------------------------------------- ; calibrate Z-pin ; ==================== ; move bed away from nozzle G1 Z10 F2400 ; lower the bed ; position for probing M98 P"/sys/lib/goto/bed_center.g" ; move to the center of the bed M400 ; wait for moves to finish ; lower probing speed for accuracy M558 K0 F100:50 ; lower probing speed ; probe the bed, minimum 0.004mm accuracy while var.temp5 >= 0.004 G30 K0 S-1 ; probe the klicky body with the Z-pin and report value M400 ; wait for moves to finish ; lift from z-pin G91 ; relative pos G1 Z2 F500 ; quickly move up 2mm G90 ; absolute pos M400 ; wait for moves to finish ; save first probe result set var.temp3 = sensors.probes[0].lastStopHeight ;probe klicky body on Z-pin again G30 K0 S-1 ; probe the klicky body with the Z-pin and report value M400 ; wait for moves to finish ; lift from z-pin G91 ; relative pos G1 Z2 F500 ; quickly move up 2mm G90 ; absolute pos M400 ; wait for moves to finish ; save second probe result set var.temp4 = sensors.probes[0].lastStopHeight ;calculate deviation set var.temp5 = (var.temp3-var.temp4) ; calculate the new z-pin offset var new_k1_offset = {var.new_k0_offset - ((var.temp3 + var.temp4) / 2)} ; enable the new z-pin offset G31 K1 Z{var.new_k1_offset} ; apply the new Z offsett value ; return standard probing speed M558 K0 F600:180 ; reset probing speed to normal values ; move bed away from nozzle G1 Z{global.klicky_clearance} F2400 ; lower the bed ;echo the z-pin offset echo "Old Z-pin offset " ^ var.old_k1_offset ^ " New Z-pin offset " ^ var.new_k1_offset ; ====================--------------------------------------------------------- ; finish up ; ==================== ; save the new offsets M500 P10:31 ; store the new Z offsett values to config-override.g G4 P250 ; wait 250 milliseconds M402 P0 ; dock the klicky probe ; home z with the new offsets G28 Z set global.Z_cal = true ; report whats going on M291 R"Z Offset Calibration" P"Done" T5 ; bed leveling done message ;LED status set global.sb_leds = "ready"
-
Thought it might be nice to see how it works/works in it's current state:
-
Great work! I'm thinking of adding such a setup to my V-Core in the future. Thanks for sharing, this will be helpful! It was a bit difficult to see in the vid... what sensor is being used to measure the nozzle Z position? The demo that I recently saw had an aditional fixed Z probe mounted in a corned of the bed, but watching the video it looks like you use a different approach.
-
@jbjhjm Thanks, it's working pretty well. Ofc you may have to tweak the trigger distance to fit the switches you use to make it perfect.
Yeah sorry the video was done right before i did a print, so the chamber was warm and i didn't want to open the doors and let out the heat
But it's one microswitch thats stationary relative to the bed surface to probe the nozzle tip (first and last parts of the macro).
-
@jbjhjm On the v-core we can't run the z probe in the position the voron can simply due to the fact that the toolhead never really goes out of bounds of the bed anywhere. While on the voron some space is left at the back to move out of bounds of the bed.
I'm currently working on getting this to work for the V-core at the back of the bed which brings me to a question for you @Exerqtor
In your experience, is it required to probe the body of the klicky/euclid probe or could we also get away with probing another "static" part on the toolhead for instance the fan duct and set the offset for this.
The reason I'm asking is because we can't reach the klicky body in the back of the v-core but we can reach the nozzle and the fan duct. So my current approach is to do it this way but maybe you can say more about this before I pour even more time in my current idea (which is actually almost at a point where I need to start writing code for it) -
@mher said in Thoughts on an auto-z offsett macro:
In your experience, is it required to probe the body of the klicky/euclid probe or could we also get away with probing another "static" part on the toolhead for instance the fan duct and set the offset for this.
The reason I'm asking is because we can't reach the klicky body in the back of the v-core but we can reach the nozzle and the fan duct. So my current approach is to do it this way but maybe you can say more about this before I pour even more time in my current idea (which is actually almost at a point where I need to start writing code for it)I haven't had to done this my self obviously, but if you're certain that the spot you choose to probe on the toolhead is static relative to the trigger distance of the klicky it should just be a matter of manually getting what this height is (either via CAD or with calipers or something like that, and dialing it with babystepping til you have the correct value).
This value should then be input as
global.klicky_offset
, wherever you choose to define that. I've got all my globals defined and exceuted on startup thru a macro i callglobals.g
.You would of course also alter this part of the code so that the toolhead moves over to the point where you want the toolhead to be probed:
; ====================--------------------------------------------------------- ; calibrate klicky ; ==================== ; position for probing G1 X"WHERE YOU WANT TO PROBE" Y"WHERE YOU WANT TO PROBE" F18000 ; move the klicky body over the Z-pin~~ G1 Z10 F2400 ; move probe closer to z-pin
I've got a example of my RRF config on github if you want to give it a look.
Just as a full disclaimer i can't guarantee that what were talking about here would work, but unless i've overseen something critical the above mentioned should work.
-
@Exerqtor Thanks for the response. I was thinking the same just wanted to verify.
I'll continue with my implementation and I'll most likely use your script as inspiration but I have some ideas of changing it. I hope to have something working around next week. I'll also update here if I got something up and running -
@mher Yeah, you might want to change the reset values for the probe at the start too. If you need more than 7.5mm i mean
Would love to hear what changes you were thinking about! And how it goes ofcoursue
😅
-
Have to "bite the bullet"a little bit here and admit defeat when it comes to calculating the offset for both probes.
And since i'm moving over to direct nozzle probing and ditching that second probe static to the bed i'm not inclined to try fixing it either
🤣
So i've opted to turn off the Z-pin offset calculation in the newest version of this script.
And with that i've also moved over to doing all Z homing with the klicky probe rather than on the Z-pin. This removes one "fudge" factor by only using the Z-pin to calculate the Klicky-probe offsett AND it makes transitioning to direct nozzle probing a little bit easier since down the road when it comes to homing macros etc.Version 2.3 of the macro:
; /sys/lib/z_cal.g (v2.3) ; Called when "M98 P"/sys/lib/z_cal.g" is sent ; Used to calibrate the Z offsett between the Nozzle and buildplate. ; - - ; ====================--------------------------------------------------------- ; - - ; IMPORTANT!! Do you wish to calibrate K1 / Z-pin as well? (Not working like intended as of v2.3 so I would advice to not use it!) var calibrate_Z_Pin = false ; - - ; ====================--------------------------------------------------------- ; - - ; ====================--------------------------------------------------------- ; Preparation before probing ; ==================== ; Report whats going on M291 R"Z Offset Calibration" P"Please wait..." T0 ; Leveling bed message ; The distance from the body of the klicky probe to it's own trigger point var base_Hot_offset = global.klicky_offset var add_Cold_offset = 0.06 ; Remember the old offsets var old_k0_offset = sensors.probes[0].triggerHeight ; Old klicky offset var old_k1_offset = sensors.probes[1].triggerHeight ; Old z-pin offset ; Reset existing calibration G31 K0 Z7.50 ; Reset klicky G31 K1 Z0.00 ; Reset z-pin ; Variables for klicky calculation var temp0 = 0 ; Placeholder value var temp1 = 5 ; Placeholder value var temp2 = 10 ; Set value above target value ; Variables for z-pin calculation var temp3 = 0 ; Placeholder value var temp4 = 2.5 ; Placeholder value var temp5 = 5 ; Set value above target value ; Message placeholder var consoleMessage1 = "N/A" M290 R0 S0 ; Clear babystepping ; LED status set global.sb_leds = "homing" ; ====================--------------------------------------------------------- ; Home all axes and lower the bed ; ==================== ; Make sure all axes are homed, and home Z again anyways if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed ; If axes aren't homed ; Home all axis G91 ; Relative positioning ; Lower currents, speed & accel M98 P"/sys/lib/current/xy_current_low.g" ; Set low XY currents M98 P"/sys/lib/current/z_current_low.g" ; Set low Z currents M98 P"/sys/lib/speed/speed_probing.g" ; Set low speed & accel ; Lower Z relative to current position if needed if !move.axes[2].homed ; If Z ain't homed G1 Z20 F9000 H1 ; Lower Z(bed) relative to current position elif move.axes[2].userPosition < 10 ; If Z is homed and less than 10 G1 Z20 F9000 ; Move to Z 10 ; Coarse home X or Y G1 X600 Y600 F2400 H1 ; Move quickly to X or Y endstop(first pass) ; Coarse home X G1 X600 H1 ; Move quickly to X endstop(first pass) ; Coarse home Y G1 Y600 H1 ; Move quickly to Y endstop(first pass) ; Move away from the endstops G1 X-5 Y-5 F9000 ; Go back a few mm ; Fine home X G1 X600 F360 H1 ; Move slowly to X axis endstop(second pass) ; Fine home Y G1 Y600 H1 ; move slowly to Y axis endstop(second pass) ; Absolute positioning G90 ; Absolute positioning ; Home Z ; Load the probe M400 ; Wait for moves to finish M98 P"/sys/lib/klicky/klicky_status.g" ; Refresh klicky status M401 P0 ; Load the klicky probe M400 ; Wait for moves to finish M98 P"/sys/lib/klicky/klicky_status.g" ; Refresh klicky status ; Last check to ensure klicky is attached if global.klicky_status = "attached" echo "Probe ATTACHED" else echo "Error probe not attached - aborting" M291 T5 R"Z Homing Aborted!" P"Z haven't been homed - check probe" abort ; Move to bed center and home Z M98 P"/sys/lib/goto/bed_center.g" ; Move to bed center M98 P"/sys/lib/speed/speed_probing.g" ; Set low speed & accel G30 K0 Z-99999 ; Probe the center of the bed else ; Home Z axis- ; Do nothing if XY is not homed yet if move.axes[0].homed && move.axes[1].homed M98 P"/sys/lib/current/z_current_low.g" ; Set low Z currents if !move.axes[2].homed ; If Z ain't homed G1 Z20 F9000 H1 ; Lower Z(bed) relative to current position elif move.axes[2].userPosition < 10 ; If Z is homed and less than 10 G1 Z20 F9000 ; Move to Z 10 ; Lower currents, speed & accel M98 P"/sys/lib/current/xy_current_low.g" ; Set low XY currents M98 P"/sys/lib/current/z_current_low.g" ; Set low Z currents M98 P"/sys/lib/speed/speed_probing.g" ; Set low speed & accel ; Load the probe M400 ; Wait for moves to finish M98 P"/sys/lib/klicky/klicky_status.g" ; Refresh klicky status M401 P0 ; Load the klicky probe M400 ; Wait for moves to finish M98 P"/sys/lib/klicky/klicky_status.g" ; Refresh klicky status ; Last check to ensure klicky is attached if global.klicky_status = "attached" echo "Probe ATTACHED" else echo "Error probe not attached - aborting" M291 T5 R"Z Homing Aborted!" P"Z haven't been homed - check probe" abort ; Move to bed center and home Z M98 P"/sys/lib/goto/bed_center.g" ; Move to bed center M98 P"/sys/lib/speed/speed_probing.g" ; Set low speed & accel G30 K0 Z-99999 ; Probe the center of the bed if move.axes[2].userPosition < 20 G1 Z20 F2400 ; Lower Z ; ====================--------------------------------------------------------- ; Calibrate klicky ; ==================== ; Position for probing G1 X{global.z_pin_x - 4} Y{global.z_pin_y - 23.5} F18000 ; Move the klicky body over the Z-pin G1 Z10 F2400 ; Move probe closer to z-pin ; Lower probing speed for accuracy M558 K1 F100:50 ; Lower probing speed ; Probe klicky body on Z-pin, minimum 0.004mm accuracy while var.temp2 >= 0.004 G30 K1 S-1 ; Probe the klicky body with the Z-pin and report value M400 ; Wait for moves to finish ; Lift from z-pin G91 ; Relative positioning G1 Z2 F500 ; Quickly move up 2mm G90 ; Absolute positioning M400 ; Wait for moves to finish ; Save first probe result set var.temp0 = sensors.probes[1].lastStopHeight ; Probe klicky body on Z-pin again G30 K1 S-1 ; Probe the klicky body with the Z-pin and report value M400 ; Wait for moves to finish ; Lift from z-pin G91 ; Relative positioning G1 Z2 F500 ; Quickly move up 2mm G90 ; Absolute positioning M400 ; Wait for moves to finish ; Save second probe result set var.temp1 = sensors.probes[1].lastStopHeight ;Calculate deviation set var.temp2 = (var.temp0-var.temp1) ; Calculate the new klicky offset var new_k0_offset = {((var.temp0 + var.temp1) / 2) + var.base_Hot_offset} ; Compensate for cold extruder if heat.heaters[1].current < 150 set var.new_k0_offset = {var.new_k0_offset + var.add_Cold_offset} ; Enable the new klicky offset G31 K0 Z{var.new_k0_offset} ; Apply the new Z offsett value ; Return standard probing speed M558 K1 F600:180 ; Reset probing speed to normal values ; Make a report message set var.consoleMessage1 = "Old Klicky offset " ^ var.old_k0_offset ^ " New Klicky offset " ^ var.new_k0_offset ; ====================--------------------------------------------------------- ; Calibrate Z-pin ; ==================== ; Check if Z-Pin calibration is enabled or not if var.calibrate_Z_Pin ; Message placeholder var consoleMessage2 = "N/A" ; Move bed away from nozzle G1 Z10 F2400 ; Lower the bed ; Position for probing M98 P"/sys/lib/goto/bed_center.g" ; Move to the center of the bed M400 ; Wait for moves to finish ; Lower probing speed for accuracy M558 K0 F100:50 ; Lower probing speed ; Probe the bed, minimum 0.004mm accuracy while var.temp5 >= 0.004 G30 K0 S-1 ; Probe the klicky body with the Z-pin and report value M400 ; Wait for moves to finish ; Lift from z-pin G91 ; Relative positioning G1 Z2 F500 ; Quickly move up 2mm G90 ; Absolute positioning M400 ; Wait for moves to finish ; Save first probe result set var.temp3 = sensors.probes[0].lastStopHeight ; Probe klicky body on Z-pin again G30 K0 S-1 ; Probe the klicky body with the Z-pin and report value M400 ; Wait for moves to finish ; Lift from z-pin G91 ; Relative positioning G1 Z2 F500 ; Quickly move up 2mm G90 ; Absolute positioning M400 ; Wait for moves to finish ; Save second probe result set var.temp4 = sensors.probes[0].lastStopHeight ;Calculate deviation set var.temp5 = (var.temp3-var.temp4) ; Calculate the new z-pin offset var new_k1_offset = {var.new_k0_offset - ((var.temp3 + var.temp4) / 2)} ; Enable the new z-pin offset G31 K1 Z{var.new_k1_offset} ; Apply the new Z offsett value ; Return standard probing speed M558 K0 F600:180 ; Reset probing speed to normal values ; Move bed away from nozzle G1 Z{global.klicky_clearance} F2400 ; Lower the bed ; Make a report message set var.consoleMessage2 = "Old Z-pin offset " ^ var.old_k1_offset ^ " New Z-pin offset " ^ var.new_k1_offset ; ====================--------------------------------------------------------- ; Finish up ; ==================== ; Save the new offsets M500 P10:31 ; Store the new Z offsett values to config-override.g G4 P250 ; Wait 250 milliseconds ; Lower bed to reduce pucker factor G1 Z20 F9000 ; Move to Z 20 ; Home z with the new offsets M98 P"/sys/lib/goto/bed_center.g" ; Move to bed center M98 P"/sys/lib/speed/speed_probing.g" ; Set low speed & accel G30 K0 Z-99999 ; Probe the center of the bed M400 ; Wait for moves to finish ; Report the new offsets ;K0 / klicky probe M118 P2 S{var.consoleMessage1} ; send used probe grid to paneldue M118 P3 S{var.consoleMessage1} ; send used probe grid to DWC console if var.calibrate_Z_Pin ;K1 / Z-pin M118 P2 S{var.consoleMessage2} ; send used probe grid to paneldue M118 P3 S{var.consoleMessage2} ; send used probe grid to DWC console set global.Z_cal = true ; Dock the probe M402 P0 ; Dock the klicky probe M400 ; Wait for moves to finish M98 P"/sys/lib/klicky/klicky_status.g" ; Refresh klicky status ; Full currents, speed & accel M98 P"/sys/lib/current/z_current_high.g" ; Restore normal Z currents M98 P"/sys/lib/current/xy_current_high.g" ; Set high XY currents M98 P"/sys/lib/speed/speed_printing.g" ; Restore normal speed & accels ; Lower Z(bed) after probing G90 ; Absolute positioning G1 Z5 F2400 ; Move to Z 5 ; Report whats going on M291 R"Z Offset Calibration" P"Done" T5 ; Bed leveling done message ;LED status set global.sb_leds = "ready"
I've also moved all the homing portion fully into the macro itself rather than calling for
G28
orG28 Z
that makes it "deploy" and "retract" the probe way to many times. -
-