Conditional homing and z-height fine adjustment



  • At the moment i'm a bit at a los. I'm trying to create a macro which checks if the machine has been homed, if not homes the machine, if yes, only homes the X and Y axis.
    I'm using 2 Z-max endswitches in combination with a BLTouch Z-probe. The idea behind it is to lower the print to the Z-max position so i can easily get the part off the buildplate and to prevent the bed crashing in the bottom when homing the first time after powerup.
    The intention of the macro is basicly omit an extra Z move to max and back up again.

    Setup:

    • Hypercube evolution style CoreXY
    • DuetWifi 1.03
    • firmware 3.1.1
    • BLTouch Z probe
    • 2x Z-max endswitches

    Refences used:

    Marco file:

    ; Source: https://forum.duet3d.com/topic/4202/homing-to-z-max-when-also-using-a-z-probe/19
    ; Start g-code: G28, M98 P"0:/macros/Leveling/SetZ" ; run z fine tuning
    
    ; If the printer hasn't been homed, home it
    
    if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed  	; Check if axis are already homed
      ;If axis are not homed, home axis
      M291 P"Axis not homed yet, homing axis" R"Homing status" S1		; Report status
      G28 															; Home all axis					
      M400 															; Wait till homeing has been completed		
    		
    else
      ;If axis are already homed, home only the X and Y axis
      M291 P"Axis already homed, homing x and y axis" R"Homing status" S1	; Report status	
      G28 XY															; Home only the X and Y 
      G1 Z15 H1 F8000											        ; move to be centre slowly
      M400 															; Wait till homeing has been completed
    
    ;End homeing check
    M291 P"Axis homed" R"Homing status" S1									; Report status
    
    G1 X130 Y97.5 H2 F1000													; move to be centre slowly.
    G1 Z15 H1 F8000	 	 													; Raise the bed to start probing
    G30 																	; probe for z=0
    G1 Z10 H1 F1000 														; raise nozzle
    G30 S-1 																; check z gap
    G1 Z10 H1 F1000 														; raise nozzle
    
    M400																	; Wait until all moves are completed
    
    

    What works:
    If the axis are not homed, all the axis go to the home position, the head moved to the x and y position as instructed in the code and the bed is probed twice.

    What doesn't work:
    If the "else" statement doest not complete completely. X and Y are homed individually and the bed start to move in the z-min direction. The probe does get deployed, but at the X and Y min position (wich is outside the bed in my case). When triggered manually, the bed does stop moving. Somehow the line telling the head to move to the X130 Y97.5 position is skipped.
    Also the M291 messages do not always work.

    Troubleshooting already performed:

    • Changed the indentation distance of the if/else statement from a tab to a double space, nil results
    • Added M400 to wait to clear the buffer, this had no effect
    • Upgraded from firmware 3.0.1 to 3.1.1, no result

    Somehow there is still a bug in the code and i'm unable to spot it. Any help and input is greatly appriciated....



  • Try using
    M98 P"0:/sys/homex.g"
    &
    M98 P"0:/sys/homey.g"

    instead of G28 XY

    Also might help if you post the contents of those two files.



  • Hi Owen,
    Thanks for the reply. I'll try it tomorrow.
    In the mean time, here are the files you requested:

    homex.g:

    ; homex.g
    ; called to home the X axis
    ;
    ; generated by RepRapFirmware Configuration Tool v2.1.8 on Mon May 11 2020 11:54:52 GMT+0200 (Midden-Europese zomertijd)
    G91               ; relative positioning
    G1 H1 Z5 F6000    ; lift Z relative to current position
    G1 H1 X-227 F1800 ; move quickly to X axis endstop and stop there (first pass)
    G1 X5 F6000       ; go back a few mm
    G1 H1 X-227 F360  ; move slowly to X axis endstop once more (second pass)
    G1 H2 Z-5 F6000   ; lower Z again
    G90               ; absolute positioning
    
    

    homey.g

    ; homey.g
    ; called to home the Y axis
    ;
    ; generated by RepRapFirmware Configuration Tool v2.1.8 on Mon May 11 2020 11:54:52 GMT+0200 (Midden-Europese zomertijd)
    G91               ; relative positioning
    G1 H1 Z5 F6000    ; lift Z relative to current position
    G1 H1 Y-285 F1800 ; move quickly to Y axis endstop and stop there (first pass)
    G1 Y5 F6000       ; go back a few mm
    G1 H1 Y-285 F360  ; move slowly to Y axis endstop once more (second pass)
    G1 H2 Z-5 F6000   ; lower Z again
    G90               ; absolute positioning
    

    And just to make everything complete, here's the homeall.g aswell:

    ; homeall.g
    ; called to home all axes
    ;
    ; generated by RepRapFirmware Configuration Tool v2.1.8 on Mon May 11 2020 11:54:52 GMT+0200 (Midden-Europese zomertijd)
    G91                     ; relative positioning
    G1 H1 Z5 F6000          ; lift Z relative to current position
    G1 H1 X-227 Y-285 F1800 ; move quickly to X or Y endstop and stop there (first pass)
    G1 H1 X-227             ; home X axis
    G1 H1 Y-285             ; home Y axis
    G1 X5 Y5 F6000          ; go back a few mm
    G1 H1 X-227 F360        ; move slowly to X axis endstop once more (second pass)
    G1 H1 Y-285             ; then move slowly to Y axis endstop
    G90                     ; absolute positioning
    G1 X55 Y45 F6000        ; go to first bed probe point and home Z
    G1 H1 Z300 F6000	; Home the Z axis fast
    ;G1 H1 Z-5 F6000	; Raise the bed 5mm
    ;G1 H1 Z300 F3000	; Slowly rehome the axis
    
    ;G30                     ; home Z by probing the bed
    
    ; Uncomment the following lines to lift Z after probing
    ;G91                    ; relative positioning
    ;G1 Z5 F100             ; lift Z relative to current position
    ;G90                    ; absolute positioning
    


  • @GuidoP said in Conditional homing and z-height fine adjustment:

    G30 S-1 ; probe bed in current position

    You are probing the bed after your conditional G Code.



  • @OwenD Yes, that the idea... 😉

    I home to Z-max, and before starting the print i want to make sure the z-gap is oke.

    I used the explanation used in this forum post to create the initial macro:

    https://forum.duet3d.com/topic/4202/homing-to-z-max-when-also-using-a-z-probe/19



  • @OwenD said in Conditional homing and z-height fine adjustment:

    Try using
    M98 P"0:/sys/homex.g"
    &
    M98 P"0:/sys/homey.g"

    instead of G28 XY

    Also might help if you post the contents of those two files.

    Tried ad suggested with following macro:

    ; Source: https://forum.duet3d.com/topic/4202/homing-to-z-max-when-also-using-a-z-probe/19
    ; Start g-code: G28, M98 P"0:/macros/Leveling/SetZ" ; run z fine tuning
    
    ; If the printer hasn't been homed, home it
    
    M291 P"checking homing status" R"Homing status" S1			; Report status
    
    if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed  	; Check if axis are already homed
      ;If axis are not homed, home axis
      M291 P"Axis not homed yet, homing axis" R"Homing status" S1	; Report status
      ;G28 															; Home all axis					
      M98 P"0:/sys/homeall.g"
      M400 															; Wait till homeing has been completed		
    		
    else
      ;If axis are already homed, home only the X and Y axis
      M291 P"Axis already homed, homing x and y axis" R"Homing status" S1	; Report status	
      ;G28 XY														; Home only the X and Y 
      M98 P"0:/sys/homex.g"											; Run the Home X macro
      M98 P"0:/sys/homey.g"											; Run the Home Y macro
      ;G1 Z15 H1 F8000												; move to be centre slowly
      G1 X100 Y100 H1 F1000											; move to be centre slowly.
      M400 															; Wait till homeing has been completed
    
    ;End homeing check
    M291 P"Axis homed" R"Homing status" S1							; Report status
    
    G1 X100 Y100 H1 F1000											; move to be centre slowly.
    G1 Z15 H1 F8000	 	 											; Raise the bed to start probing
    G30 															; probe for z=0
    G1 Z10 H1 F1000 												; raise nozzle
    G30 S-1 														; check z gap
    G1 Z10 H1 F1000 												; raise nozzle
    
    M400															; Wait until all moves are completed
    

    No luck.

    If the axis are not homed, homing is initiated and works as requested. Only the messages don't show on either the paneldue or DWC.
    If the axis are homed, the message shows that the axis are homed, X and Y are homes seperately, the head keeps in the X0 Y0 position, the bed moves to the Z-min position and the probe deploys. When the probe is triggered manually the expected sequence is completed.

    Basically the head is stuck in the X0 Y0 position. It does not mater if the G1 is in the "else" block or outside.



  • Hi,

    I was wondering why you home to Z max.

    Thanks.

    Frederick



  • @fcwilt said in Conditional homing and z-height fine adjustment:

    Hi,

    I was wondering why you home to Z max.

    Thanks.

    Frederick

    I have had several considerations for implementing the z-max switches:

    • When the axis home they drop down a couple of mm. If the bed is max down it would crash into the hard mechanical endstops, offsetting the mesh and creating a terrible noise. Creating endstops and adjusting the homeing files eliminated this problem
    • After the print i want the bed to drop down so i have easy access to the print and don't have to move something manual. Now i can simply home the Z-axis, and don't need to worry abbout the previous issue
    • Additional benefit is having 2 z-max switches is that i can easily have a fixed reference point without much adjustment and home both z motors individually without much hassle.

    There are a couple of downsides aswell:

    • Starting a print can take considrable longer as the bed needs to travel from z-max to z-min.
    • You have to carefully need to measure the Z-max to get your mesh leveling to work niceliy. Also you need something in your start g-code to do some z-level fine adjustments, (Hence above script).

    To reduce the total time before the print starts i want to check the homing status to prevent a unnessecairy homing cycle in case the z-axis is already homed. And i wanted to test out the meta commands to see what would be possible.



  • @GuidoP said in Conditional homing and z-height fine adjustment:

    I have had several considerations for implementing the z-max switches: ...

    Thank you for the reply.

    All of my printers home to Z min and it seems to me all of the reasons you stated for using Z max apply to Z min.

    • The crash scenario is the same for min versus max.

    • Most slicers will execute some user defined code on print completion. One of the things my "printing complete" macro does is move down to a bit - it could just as easily move to Z max.

    • I don't understand the fixed reference issue. You are referencing the frame when using either min or max - correct?

    Thanks for the help in understanding.

    I don't know if this makes any difference but I eliminated multiple Z steppers in favor a single stepper, belt driven setup which naturally keeps both Z axis lead screws in sync.

    Frederick



  • @fcwilt Thanks for sharing your thoughts and considerations.
    An alternative to my current setup would indeed be using a z-min homing scenario and just use the endstops as safetystops so the bed wont crash when is full down when the machine starts. (This is actuatlly my backuo scenario if i don't get the macro running).

    The crash scenarion in a z-min homing situation is higher imho:

    • Machine starts, axis are not homed. The machine has no clue where the different axis are located
    • Homing is initiated. X and Y homing will initiate (in the default g-code) a Z move in the z-max direction. Regardless if z-max or z-min is used
    • If the bed is at or near the z-max position, with z-min endstops the machine has no way of knowing it will run out of bed travel and will crash to the mechanical limits. In a z-max endstop configuration the z-max endstop will trigger, stopping the move gracefully. With to independend z-motors you'll need to re-perform the bed leveling again due to the unknown shift between the two leadscrews. I'm not sure what would happen in your setup with a single stepper for 2 leadscrews. Does the belt slip or does the stepper skip steps?

    I have two optical endstops bolted to the frame between steppermotor and linear rod. As the frame is square and level these switches are in the same position horizontally. I use a single 25mm aluminium angle profile bolted directly to the 2020 profiles of the bed as endstop flag. So basically there are no manual adjustments and everything is referenced to a fixed point resulting in a repeatable fixed horizontal level.
    An alternative to this procedure on the z-min side would be using the z-probe to probe near the leadscrews and let the duet calculate how to level things out. This is a bit more straight forward without extra probing time. (Or use a single steppermotor which drives 2 leadscrews.... 😉 )

    There are a lot of differnt approaches and sollutions to solving a single problem. These are my solutions now, which i might (or might not) change in the future... That's the beauty of learning and progressing... 🙂

    Anyway, i'm getting a bit off-topic... Sorry... 🙂



  • @GuidoP said in Conditional homing and z-height fine adjustment:

    • Homing is initiated. X and Y homing will initiate (in the default g-code) a Z move in the z-max direction. Regardless if z-max or z-min is used

    If it moves in the Z max direction when using Z min end stop then something is wrong. It should not do that.

    Frederick


  • Moderator

    @fcwilt said in Conditional homing and z-height fine adjustment:

    If it moves in the Z max direction when using Z min end stop then something is wrong. It should not do that.

    Maybe he means the small lift before homing x and y for clearance?



  • @Phaedrux said in Conditional homing and z-height fine adjustment:

    Maybe he means the small lift before homing x and y for clearance?

    What small lift? I must do things backwards. I home Z first and then move to Z=5 before I home Y & X.

    Frederick


  • Moderator

    @fcwilt For instance in homeall.

    G1 Z5 F100 S2 ; Lower bed 5mm to ensure it is below the trigger height



  • @Phaedrux said in Conditional homing and z-height fine adjustment:

    @fcwilt For instance in homeall.

    G1 Z5 F100 S2 ; Lower bed 5mm to ensure it is below the trigger height

    What would you do that?

    Consider when homing to Z min:

    G1 Z-999 H1
    G1 Z20
    G1 Z-999 H1

    When the first G1 executes if the endstop is already triggered no movement takes place and the next G1 executes which is safe.

    Am I overlooking something?

    Frederick


  • Moderator

    @fcwilt said in Conditional homing and z-height fine adjustment:

    Am I overlooking something?

    Yes, when using a probe you must position the probe first, so X and Y must be homed first, and by default the configurator includes a short lift of the Z axis to give clearance for the X Y move and to lift the probe above trigger height.

    But I was just speculating on what he might have been meaning.



  • @Phaedrux said in Conditional homing and z-height fine adjustment:

    Yes, when using a probe you must position the probe first, so X and Y must be homed first, and by default the configurator includes a short lift of the Z axis to give clearance for the X Y move and to lift the probe above trigger height.

    Ah... I see.

    I use a Z min endstop switch setup for homing in relation to the frame so I never encountered that issue.

    I only use the Z probe for setting Z=0 and mesh comp probing, things which only occur after the ZYX homing has been done.

    Thanks.

    Frederick



  • @Phaedrux said in Conditional homing and z-height fine adjustment:

    @fcwilt said in Conditional homing and z-height fine adjustment:

    If it moves in the Z max direction when using Z min end stop then something is wrong. It should not do that.

    Maybe he means the small lift before homing x and y for clearance?

    Thats correct 🙂



  • Thanks all for the input, but unfortunately it does not bring me closer to an answer to the original question: Why does the conditional gcode not work as intended? Where is the bug in the code??



  • I finally got the macro working with following code:

    ; Source: https://forum.duet3d.com/topic/4202/homing-to-z-max-when-also-using-a-z-probe/19
    ; Start g-code: G28, M98 P"0:/macros/Leveling/SetZ" ; run z fine tuning
    
    ; If the printer hasn't been homed, home it
    
    ;M291 P"checking homing status" R"Homing status" S1			; Report status
    
    if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed  	; Check if axis are not homed
      ;If axis are not homed, home axis
      echo "Axis are not homed, performing homing"
      M98 P"0:/sys/homeall.g"
    else
      ;If axis are already homed, home only the X and Y axis
      echo "axis are homed, re-homing x and Y"
      M98 P"0:/sys/homex.g"											; Run the Home X macro
      M98 P"0:/sys/homey.g"											; Run the Home Y macro
      ;G1 X100 Y100 H0 F1800											; move to be centre slowly.
      
    ;End homeing check
    M291 P"Axis homed" R"Homing status" S1							; Report status
    ;echo "start fine tuning z-level"
    G1 X100 Y100 H0 F1000											; move to be centre slowly.
    G1 Z15 H1 F8000	 	 											; Raise the bed to start probing
    G30 															; probe for z=0
    G1 Z10 H1 F1000 												; raise nozzle
    G30 S-1 														; check z gap
    G1 Z10 H1 F1000 												; raise nozzle
    
    M400															; Wait until all moves are completed
    

    I changed and tested several different thing, but i think the trick that did it was removing the empty line between the end of the "If" block and the start of the "else" block.


Log in to reply