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

    How to: storing the Z-offset automatically without using M500

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    7
    657
    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.
    • ComedianTF2undefined
      ComedianTF2
      last edited by

      If for whatever reason you want to store the Z-offset outside of the config.g file (in this example in a file named config_probe.g), here is the method I've found out to work quite well.

      This method works for RepRapFirmware 3.4 and up, as we need to use the ability to write to a file using the echo command. It has been tested on 3.4.1

      For more info, see https://docs.duet3d.com/User_manual/Reference/Gcode_meta_commands#echo-command

      The macro also allows you to automatically compensate for using of a known thickness shim, using the var probing_tool setting at the start of the macro.

      Z-offset macro:

      var probing_tool = 0.000
      ; This allows you to compensate for whatever tool you use to measure the nozzle distance.
      ; It is set to 0.000 by default, you can set this to the thickness of the tool or paper you use for the Z-offset calibration
      ; A sheet of paper is on average 0.05 to 0.10mm thick.
      
      M291 S3 R"Heating up nozzle" P"Wait for the nozzle to reach printing temperatures"
      M568 P0 S215		; set tool 0 (primary hotend) temperature to 215c
      T0			; select tool 0 (primary hotend)
      M116 P0 H5		; wait for temperature to reach within 5c of set temperature
      
      M300 S666 P666               ; beep
      M291 S3 R"Setting the Z-offset Height" P"Press OK to continue, or CANCEL to abort"
      G28                          ; home all
      G29 S2                       ; cancel mesh bed compensation
      M290 R0 S0                   ; cancel baby stepping
      G90                          ; absolute movements
      
      G1 Z10
      G1 X100 Y100 F1800
      G4 P0
      
      M300 S1111 P666              ; beep
      M564 H1 S0                   ; ignore axis limits
      M291 S2 R"Test Z Probe Trigger Height - Step 1" P"Place a paper sheet under the nozzle and raise the bed until slight friction can be noticed" Z1 ;
      
      G92 Z0                       ; the nozzle should now be just touching the bed so set the logical Z position to match the physical Z position
      M300 S666 P666               ; beep
      G1 Z8 F300                   ; insure Z position will allow for probing
      G4 P0						 ; wait for the movement to stop
      
      M291 S2 R"Test Z Probe Trigger Height - Step 2" P"Please remove the paper sheet and wait for the bed-probing to begin" ;
      G30 S-1                      ; probe the bed and report the Z probe trigger height
      M564 S1 H1                   ; respect axis limits
      
      ;M291 S2 R"Test Z Probe Trigger Height - Step 3" P"Copy the reported height value on the G-Code console and paste it into the config_probe.g file"
      
      var Z_auto_offset = {sensors.probes[0].lastStopHeight+var.probing_tool} ; math to calculate the BLTouch offset
      echo >"0:/sys/config_probe.g" "G31 Z"^{var.Z_auto_offset}				; write the Z-offset to the config_probe.g file
      
      echo "the Z-offset has been stored in the config_probe.g file. The Z-offset is", var.Z_auto_offset, "mm"
      
      G4 P0						 ; wait for the movement to stop
      G1 Z10 F300                  ; Lift up the nozzle again so it's not pressed against the bed surface
      

      config_probe.g :

      G31 Z1.5 
      

      It's a fairly simple macro, but if there are any questions let me know

      1 Reply Last reply Reply Quote 4
      • Trojan3Dundefined
        Trojan3D
        last edited by

        Hello,
        Any chance i can save the Z-offset directly in the "Config.override" file without deleting all the other settings instead of creating a new one?
        Thanks a lot for your time.

        ComedianTF2undefined 1 Reply Last reply Reply Quote 0
        • ComedianTF2undefined
          ComedianTF2 @Trojan3D
          last edited by

          @Trojan3D If you change it to be >> instead of > on the echo, it adds data to the file instead of overwriting it

          So in your case it would be:
          echo >>"0:/sys/config-override.g" "G31 Z"^{var.Z_auto_offset} ; write the Z-offset to the config-override.g file

          This adds the value to the last line of the config-override.g, however you will see it become quite a mess over time, as the echo >> only adds another line

          So after doing it ten times, you it would have the G31 Z value added ten times in a row, with the bottom one being the value you're trying to have.

          That's why it's generating a separate file called config_probe.g in this example, and then you can load the Z-offset using a M98 P"config_probe.g" in your config.g and homing files

          Trojan3Dundefined bluenavyundefined 2 Replies Last reply Reply Quote 1
          • Trojan3Dundefined
            Trojan3D @ComedianTF2
            last edited by

            @ComedianTF2 That's great, thank you very much for your help!
            New to duet and trying to figure out what's what here in my new Prusa Bear with Duet mini.
            All the best and thank you again.

            1 Reply Last reply Reply Quote 1
            • bluenavyundefined
              bluenavy @ComedianTF2
              last edited by

              @ComedianTF2 Hi, thanks for this macro, it's very handy. I've tried to use it but i think I'm having a problem with calling the config_probe.g file into config.g. I've used:
              G31 K1 P500 X-28.2 Y-18.1 ; set Z probe trigger value offset
              M98 P"0:/sys/config_probe.g" ; z probe trigger height

              When I try to print, there isn't any z-offset. Am i doing this properly?

              Thanks

              ComedianTF2undefined 1 Reply Last reply Reply Quote 0
              • ComedianTF2undefined
                ComedianTF2 @bluenavy
                last edited by ComedianTF2

                @bluenavy I have it similar to you, so check that the config_probe.g is populated properly

                G31 P500 X-22.5 Y38.9	; BLTouch X and Y offset
                M98 P"config_probe.g"	; Load the Z-offset from the config_probe.g file
                

                Then the config_probe.g file is this:

                G31 Z2.688
                

                And homing files also have the Z-offset loaded in there

                ; homeall.g
                ; called to home all axes
                M98 P"config_probe.g"	; Load BLTouch probe settings
                M280 P0 S60 I1		; clear any probe errors
                G29 S2                      	; cancel mesh bed compensation
                G91                    		; relative positioning
                
                M913 X50 			; X axis 50% power
                
                G1 H2 Z5 F200          	; lift Z relative to current position
                G1 H1 X{(move.axes[0].max+5)*-1} Y{move.axes[1].max+5} F3000  	; move quickly to X and Y axis endstops and stop there (first pass)
                G1 H2 X5 Y-5 F600      	; go back a few mm
                G1 H1 X{(move.axes[0].max+5)*-1} Y{move.axes[1].max+5} F600  	; move slowly to X and Y axis endstops once more (second pass)
                
                M913 X100 			; X axis 100% power
                
                G90                    		; absolute positioning
                G1 X{move.axes[0].min+2} Y{move.axes[1].min+2} F6000 		; move to front left
                
                G1 F600				; reduce speed
                G30                    		; home Z by probing the bed
                G29 S1				; load heightmap
                
                
                bluenavyundefined 1 Reply Last reply Reply Quote 0
                • bluenavyundefined
                  bluenavy @ComedianTF2
                  last edited by

                  @ComedianTF2 Thanks!

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