Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Automatic Bed Leveling with Conditional Gcode Iterations

    Scheduled Pinned Locked Moved
    Gcode meta commands
    5
    79
    6.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mwolterundefined
      mwolter @fcwilt
      last edited by mwolter

      @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.

      fcwiltundefined 1 Reply Last reply Reply Quote 0
      • mwolterundefined
        mwolter @Kolbi
        last edited by

        @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
        
        Kolbiundefined 1 Reply Last reply Reply Quote 0
        • Kolbiundefined
          Kolbi @mwolter
          last edited by Kolbi

          @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
           
          ;
          
          1 Reply Last reply Reply Quote 0
          • Kolbiundefined
            Kolbi
            last edited by

            @mwolter I guess the trailing code is not a hard requirement? By trailing code I'm referring to this:

             continue
            
             
            ;
            
            mwolterundefined 1 Reply Last reply Reply Quote 0
            • mwolterundefined
              mwolter @Kolbi
              last edited by

              @Kolbi nope

              1 Reply Last reply Reply Quote 0
              • mwolterundefined
                mwolter
                last edited by mwolter

                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
                
                1 Reply Last reply Reply Quote 0
                • Kolbiundefined
                  Kolbi
                  last edited by Kolbi

                  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 
                  
                  1 Reply Last reply Reply Quote 1
                  • fcwiltundefined
                    fcwilt @mwolter
                    last edited by

                    @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

                    Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                    mwolterundefined 1 Reply Last reply Reply Quote 0
                    • mwolterundefined
                      mwolter @fcwilt
                      last edited by

                      @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.

                      fcwiltundefined 1 Reply Last reply Reply Quote 0
                      • Kolbiundefined
                        Kolbi @Phaedrux
                        last edited by

                        @Phaedrux said in Automatic Bed Leveling with Conditional Gcode Iterations:

                        Now you're cooking with gas!

                        Definitely cooking with gas now!

                        1 Reply Last reply Reply Quote 0
                        • fcwiltundefined
                          fcwilt @mwolter
                          last edited by fcwilt

                          @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

                          Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                          mwolterundefined Phaedruxundefined 2 Replies Last reply Reply Quote 1
                          • mwolterundefined
                            mwolter @fcwilt
                            last edited by

                            This post is deleted!
                            1 Reply Last reply Reply Quote 0
                            • Phaedruxundefined
                              Phaedrux Moderator @fcwilt
                              last edited by

                              @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

                              Z-Bot CoreXY Build | Thingiverse Profile

                              mwolterundefined 1 Reply Last reply Reply Quote 1
                              • mwolterundefined
                                mwolter @Phaedrux
                                last edited by

                                @Phaedrux If the command G90 G1 Z20 is used in one line, does G91 have to be used to return to absolute mode?

                                Phaedruxundefined A Former User? fcwiltundefined 3 Replies Last reply Reply Quote 1
                                • Phaedruxundefined
                                  Phaedrux Moderator @mwolter
                                  last edited by

                                  @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.

                                  Z-Bot CoreXY Build | Thingiverse Profile

                                  1 Reply Last reply Reply Quote 0
                                  • Kolbiundefined
                                    Kolbi
                                    last edited by

                                    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.
                                    BMGm-BLTouch.JPG BMGm-BLTouch-Actual.jpg

                                    mwolterundefined 1 Reply Last reply Reply Quote 0
                                    • mwolterundefined
                                      mwolter @Kolbi
                                      last edited by

                                      @Kolbi looks good! Is that SLS or MJF printed?

                                      Kolbiundefined 1 Reply Last reply Reply Quote 0
                                      • Kolbiundefined
                                        Kolbi @mwolter
                                        last edited by Kolbi

                                        @mwolter It was done on an HP Multijet Fusion (MJF), using Nylon PA12.

                                        1 Reply Last reply Reply Quote 0
                                        • A Former User?
                                          A Former User @mwolter
                                          last edited by

                                          @mwolter said in Automatic Bed Leveling with Conditional Gcode Iterations:

                                          If the command G90 G1 Z20 is used in one line, does G91 have to be used to return to absolute mode?

                                          yes, g-code knows nothing about white space or line breaks

                                          (optionally you can use push and pop, M120, M121)

                                          Kolbiundefined 1 Reply Last reply Reply Quote 1
                                          • fcwiltundefined
                                            fcwilt @mwolter
                                            last edited by

                                            @mwolter said in Automatic Bed Leveling with Conditional Gcode Iterations:

                                            @Phaedrux If the command G90 G1 Z20 is used in one line, does G91 have to be used to return to absolute mode?

                                            G90 is absolute, G91 is relative.

                                            Frederick

                                            Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                                            mwolterundefined 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Unless otherwise noted, all forum content is licensed under CC-BY-SA