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

    Conditonal script for homing and autolevel - help!

    Scheduled Pinned Locked Moved
    Gcode meta commands
    4
    12
    768
    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.
    • PaulHewundefined
      PaulHew
      last edited by

      I need some help with conditional code please.
      I looked at an example and my skills are limited in this particular coding.

      My RailCore II is a CoreXY, 3 steppers on the Z axis. Running

      Board: Duet Ethernet 1.02 or later + DueX5
      Firmware: RepRapFirmware for Duet 2 WiFi/Ethernet 3.01-RC6 (2020-04-03b3)
      

      In my start GCode for PrusaSlicer it runs the following lines.

      G28 ; home all axes
      G32 ; Autocalibrate bed
      G32 ; Autocalibrate bed a second time
      G32 ; And a third time ( for 4 point probe)
      

      I would like it not to have to do this every-time I print, especially when printing calibration items.
      I understand that if it is powered off or I use M84 it will need homing and leveling again.

      Can someone help in streamlining my homing with conditionals, please

      Kind Regards,
      Paul.

      RailCore II - Duet Mini + 1LC, Voron V0.1 - Duet Mini
      Voron 2.4 disassembled..... Waiting for the RailCore Mini....

      dc42undefined 1 Reply Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators @PaulHew
        last edited by dc42

        Something like (edited):

        if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
          G28
          while iterations = 0 || move.calibration.initial.deviation > 0.03
            G32
        

        Replace the 0.03 figure by whatever works for you.

        Duet WiFi hardware designer and firmware engineer
        Please do not ask me for Duet support via PM or email, use the forum
        http://www.escher3d.com, https://miscsolutions.wordpress.com

        1 Reply Last reply Reply Quote 0
        • PaulHewundefined
          PaulHew
          last edited by

          @dc42 said in Conditonal script for homing and autolevel - help!:

          if !move.axes[0].isHomed || !move.axes[1].isHomed || !move.axes[2].isHomed

          Thank you @dc42
          I created a new macro file, homing.g, copied text in and tried to run it and I get this error message.

          M98 P"0:/macros/Scripts/Homing.g"
          Error: in file macro line 1 column 5: M98: unknown value
          

          there is no M98 in the command.

          I do not understand!

          Regards,
          Paul

          RailCore II - Duet Mini + 1LC, Voron V0.1 - Duet Mini
          Voron 2.4 disassembled..... Waiting for the RailCore Mini....

          1 Reply Last reply Reply Quote 0
          • chrishammundefined
            chrishamm administrators
            last edited by chrishamm

            @PaulHew There is a typo in dc42's code, actually it's homed instead of isHomed.

            PS: Please upgrade to the latest RC when you can.

            Duet software engineer

            PaulHewundefined 1 Reply Last reply Reply Quote 0
            • PaulHewundefined
              PaulHew @chrishamm
              last edited by

              @chrishamm Thanks, appreciated.
              you already know this, but I have learnt that the text needs to be lowercase for homed.
              Just incase someone finds this post and needs some help.

              Works well, just need to drop my probing temps into the macro.
              Also saves wear and tear on the printer!

              Sorry, one other thing, what happens if it cannot for some reason hit 0.03.
              I am calling the macro from my start gcode in my slicer. I presume it will just carry on printing even though the deviation is off.

              Regards,
              Paul

              RailCore II - Duet Mini + 1LC, Voron V0.1 - Duet Mini
              Voron 2.4 disassembled..... Waiting for the RailCore Mini....

              dc42undefined 1 Reply Last reply Reply Quote 0
              • dc42undefined
                dc42 administrators @PaulHew
                last edited by

                @PaulHew said in Conditonal script for homing and autolevel - help!:

                Sorry, one other thing, what happens if it cannot for some reason hit 0.03.

                It will carry on running G32 forever. You could set a limit on the number of iterations, or have it abort if it reaches a specific number of iterations.

                Duet WiFi hardware designer and firmware engineer
                Please do not ask me for Duet support via PM or email, use the forum
                http://www.escher3d.com, https://miscsolutions.wordpress.com

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

                  @PaulHew After using a script like this for a while, I've found it's best to always home z before and after G32. I've actually added M98 P"0:/sys/homez.g" to the top and G28 Z to the bottom of bed.g. The reason is after the printer warms or cools the z height changes a little causing an inconsistent first layer.

                  Here's my bed.g for a coreXY

                  if !move.axes[0].homed || !move.axes[1].homed	; If the printer hasn't been homed, home it
                  	M98 P"0:/sys/homeyx.g"	; home y and x
                  ;
                  M98 P"0:/sys/homez.g"			; home z
                  ;
                  M561							; clear any bed transform
                  M558 P9 H5 F120 T24000			; increase dive height
                  M98 P"bed_threeScrews.g"		; perform bed tramming
                  echo "Bed Traming 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"
                    M98 P"0:/macros/Utilities/Config/bltouch_config"     ; Apply default BLTouch config
                    M98 P"bed_threeScrews.g"		; perform bed tramming
                    echo "Bed Traming Cycle: " ^ iterations + 2 ^ " - Difference was " ^ move.calibration.initial.deviation ^ "mm"
                    continue
                  ;
                  M98 P"0:/macros/Utilities/Config/bltouch_config"     ; Apply default BLTouch config
                  G28 Z							; home z
                  

                  homeyz.g

                  ; homeyx.g
                  ; called to home x and y axes
                  ;
                  ; 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"
                  ;
                  M106 P2 S1				; turn on virtual fan 2 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
                  ;
                  M106 P2 S0	 			; turn off virtual fan 2 to indicate homeall is done
                  

                  bed_threeScrews.g

                  G30 P0 X10 Y18 Z-99999			; probe near a front left leadscrew
                  G30 P1 X10 Y300 Z-99999			; probe near a back left leadscrew
                  G30 P2 X320 Y166 Z-99999 S3		; probe near a right leadscrew and level
                  
                  PaulHewundefined 1 Reply Last reply Reply Quote 1
                  • PaulHewundefined
                    PaulHew @mwolter
                    last edited by

                    @mwolter said in Conditonal script for homing and autolevel - help!:

                    bed_threeScrews.g

                    Apologies for the delay in saying thanks. Really appreciate you sending me this info.

                    Just need to work out what I need to modify to implement it into my config.
                    I noticed this, just wondering what is in this file, I am presuming it is not in your config.g possibly.

                    M98 P"0:/macros/Utilities/Config/bltouch_config"     ; Apply default BLTouch config
                    

                    Otherwise, really appreciate the help, conditionals I write in another language are nothing like this!

                    Regards,
                    Paul.

                    RailCore II - Duet Mini + 1LC, Voron V0.1 - Duet Mini
                    Voron 2.4 disassembled..... Waiting for the RailCore Mini....

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

                      @PaulHew said in Conditonal script for homing and autolevel - help!:

                      I noticed this, just wondering what is in this file, I am presuming it is not in your config.g possibly.

                      Haha, sharp eye!
                      I did my best to use modular configs and macros to prevent changes needing to be done in multiple locations. What you are seeing is a macro to set the BLTouch parameters back to default. Since you mentioned it, I'll try to be as complete as possible with the macros and configs.

                      All it does is reset the probe height parameter back to 2mm from 5mm set in line 7. It's increased to 5mm to allow for probing of a bed that is extremely out of tram.

                      bltouch_config

                      M558 P9 C"^io7.in" H2 F120 T24000 	; set Z probe type to bltouch and the dive height + speeds
                      ;
                      M98 P"0:/macros/Utilities/Config/bltouch_offset_config"
                      

                      For completeness here is bltouch_offset_config also

                      ;
                      ; G31 - +Z Nozzle closer to bed, -Z Nozzle further from bed
                      ;
                      G31 X0 Y-28.58 Z2.90 P500		; 200411 powder coated pei
                      

                      There another thing that was not explained. At the top of homeyx.g are the following commands that turn on and off a virtual fan to indicate a multi axis home is in progress. This is only necessary until RRF provides actual variables that can be shared among macros. This should come in RRF 3.02. Until then I'm using a virtual fan.

                      M106 P2 S1				; turn on virtual fan 2 to indicate homeall is in progress
                      M106 P2 S0	 			; turn off virtual fan 2 to indicate homeall is done
                      

                      This is the code in config.g that configures the virtual fan

                      ; Virtual Fans Used as Variables
                      ;
                      M950 F2 C"out6"
                      M106 P2 S0 C"vFan Homeall"
                      

                      Here is the homex.g that uses the firtual fan. I did it this way so the homex.g and homey.g files can be used in a homeall script and the bed doesn't go up and down 5mm when homing each axes.

                      ; homex.g
                      ; called to home the X axis
                      ;
                      ;
                      if fans[2].actualValue = 0	; not homeall?	
                        G91              ; relative positioning
                        G1 Z5 F6000 H2   ; lift Z relative to current position
                      ;
                      G1 H1 X357 F6000 ; move quickly to X axis endstop and stop there (first pass)
                      G1 X-5 F3600     ; go back a few mm
                      G1 H1 X357 F360  ; move slowly to X axis endstop once more (second pass)
                      ;
                      if fans[2].actualValue = 0	; not homeall?
                        G1 Z-5 F6000 H2  ; lower Z again
                        G90              ; absolute positioning
                      
                      ; homey.g
                      ; called to home the Y axis (G28 Y)
                      ;
                      ;
                      if fans[2].actualValue = 0	; not homeall?	
                        G91              ; relative positioning
                        G1 Z5 F6000 H2   ; lift Z relative to current position
                      ;
                      G1 H1 Y350 F6000 		; move quickly to Y axis endstop and stop there (first pass)
                      G1 Y-5 F3600     		; go back a few mm
                      G1 H1 Y350 F360  		; move slowly to Y axis endstop once more (second pass)
                      ;
                      if fans[2].actualValue = 0	; not homeall?
                        G1 Z-5 F6000 H2  ; lower Z again
                        G90              ; absolute positioning
                      
                      1 Reply Last reply Reply Quote 0
                      • PaulHewundefined
                        PaulHew
                        last edited by

                        Morning. So I was kindly given the above scripts to use on my RailCore II, thank you @mwolter
                        Modified only the bits I understand, like bedscrews file as I use a 4 point probe.

                        I am getting this error in my console and I do not understand what is wrong...

                        02/05/2020, 09:19:00 	Leadscrew adjustments made: -0.000 0.001 -0.000, points used 4, (mean, deviation) before (-0.000, 0.003) after (-0.000, 0.003)
                        Error: in file macro line 38 column 42: meta command: 'iterations' used when not inside a loop
                        
                        02/05/2020, 09:18:19 	g32
                        Leadscrew adjustments made: -0.048 -0.048 -0.050, points used 4, (mean, deviation) before (-0.049, 0.003) after (0.000, 0.003)
                        Bed Traming Cycle: 1 - Difference was 0.003mm
                        

                        this is my Bed.g - It has my original Bed info

                        ;M561                         ; clear any existing bed transform
                        ;G1 Z5						 ; _RRF3_ remove S2 
                        ;G30 P0 X15 Y45 Z-99999
                        ;G30 P1 X15 Y275 Z-99999
                        ;G30 P2 X275 Y150 Z-99999 S3
                        ;;G30 P3 X275 Y45 Z-99999 S3
                        ;G1 X0 Y0 F5000               ; move the head to the corner (optional)
                        
                        ;Satre suggestion
                        ;M561                         ; clear any existing bed transform
                        ;G1 Z5                         ; RRF3 remove S2 
                        ;G30 P0 X15 Y45 Z-99999
                        ;G30 P1 X15 Y275 Z-99999
                        ;G30 P2 X275 Y275 Z-99999 ;S3
                        ;G30 P3 X275 Y45 Z-99999 S3
                        ;G1 X0 Y0 F5000               ; move the head to the corner (optional
                        
                        
                        ; New 2/5/2020
                        if !move.axes[0].homed || !move.axes[1].homed	; If the printer hasn't been homed, home it
                        M98 P"0:/sys/homex.g"							; home x
                        M98 P"0:/sys/homey.g"							; home Y
                        M98 P"0:/sys/homez.g"							; home z
                        ;
                        M561											; clear any bed transform
                        ;M558 P9 H5 F120 T24000							; increase dive height
                        M98 P"0:/sys/bed_FourScrews.g"					; perform bed tramming
                        ;
                        echo "Bed Traming Cycle: 1 - Difference was " ^ move.calibration.initial.deviation ^ "mm"
                        ;
                        while move.calibration.initial.deviation >= 0.02	; perform additional tramming if previous deviation was over 0.02mm
                          if iterations = 5
                          abort "Too many auto tramming attempts"
                        ;
                        ;M98 P"0:/macros/Utilities/Config/bltouch_config"     	; Apply default BLTouch config
                        M98 P"0:/sys/bed_FourScrews.g"				; perform bed tramming
                        
                          echo "Bed Traming Cycle: " ^ iterations + 2 ^ " - Difference was " ^ move.calibration.initial.deviation ^ "mm"
                        
                          continue
                        
                        ;
                        
                        ;M98 P"0:/macros/Utilities/Config/bltouch_config"     	; Apply default BLTouch config
                        G28 Z							; home z
                        
                        
                        

                        I understand it is referring to this line

                        echo "Bed Traming Cycle: " ^ iterations + 2 ^ " - Difference was " ^ move.calibration.initial.deviation ^ "mm"
                        

                        but am not knowledgeable enough to understand and fix it.

                        As always your assistance is appreciated.

                        Regards,

                        Paul.

                        RailCore II - Duet Mini + 1LC, Voron V0.1 - Duet Mini
                        Voron 2.4 disassembled..... Waiting for the RailCore Mini....

                        1 Reply Last reply Reply Quote 0
                        • dc42undefined
                          dc42 administrators
                          last edited by

                          @PaulHew, the problem is that your M98 command at line 36 isn't indented with respect to the while-command at line 31, therefore the loop body ends just after the abort-command at line 33.

                          Duet WiFi hardware designer and firmware engineer
                          Please do not ask me for Duet support via PM or email, use the forum
                          http://www.escher3d.com, https://miscsolutions.wordpress.com

                          1 Reply Last reply Reply Quote 0
                          • PaulHewundefined
                            PaulHew
                            last edited by

                            @dc42 and @mwolter Thank you both for your help.
                            As I mentioned conditionals are not my forte.

                            I eventually got it working and am pleased with what it does.
                            I include it for anyone else, even the original above by @mwolter would work but tweaked what I knew I could tweak, namely I used 4 screw locations instead of 3.

                            This is for a RailCore II CoreXY with 3 Z motors but could probably be applied to anything else.

                            New bed.g

                            ; New 2/5/2020
                            if !move.axes[0].homed || !move.axes[1].homed	; If the printer hasn't been homed, home it
                            M98 P"0:/sys/homex.g"							; home x
                            M98 P"0:/sys/homey.g"							; home Y
                            M98 P"0:/sys/homez.g"							; home z
                            ;
                            M561											; clear any bed transform
                            ;M558 P9 H5 F120 T24000							; increase dive height
                            M98 P"0:/sys/bed_FourScrews.g"					; perform bed tramming
                            ;
                            echo "Bed Traming Cycle: 1 - Difference was " ^ move.calibration.initial.deviation ^ "mm"
                            ;
                            while move.calibration.initial.deviation >= 0.02	; perform additional tramming if previous deviation was over 0.02mm
                            	if iterations = 5
                            		abort "Too many auto tramming attempts"
                            	M98 P"0:/sys/bed_FourScrews.g"				; perform bed tramming
                            	echo "Bed Traming Cycle: " ^ iterations + 2 ^ " - Difference was " ^ move.calibration.initial.deviation ^ "mm"
                            		continue
                            
                            ;
                            
                            ;M98 P"0:/macros/Utilities/Config/bltouch_config"     	; Apply default BLTouch config
                            G28 Z							; home z
                            
                            

                            bed_Fourscrews.g

                            G30 P0 X15 Y45 Z-99999
                            G30 P1 X15 Y275 Z-99999
                            G30 P2 X275 Y275 Z-99999 
                            G30 P3 X275 Y45 Z-99999 S3
                            

                            If you make it better, please let me know so I can implement it also!

                            Regards,
                            Paul

                            RailCore II - Duet Mini + 1LC, Voron V0.1 - Duet Mini
                            Voron 2.4 disassembled..... Waiting for the RailCore Mini....

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