So, here's how I'm iterating through auto-tramming to level a RailCore. This can be cleaned up once we have variables, but even still, it's very cool (and confirmed working)!
First, to simplify, I moved my "G32" commands for probing the bed into a macro called "bedlevel". So I can use that like a function. (Feature request: can we send arguments to macros? Then they really would be functions!)
;bedlevel
;Call from auto-level Routine in bed.g
;Run initial 4 point leveling routine
G30 P0 X15 Y45 Z-99999
G30 P1 X15 Y275 Z-99999
;G30 P2 X275 Y150 Z-99999 S3
G30 P2 X275 Y275 Z-99999
G30 P3 X275 Y45 Z-99999 S3
Now that those commands are there, the following can go in your bed.g
The goal is to level across the bed to a deviation of < 0.01, and then do another round, and have that round within 0.005 of the previous. If not, it repeats.
M561 ; clear any existing bed transform
; If the printer hasn't been homed, home it
if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
G28
;Move up 7.5mm in Z to clear the bed
G1 Z7.5
;Run an initial auto-tramming
M98 P"/macros/bedlevel"
while true
if iterations = 5
abort "Too many auto calibration attempts"
if move.initialDeviation.deviation < 0.01
if move.calibrationDeviation.deviation < move.initialDeviation.deviation + 0.005
if move.calibrationDeviation.deviation > move.initialDeviation.deviation - 0.005
break
echo "Repeating calibration because initial deviation (" ^ move.initialDeviation.deviation ^ "mm) must be < 0.01"
echo "and (" ^ move.calibrationDeviation.deviation ^ "mm) must be within 0.005 of initialDeviation"
M98 P"/macros/bedlevel"
echo "Auto calibration successful, deviation", move.calibrationDeviation.deviation ^ "mm"
echo "Auto calibration successful, initialDeviation", move.initialDeviation.deviation ^ "mm"
G28 Z
G1 X0 Y0 F24000