Store Last Z Height from prior print
-
I was wondering if the microcontrollers on the Duet 2 or Duet 3 have enough memory so that the max Z height from the last print is stored in memory before the print is finished. This way, when a new print is started and the printer has to home on Z, it can recall that saved height and start from a potentially known position (not as an accurate height, but a starting point of reference to assist with homing). This can avoid overtravel since most homing moves require the Z axis to move away from the print head (usually 5 or 10 mm) and if the prior print used the printer's full Z capacity, then there would be no more Z travel left and it puts unnecessary strain on the motors.
If this value can be stored, is there a way it can be stored using ending G-Code?
-
@theindiandude
You can use the echo command to write the last known Z position to a macro and then use that same macro to create a global variable on restart.First create a macro to save the position to a file for later re-use
;0:/macros/SaveLastZ.g - called at the end of print to record last used Z position echo >"0:/macros/lastZ.g" "if !exists(global.lastZ)" echo >>"0:/macros/lastZ.g" " global lastZ=" ^ move.axes[2].userPosition echo >>"0:/macros/lastZ.g" "else" echo >>"0:/macros/lastZ.g" " set global.lastZ=" ^ move.axes[2].userPosition
In your end code you can put
M98 P"0:/macros/SaveLastZ.g"
then in your homing file use
EDIT: Changed so that it takes into account whether the machine is already homed and knows where it isif move.axes[2].userPosition = 0 ; we don't know where we are, so call the macro M98 P"0:/macros/lastZ.g" ; call the macro to create the global variable with the last known position if result != 0 ; the macro call was successful echo "macro failed" else ; we do know where we are, so rreset the global or create it if need be if exists(global.LastZ) set global.LastZ = move.axes[2].userPosition else global LastZ = move.axes[2].userPosition if global.lastZ < move.axes[2].max - 10 G91 ; set relative positioning G1 H2 Z10 F120 G90 ; set absolute positioning echo "Z lifted" ; rest of homing file is not indented
Anything in the indented section will only happen if the last known position is greater than 10mm from the max Z position.
Note that the macro won't exist until after your first print unless you create it manually.
If it doesn't exist then it will skip the raising section. -
@owend This is super cool! I didn't know RRF supported conditional GCode. Now I need to learn how to program in this language.
Thanks a bunch!
-
@owend quick question. I'm assuming move.axes(2) refers to motor driver 2 which is usually mapped to the Z axis. What if I have multiple independent Z (my printer has drives 5, 6, and 7 mapped to z on a Duex 5)? Can I use any one of those drive numbers?
-
-
@theindiandude
No, move.axes[2] refers to the axis, not the drivers.
I have two Z axis drives.
If you sendecho move.axes[2].letter
from the console it will confirm.