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.
    • fcwiltundefined
      fcwilt @Kolbi
      last edited by

      @Kolbi

      Hi,

      I've never used Push & Pop.

      Yes there are places where I switch to relative (G91) and shortly thereafter switch back to absolute (G90) but not that many places, primarily in the homing macros.

      If you were to look at all of the .g files in my sys directory the numbers of G90s or G91s would be small in comparison with all the other code.

      I've simply never worried about it - I use them as needed.

      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

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

        Thanks @fcwilt, much like what you have stated - I have never used M120/1 and haven't had any issues.

        But on the other side of the coin, it makes me wonder if I could/should be doing things better by employing it's use? It seems to me, with my limited duet experience, that such command would be most usefully employed by a macro being called while performing an actual print, so that the desired settings set by the slicer would 'pick up where the macro leaves off' & not so important while performing homing evolutions before a print is started.

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

          @Kolbi

          I don't rely on the commands my slicer sets at the beginning of a print.

          Here is my "print begin" macro called by the slicer at the beginning of a print.

          None of those slicer commands matter because my code overrides them all.

          ; S3D inserts the following 5 lines of code just before calling this file
          ;G90                                            ; absolute XYZ moves
          ;M83                                            ; relative E moves
          ;M106 S0                                        ; fan off
          ;M140 S60                                       ; bed temp to 60
          ;M104 S190 T0                                   ; extruder temp to 190
          
          M98 P"test_if_homed.g"				; aborts print if not homed
          
          T0                                              ; select tool 0 so extruder commands below will work
          M703                                            ; configure selected filament (sets bed/extruder temps)
          
          M106 P2 S255                                    ; lights on
          M106 P3 S255                                    ; lights on
          M106 P4 S255                                    ; lights on
          
          G90                                             ; absolute moves
          G1 Z75      F1200                               ; position for cleaning
          G1 X0 Y-145 F6000                               ; position for cleaning
          
          M291 R"Heating Extruder/Bed" P"Please wait..." T0
          
          M116                                            ; wait for temps to reach set points
          
          M291 R"Priming Extruder" P"Please wait..." T0
          
          G92 E0                                          ; reset the extruder logical position
          M83                                             ; extruder relative mode
          G1  E10 F120                                    ; prime the extruder
          M400                                            ; wait for extruding to finish
          G92 E0                                          ; reset the extruder logical position
          
          M291 R"Clean Nozzle and Bed" P"Click OK to begin printing" S3
          
          M98 P"mesh_comp_map_load.g"                     ; load height map based on height map mode
          
          
          

          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

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

            @fcwilt Thanks for that info. Could you achieve the same thing by use of start.g? If not the same because timing with regards of being called by the slicer, what does your start.g contain?

            Many thanks,
            Kolbi

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

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

              @fcwilt Thanks for that info. Could you achieve the same thing by use of start.g? If not the same because timing with regards of being called by the slicer, what does your start.g contain?

              Many thanks,
              Kolbi

              I haven't gotten around to determining exactly when start.g executes, just too many things on my plate.

              My current system works but I imagine converting it to rely on start.g would not be a problem.

              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

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

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

                too many things on my plate

                I totally understand that. Thanks again for sharing all the info.

                Cheers,
                Kolbi

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

                  I updated the first initial post to give a 'bottom line up front', the two efficient ways that were created to level the gantry, for ease of use.

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

                    @Kolbi

                    Hi,

                    Normally I invoke PRINT_BEGIN.g and PRINT_END.g from within the slicer using whatever feature the slicer provides.

                    START.g was called before the call to PRINT_BEGIN.g. That seems to happen automatically without any action on part of Simply3D (S3D).

                    PRINT_BEGIN.g was called because I invoked it within S3D in the "Starting Script" option on the "Scripts" tab.

                    STOP.g was not called at all. It seems the slicer must insert a M0 command at the end of the print to invoke STOP.g.

                    PRINT_END.g was called because I invoked it within S3D in the "Ending Script" option on the "Scripts" tab.

                    Since I want a "end of print" macro to execute, without a way to force the slicer to include M0 at the end I will stick with the "Script" options and invoke PRINT_BEGIN.g and PRINT_END.g

                    If would be nice if START.g and STOP.g would execute without any action on the part of the slicer. Then I could dispense with insuring the slicer invokes PRINT_BEGIN.g and PRINT_END.g

                    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

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

                      @fcwilt I understand, thanks!

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

                        there is also this overview https://duet3d.dozuki.com/Wiki/Macros#Section_System_Macros

                        fcwiltundefined 1 Reply Last reply Reply Quote 0
                        • fcwiltundefined
                          fcwilt @A Former User
                          last edited by

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

                          there is also this overview https://duet3d.dozuki.com/Wiki/Macros#Section_System_Macros

                          Thanks - I had not seen that.

                          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

                          1 Reply Last reply Reply Quote 0
                          • Phaedruxundefined
                            Phaedrux Moderator
                            last edited by

                            I use start.g for general print prep. Homing, preheat. Then it passes off to the slicer for setting the temps for the print. Then in the slicer start gcode section it calls a macro to print a prime line and then start the print. I do it this way so that the prime line is printed at the right temp for the material being used.

                            The slicer end gcode just contains M0 and then stop.g has all of the actual end of print commands.

                            I kind of wish there was just an end.g that could take the place of M0 -> stop.g

                            Z-Bot CoreXY Build | Thingiverse Profile

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

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

                              Then it passes off to the slicer for setting the temps for the print.

                              As you may have noticed in my print_begin.g macro I rely on the filament feature to set bed/filament temps.

                              I do wait for the temps to be reached before starting to print. I don't know what a "prime line" is - I just print a 2 line skirt so I can watch to see how the first layer is going down and adjust baby-stepping or abort, as needed.

                              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

                              Phaedruxundefined 1 Reply Last reply Reply Quote 0
                              • Phaedruxundefined
                                Phaedrux Moderator @fcwilt
                                last edited by

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

                                "prime line"

                                In my case:

                                ;M98 P"0:/sys/PrimeNozzle.g"
                                
                                G90 			; Absolute positioning
                                G1 X1 Y270 F6000 	; Move to rear left corner
                                M400 			; clear movement buffer
                                M116 			; Wait for temps
                                G1 Z0.3 F100		; Move Z to prime height
                                G91 			; Relative positioning
                                M83 			; Relative extrusion
                                G1 X40 E10 F300 	; Prime nozzle
                                G10			; Retract
                                G1 Y-1 X1 F10000 	; Wipe nozzle
                                M400
                                

                                And start.g since we're being transparent.

                                M106 P2 F30000 S0.5 H-1 C"Duet Fans"
                                M140 S65		; set heated bed to 65 and release
                                T0			; Select Tool 0
                                M291 P"Print Started. Preheating and Homing." T10
                                G4 S1
                                M98 P"0:/macros/Musical Tunes/LuckyTune.g" ; Lucky tune to start print off on the right foot
                                G4 S1
                                M220 S100		; Set speed factor back to 100% in case it was changed
                                M221 S100		; Set extrusion factor back to 100% in case it was changed
                                M290 R0 S0		; clear babystepping
                                M106 S0			; Turn part cooling blower off if it is on
                                G10 P0 R0 S80		; Set extruder to 80 and release
                                M190 S65		; set heated bed to 65 and wait
                                G28			; home XYZ
                                G29 S1			; load heightmap
                                M400
                                G10 P0 R80 S180	; Set extruder to 180 and release
                                M98 P"0:/sys/ZSpeedsPrint.g"	; Load Z speeds for printing
                                M98 P"0:/sys/CurrentsPrint.g"	; Load print motor currents
                                
                                ; Slicer Start Gcode begins.
                                

                                and stop.g for the hell of it.

                                ; stop.g
                                ; called when M0 (Stop) is run (e.g. when a print from SD card is cancelled)
                                ; Also called by slicer end gcode by M0
                                ;
                                M400			; Finish move queue
                                M104 S0 		; Extruder heater off
                                M140 S0 		; Bed heater off
                                M106 S255 		; Fan at 100 to cool nozzle and bed
                                G91			; Relative positioning
                                M220 S100		; Set speed factor back to 100% in case it was changed
                                M221 S100		; Set extrusion factor back to 100% in case it was changed
                                G1 E-2 F9000			; Retract filament 2mm
                                G1 X5 Y5 F9000		; Wipe nozzle 
                                G1 Z20 F500			; raise nozzle 5mm from printed part
                                G90				; absolute positioning
                                G1 X150 Y130 F6000		; Move x and Y axis over to bed center so probe is on top of bed
                                ;M104 S35		; Set hot end low and wait
                                G4 S60			; Wait 5 minutes
                                ;M116			; wait for temp to drop
                                G28 X Y			; Home X and Y
                                G28 X Y			; Home it again, Sam.
                                M290 R0 S0		; clear babystepping
                                M84			; Steppers off
                                M98 P"ZSpeedsNormal.g"	; Load normal z speed settings again.
                                M106 S0			; Fan off
                                M106 P2 F30000 L0.1 X0.8 B0.5 T35:70 H100:101:102 C"Duet Fans"
                                
                                ;Play a little beep beep beep to show print ended.
                                M400			; Clear queue again before jingle
                                G4 S1
                                M300 P250 S750
                                G4 P251
                                M300 P200 S1250
                                G4 P201
                                M300 P250 S750
                                G4 P251
                                M300 P200 S1250
                                G4 P201
                                M300 P250 S2500
                                G4 P251
                                M300 P150 S2000
                                G4 P151
                                M300 P150 S2500
                                G4 P151
                                M300 P350 S3700
                                G4 P351
                                

                                Z-Bot CoreXY Build | Thingiverse Profile

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

                                  @Phaedrux Thanks for sharing. Do you use filament/config.g or just use slicer start code?

                                  Phaedruxundefined 1 Reply Last reply Reply Quote 0
                                  • Phaedruxundefined
                                    Phaedrux Moderator @Kolbi
                                    last edited by

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

                                    @Phaedrux Thanks for sharing. Do you use filament/config.g or just use slicer start code?

                                    I haven't used the filaments function for a long time. I use prusa slicer and cura interchangeably. I use prusa slicer for the filaments library and refer to it when I'm setting up a print in Cura.

                                    Z-Bot CoreXY Build | Thingiverse Profile

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

                                      @Phaedrux As of thus far, me too. For some reason, it feels a bit to foreign to me to offload stuff from the slicer's start and end code spots. I do plan to slowly start migrating stuff over but only after I have everything else on point.

                                      fcwiltundefined Phaedruxundefined 2 Replies Last reply Reply Quote 0
                                      • Kolbiundefined
                                        Kolbi
                                        last edited by Kolbi

                                        @Phaedrux For prime line I made a crude random(ish) number generator to not get a 'prime line gutter' on my plates. It gives a numeric swing of 9 to -9.

                                        floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))
                                        

                                        So for the prime line, it would be (using Y as an example / with a .1mm randomness, targeted at -2):

                                        Before:
                                        G1 X0 Z0.6 Y-3.0 F3000.0;
                                        
                                        After:
                                        G1 X0 Z0.6 Y{-2+(0.1*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} F3000.0;
                                        

                                        So my use is to have the M98 P"0:/sys/PrimeLine.g" called after temps are set and obtained by the slicer's gcode.

                                        ;M98 P"0:/sys/PrimeLine.g"
                                        ;This sets up the prime to be initiated at a 'randomized' Y positon from -1.1 to -2.9
                                        G1 X0 Z0.6 Y{-2+(0.1*(floor(10*(cos(sqrt(sensors.analog[0].lastReading * state.upTime))))))} F3000.0;
                                        G92 E0.0
                                        G1 Z0.2 X100.0 E30.0 F1000.0 ; prime line
                                        G92 E0.0
                                        
                                        1 Reply Last reply Reply Quote 1
                                        • fcwiltundefined
                                          fcwilt @Kolbi
                                          last edited by

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

                                          For some reason, it feels a bit to foreign to me to offload stuff from the slicer's start and end code spots.

                                          My goal was to have as little filament related items (like temps) in the slicer since I hoped to avoid going back to the slicer to generate a new gcode file just to change a temp.

                                          So far that approach is working for me.

                                          YMMV.

                                          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

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

                                            @fcwilt That is my eventual goal also, but because from within the slicer - I use inner-slicer variables, that portion would get somewhat lost?
                                            I'm slowly brain-storming different ways to skin-the-cat, but as of this moment, it feels like I happen to be dealing with skinning Schrödinger's cat.

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