I wrote a Macro for surfacing stock and figured I should share:
; Constants
var Debug = false;
var ProbeThickness = 15.5;
var CoordSystem = 20;
var StepOver = 10;
var DepthOfCut = 0.2;
var FeedRate = 8000;
var ZClearanceHeight = 25;
; Variables
var StartX = 0; ; The X starting position
var StartY = 0; ; The Y starting position
var EndX = 0; ; The X ending position
var EndY = 0; ; The Y ending position
var YDir = 0; ; The direction to go in Y
var YDist = 0; ; The distance to go in Y
var YPos = 0; ; The position in Y to move to
var YDistLeft = 0; ; How much we have left to move in Y
var ZDepth = 0; ; How far down we should be in Z
var XSorE = "End" ; Whether X should move towards the start or the end position
; If the printer hasn't been homed, home it
if !move.axes[0].homed || !move.axes[1].homed || !move.axes[2].homed
G28
; Adjust probe for low speed probing
M558 K0 P8 C"!io3.in" H20 F120 T300 ; Z probe number - Z probe switch type - probe recovery 1s probe speed and travel speed
G31 K0 P500 X0 Y0 Z0 ; Set trigger value - set offset and trigger height - Z probe number
M291 P"Insert your surfacing bit into your spindle and position it above the probe plate" R"Probing" S3 X1 Y1 Z1
; Set bit above center of probe
G91 ; relative positioning
; Probe Z component
G38.2 Z{move.axes[2].userPosition - (var.ProbeThickness + 2.25)} ; seek until the probe circuit is closed Z-axis 25 mm
G0 Z{var.ZClearanceHeight} ; rapid move Z axis 5 mm
G10 P1 L{var.CoordSystem} Z{var.ProbeThickness + var.ZClearanceHeight} ; store relative probe offset for coordinates system 1
G90 ; Absolute positioning
M291 P"Move to the starting X Y position for surfacing" R"Start Position" S3 X1 Y1 Z0
set var.StartX = move.axes[0].userPosition;
set var.StartY = move.axes[1].userPosition;
if var.Debug
M118 P0 S{"StartX = " ^ var.StartX} L2
M118 P0 S{"StartY = " ^ var.StartY} L2
M291 P"Move to the ending X Y position for surfacing" R"End Position" S3 X1 Y1 Z0
set var.EndX = move.axes[0].userPosition;
set var.EndY = move.axes[1].userPosition;
if var.Debug
M118 P0 S{"EndX = " ^ var.EndX} L2
M118 P0 S{"EndY = " ^ var.EndY} L2
M291 P"Are you ready to begin surfacing?" S3 X0 Y0 Z0
; Figure out which direction in Y we are going
if var.EndY < var.StartY
set var.YDir = -1;
elif var.EndY > var.StartY
set var.YDir = 1;
else
set var.YDir = 0;
if var.Debug
M118 P0 S{"YDir = " ^ var.YDir} L2
set var.YDist = {abs(var.StartY - var.EndY)};
if var.Debug
M118 P0 S{"YDist = " ^ var.YDist} L2
; Begin surfacing loop
while true
if var.Debug
M118 P0 S"Begin Layer Loop" L2;
set var.ZDepth = {var.ZDepth - var.DepthOfCut};
set var.YDistLeft = {var.YDist};
; go to the start X and Y position then down to Z Depth
if var.Debug
M118 P0 S{"Move to start X" ^ var.StartX ^ ",Y" ^ var.StartY} L2
G0 X{var.StartX} Y{var.StartY}
if var.Debug
M118 P0 S{"Move to start Z" ^ var.ZDepth} L2
G1 Z{var.ZDepth}
; we should be at the Start X position so move to the End X position
if var.Debug
M118 P0 S{"Move to X" ^ var.EndX} L2
G1 X{var.EndX} F{var.FeedRate}
set var.XSorE = "Start"
while var.YDistLeft > var.StepOver
if var.Debug
M118 P0 S"Begin Y Loop" L2
; move in Y by StepOver
set var.YPos = {move.axes[1].userPosition + (var.StepOver * var.YDir)}
if var.Debug
M118 P0 S{"Move to Y" ^ var.YPos} L2
G1 Y{var.YPos} F{var.FeedRate}
set var.YDistLeft = {var.YDistLeft - var.StepOver}
if var.XSorE == "Start"
; move X to the start position
if var.Debug
M118 P0 S{"Move to X" ^ var.StartX} L2
G1 X{var.StartX} F{var.FeedRate}
set var.XSorE = "End"
else
; move X to the end position
if var.Debug
M118 P0 S{"Move to X" ^ var.EndX} L2
G1 X{var.EndX} F{var.FeedRate}
set var.XSorE = "Start"
; move in Y the rest of the distance left
set var.YPos = {move.axes[1].userPosition + (var.YDistLeft * var.YDir)}
if var.Debug
M118 P0 S{"Move to Y" ^ var.YPos} L2
G1 Y{var.YPos} F{var.FeedRate}
; one last move in X
if var.XSorE == "Start"
; move X to the start position
if var.Debug
M118 P0 S{"Move to X" ^ var.StartX} L2
G1 X{var.StartX} F{var.FeedRate}
set var.XSorE = "End"
else
; move X to the end position
if var.Debug
M118 P0 S{"Move to X" ^ var.EndX} L2
G1 X{var.EndX} F{var.FeedRate}
set var.XSorE = "Start"
G0 Z{var.ZClearanceHeight} ; get out of the way
M400 ; wait for the movement buffer to catch up
M291 P"Surface another layer?" S3 X0 Y0 Z0 ; then prompt the user if they want to do another layer
It is working really well so far, but I cannot promise it is perfect. It is designed to be used with a Z Probe like this:
https://openbuildspartstore.com/xyz-touch-probe-plus/
Once the top surface of the piece is determined it will then have you jog to the X / Y start position and press Ok. Next it will have you jog to the X / Y end position and press Ok. Then it will ask you if you are ready. Press Ok and it will begin surfacing your part. Once it has made a pass it will prompt you if you want to surface another layer. If you say Ok it will move back to the X / Y start position and go down in Z by the DepthOfCut variable and continue surfacing. It will keep going till you cancel at the end of a pass.
There are several constants you can set at the top:
Debug - Determines if it should spit out the M118 debug output. (Will probably switch this over to echos to a file once 3.4 is finally released)
ProbeThickness - How thick your XYZ probe is.
CoordSystem - The coordinate system to save the top of your piece in as Z0
StepOver - The step over in MM for each pass of your cutter
DepthOfCut - The depth of cut that will be taken off with each pass
FeedRate - The feed rate used when cutting
ZClearanceHeight - How high to retract in Z when moving to the Start Point
Would love your feedback.
EDIT: So I forgot to mention that the Start and End points define two opposite corners of the rectangle to be surfaced.