Automatic Bed Leveling with Conditional Gcode Iterations
-
@mwolter Beautiful.
-
@mwolter Nice, thanks for that.
Being away from my printer at the moment, but I would guess the following would be a correct implementation for my dual Z setup:
!!! Please see my final code, this is not correct !!!; bed.g M561 ; clear any bed transform G28 ; home while move.calibration.initial.deviation >= 0.01 ; perform additional tramming if previous deviation was over 0.01mm if iterations = 5 ; perform 5 checks abort "!!!Failed to achieve < 0.01 deviation within 5 movements. Current deviation is " ^ move.calibration.initial.deviation ^ "mm." G30 P0 X25 Y100 Z-99999 ; probe near a leadscrew, half way along Y axis G30 P1 X235 Y100 Z-99999 S2 ; probe near a leadscrew and calibrate 2 motors G90 ; back to absolute mode echo "Bed Tramming Cycle: " ^ iterations + 2 ^ " - Difference was " ^ move.calibration.initial.deviation ^ "mm" continue ;
-
@mwolter said in Automatic Bed Leveling with Conditional Gcode Iterations:
G1 Z{move.axes[2].userPosition+20} F1200
Hi,
Why that command as opposed to G91 G1 Z20?
And why did you implement homing such that you could not safely use G28 X or G28 Y?
It would not be hard to structure it so you could.
Thanks.
Frederick
-
@fcwilt Using that command I can be sure it raised 20mm from the previous height. Probably overkill It was a quick add before posting this and thought it would help with changing the magnetic bed but it makes for an odd extra movement of the bed between performing the homez and bed leveling. I'll rework the macros to utilize the virtual homeall tool to skip the unnecessary bed movement and update the macros above.
-
@Kolbi There are too many spaces before the G30 commands and it would cause issues. Would recommend doing one leveling pass before the while command. I haven't tested the following code but it should be close.
M561 ; clear any bed transform G28 ; home G30 P0 X25 Y100 Z-99999 ; probe near a leadscrew, half way along Y axis G30 P1 X235 Y100 Z-99999 S2 ; probe near a leadscrew and calibrate 2 motors echo "Bed Tramming Cycle: 1 - Difference was " ^ move.calibration.initial.deviation ^ "mm" while move.calibration.initial.deviation >= 0.01 ; perform additional tramming if previous deviation was over 0.01mm if iterations = 5 abort "Too many auto tramming attempts" G30 P0 X25 Y100 Z-99999 ; probe near a leadscrew, half way along Y axis G30 P1 X235 Y100 Z-99999 S2 ; probe near a leadscrew and calibrate 2 motors echo "Bed Tramming Cycle: " ^ iterations + 2 ^ " - Difference was " ^ move.calibration.initial.deviation ^ "mm" continue G28 Z ; home z
-
@mwolter Thanks for covering my 6, I just caught that and was typing this:
!!! Please see my final code, this is not correct !!!; bed.g ; Called to perform automatic bed compensation via G32 M561 ; clear any bed transform G28 ; home G30 P0 X25 Y100 Z-99999 ; probe near a leadscrew, half way along Y axis G30 P1 X235 Y100 Z-99999 S2 ; probe near a leadscrew and calibrate 2 motors while move.calibration.initial.deviation >= 0.01 ; perform additional tramming if previous deviation was over 0.01mm if iterations = 5 ; perform 5 checks abort "!!!Failed to achieve < 0.01 deviation within 5 movements. Current deviation is " ^ move.calibration.initial.deviation ^ "mm." G30 P0 X25 Y100 Z-99999 ; probe near a leadscrew, half way along Y axis G30 P1 X235 Y100 Z-99999 S2 ; probe near a leadscrew and calibrate 2 motors G90 ; back to absolute mode echo "Gantry deviation of " ^ move.calibration.initial.deviation ^ "mm obtained within " ^ iterations + 2 ^ " tramming cycles." continue ;
-
@mwolter I guess the trailing code is not a hard requirement? By trailing code I'm referring to this:
continue ;
-
@Kolbi nope
-
Removed the following and added it to homeall.g since I typically do a home all before changing the bed.
G1 Z{move.axes[2].userPosition+20} F1200 ; move z up 20mm for magnetic bed replacement
homeall.g
; homeall.g ; called to home all axes (G28) ; ; Warning: do not home individual axes by calling G28 X or G28 Y. It will cause errors. Instead run the macro file directly. IE M98 P"0:/sys/homex.g" ; M563 P9 S"HomeAll" ; create tool 9 to indicate homeall is in progress ; G91 ; relative positioning G1 Z5 F6000 H2 ; lift Z relative to current position M98 P"0:/sys/homey.g" ; home y M98 P"0:/sys/homex.g" ; home x G90 ; absolute positioning ; M98 P"0:/sys/homez.g" ; home z ; M563 P9 D-1 H-1 ; delete tool 9 to indicate homeall is done ; G1 Z{move.axes[2].userPosition+50} F1200 ; move z up 50mm for magnetic bed replacement
-
Thanks @mwolter!
For brevity, here is my final working version:
; bed.g ; Called to perform automatic bed compensation via G32 M561 ; Clear any bed transform G28 ; Home while iterations <=1 ; Do minimum of 2 passes G30 P0 X25 Y100 Z-99999 ; Probe near a leadscrew, half way along Y axis G30 P1 X235 Y100 Z-99999 S2 ; Probe near a leadscrew and calibrate 2 motors G90 while move.calibration.initial.deviation >= 0.002 ; perform additional tramming if previous deviation was over 0.002mm if iterations = 5 ; Perform 5 checks M300 S3000 P500 ; Sound alert, required deviation could not be achieved abort "!!! ABORTED !!! Failed to achieve < 0.002 deviation within 5 movements. Current deviation is " ^ move.calibration.initial.deviation ^ "mm." G30 P0 X25 Y100 Z-99999 ; Probe near a leadscrew, half way along Y axis G30 P1 X235 Y100 Z-99999 S2 ; Probe near a leadscrew and calibrate 2 motors G90 ; Back to absolute mode echo "Gantry deviation of " ^ move.calibration.initial.deviation ^ "mm obtained." G1 H2 Z8 F2600 ; Raise head 8mm to ensure it is above the Z probe trigger height G1 X104 Y100 F6000 ; Put head over the centre of the bed, or wherever you want to probe G30
-
@mwolter said in Automatic Bed Leveling with Conditional Gcode Iterations:
@fcwilt Using that command I can be sure it raised 20mm from the previous height.
Hi,
Thanks for the reply.
Why do you think G91 G1 Z20 doesn't do that same thing?
Frederick
-
@fcwilt
Itโs just a different way of doing it and like I mentioned, this way I can be sure itโs raised 20mm from its current position. The G30 command actually sets Z to about 3m. So G1 Z20 will only raise Z by 17mm. -
@Phaedrux said in Automatic Bed Leveling with Conditional Gcode Iterations:
Now you're cooking with gas!
Definitely cooking with gas now!
-
@mwolter said in Automatic Bed Leveling with Conditional Gcode Iterations:
The G30 command actually sets Z to about 3m. So G1 Z20 will only raise Z by 17mm.I think you will find that a G91 G1 Z20 will raise Z by 20 unless it doesn't have that much room left on the axis.
If a G30 sets Z to 3 then a G91 G1 Z20 will take Z to 23.
At least that is my experience.
Good luck.
Frederick
-
This post is deleted! -
@fcwilt said in Automatic Bed Leveling with Conditional Gcode Iterations:
I think you will find that a G91 G1 Z20 will raise Z by 20 unless it doesn't have that much room left of the axis.
Correct. G90 moves to an absolute point, G91 is relative to the current position.
https://duet3d.dozuki.com/Wiki/Gcode#Section_G90_Set_to_Absolute_Positioning
-
@Phaedrux If the command G90 G1 Z20 is used in one line, does G91 have to be used to return to absolute mode?
-
@mwolter That's a good question, and I'm not sure off the top of my head. Would have to test to see if it sticks in that format or not.
-
Another thing I noticed is repeatability with PindaV2 probe is not as consistent as BLTouchV3.1... So being that I use a bondtech bmg mosquito, I've made this modified version to scrap the Pinda and welcome the BLTouch. Will get it sorted on the printer and test it fully this weekend.
-
@Kolbi looks good! Is that SLS or MJF printed?