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

    Surfacing Macro

    Scheduled Pinned Locked Moved
    CNC
    11
    28
    2.5k
    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.
    • CthulhuLabsundefined
      CthulhuLabs
      last edited by CthulhuLabs

      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.

      jay_s_ukundefined Sindariusundefined sinned6915undefined 3 Replies Last reply Reply Quote 8
      • jay_s_ukundefined
        jay_s_uk @CthulhuLabs
        last edited by

        @cthulhulabs wow, thats really nice.
        how is the cutter diameter set so each movement in Y isn't too large/too small?

        Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

        CthulhuLabsundefined 1 Reply Last reply Reply Quote 1
        • CthulhuLabsundefined
          CthulhuLabs @jay_s_uk
          last edited by CthulhuLabs

          @jay_s_uk you just adjust the step over. So if you were using a 1/4in end mill you'd set the step over to like 2mm. I'm using a 1" surfacing bit so I set it to 10mm. Seems to leave a nice finish.

          jay_s_ukundefined 1 Reply Last reply Reply Quote 2
          • jay_s_ukundefined
            jay_s_uk @CthulhuLabs
            last edited by

            @cthulhulabs fantastic! I look forward to trying this when I next need it

            Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

            1 Reply Last reply Reply Quote 1
            • Sindariusundefined
              Sindarius @CthulhuLabs
              last edited by

              @cthulhulabs This is really impressive! Thanks for sharing. I plan on trying it out soon myself!

              CthulhuLabsundefined 1 Reply Last reply Reply Quote 1
              • CthulhuLabsundefined
                CthulhuLabs @Sindarius
                last edited by

                @sindarius / @jay_s_uk
                Get a chance to try this out? Trying to see if there are any ways to improve it.

                Sindariusundefined 1 Reply Last reply Reply Quote 0
                • Sindariusundefined
                  Sindarius @CthulhuLabs
                  last edited by Sindarius

                  @cthulhulabs It's been too cold in my garage to want to do any woodworking at the moment 😓

                  I do have the macro copied over to my machine once it warms up enough to be in there.

                  1 Reply Last reply Reply Quote 0
                  • chimaeraghundefined
                    chimaeragh
                    last edited by

                    It would be nice if this macro could be made into a plugin. Then you wouldn't have to edit the macro to change parameters. Something like the CNC touchprobe plugin by @raymondstone 👍

                    Duet 2 Wifi, Ooznest Workbee CNC 1510

                    chimaeraghundefined 1 Reply Last reply Reply Quote 1
                    • psychotik2k3undefined
                      psychotik2k3
                      last edited by

                      damn that would be another reason for me to update my old duet2w from RRF2.1 to 3.3 🤔
                      no build another cnc first

                      1 Reply Last reply Reply Quote 0
                      • chimaeraghundefined
                        chimaeragh @chimaeragh
                        last edited by chimaeragh

                        I tested this macro today. Works nicely, had to edit some parameters for my Ooznest touchprobe input. Thanks a lot

                        ; Adjust probe for low speed probing
                        M558 K0 P8 C"!e0stop" H20 F120 T300					; Z probe number - Z probe switch type - probe recovery 1s probe speed and travel speed
                        

                        Duet 2 Wifi, Ooznest Workbee CNC 1510

                        1 Reply Last reply Reply Quote 1
                        • sinned6915undefined
                          sinned6915 @CthulhuLabs
                          last edited by

                          @cthulhulabs i like this macro! I am trying ot use it by I am encountering a couple of hiccups. I know this is an older thread, but I am hoping you might see this reply.

                          1. Are you using a PanelDue in conjunction with your machine?

                          2. Where/how are you controlling your spindle?

                          3. I am getting funny outputs with the move command prompts on PanelDue. I get the first one for probing Z. but not for any of the other ones. M291 Syntax looks correct. I am trying to get a PC near the machine to see what the console looks like.

                          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;
                          
                          1. How or where are you turning your spindle on? As mine is controlled through RRF, I need to insert the tokens to turn off/on. I am thjnking before and after the while loop?
                          T1 
                          
                          G90
                          M03 S5000
                          G04 S1
                          G0 X0.0000 Y0.0000 Z3.0000
                          
                          ; Begin surfacing loop
                          while true
                          
                          ...
                          ...
                          	M291 P"Surface another layer?" S3 X0 Y0 Z0	; then prompt the user if they want to do another layer
                          
                          M03 S3500          ; ramp spindle speed down
                          G04 S1
                          M03 S1500
                          G04 S1
                          M05
                          G04 S1
                          G90
                          G0 X0.0000 Y0.0000 Z3.0000
                          chimaeraghundefined CthulhuLabsundefined 2 Replies Last reply Reply Quote 0
                          • chimaeraghundefined
                            chimaeragh @sinned6915
                            last edited by chimaeragh

                            @sinned6915 I have modified the macro for an Ooznest Workbee with their latest Firmware (RRF3.3). M3 starts the router and M5 stops it.

                            ; Constants
                            var Debug = false;
                            var ProbeThickness = 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"!e0stop" 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
                               T1
                               M3 S17500 ;M42 P1 S1
                               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
                               M5 ;M42 P1 S0
                               M291 P"Surface another layer?" S3 X0 Y0 Z0	; then prompt the user if they want to do another layer
                            
                            

                            Duet 2 Wifi, Ooznest Workbee CNC 1510

                            sinned6915undefined 1 Reply Last reply Reply Quote 0
                            • sinned6915undefined
                              sinned6915 @chimaeragh
                              last edited by

                              @chimaeragh thank you. i am downloading now and will try it again.

                              chimaeraghundefined 1 Reply Last reply Reply Quote 0
                              • chimaeraghundefined
                                chimaeragh @sinned6915
                                last edited by

                                @sinned6915 Line 89 selects the tool (T1). If your spindle is set to tool 0 (T0) change it accordingly. Line 90 sends the M3 command to start the spindle.

                                Duet 2 Wifi, Ooznest Workbee CNC 1510

                                1 Reply Last reply Reply Quote 0
                                • CthulhuLabsundefined
                                  CthulhuLabs @sinned6915
                                  last edited by

                                  @sinned6915 sorry for the late reply. Have not been on this forum for a while. No I am not using a PanelDue. I am using a Pi with an HDMI touch screen monitor. As for spindle I am using a Brushless Dewalt Trim Router with the ESC replaced with an ODrive. It currently requires running commands from odrivetool on the Pi.

                                  @chimaeragh what all did you change in your version? I just upgraded to an ODrive Pro and can finally use an ADC input to control my spindle.

                                  chimaeraghundefined 1 Reply Last reply Reply Quote 0
                                  • chimaeraghundefined
                                    chimaeragh @CthulhuLabs
                                    last edited by chimaeragh

                                    @cthulhulabs My DeWalt is configured as a spindle and is automated via a relay. So I can use M3 to start it and M5 to stop it. (Already modified my Vectric postprocessor for this)
                                    I added M3 and M5 commands into the surfacing loop at line 89 and line 148 of the macro.

                                    T1 ; selects the spindle Tool 1

                                    M3 S17500 ; starts tool

                                    Duet 2 Wifi, Ooznest Workbee CNC 1510

                                    CthulhuLabsundefined 1 Reply Last reply Reply Quote 0
                                    • CthulhuLabsundefined
                                      CthulhuLabs @chimaeragh
                                      last edited by

                                      @chimaeragh Cool. There is a variable at the top for the spindle RPMs. Now that my spindle RPM can be controlled by the Duet I plan to add it. You should probably use that in your M3 command.

                                      I am thinking of rewriting this Macro to only cut in one direction to give a more uniform surface finish. Basically cut from Left to Right, raise up, rapid to the next cut, lower and repeat. There would be a flag in it to change it between Left to Right and Right to Left. Might also add a flag to go from top to bottom or bottom to top.

                                      nikki-mundefined 1 Reply Last reply Reply Quote 0
                                      • nikki-mundefined
                                        nikki-m @CthulhuLabs
                                        last edited by

                                        @CthulhuLabs I use your surfacing.g code on a regular basis. Love it.
                                        But is there any way to modify it so that the Depth of Cut could be adjusted by user input?

                                        It would be nice to be able to enter a different value each time I use this macro, without having to edit the code. It would be even nicer if the DOC could be modified on each susbequent pass ("run again"). Perhaps also to limit the input value to between 0.1mm and 3.0mm?

                                        HebigTundefined 1 Reply Last reply Reply Quote 0
                                        • HebigTundefined
                                          HebigT @nikki-m
                                          last edited by

                                          @nikki-m

                                          I know you can pass parameters to a macro in the macro call itself (e.g. depth of pass)

                                          Manually choosing this value on each run of the macro may be possible now using M291 on 3.5 beta firmware.

                                          nikki-mundefined 1 Reply Last reply Reply Quote 0
                                          • nikki-mundefined
                                            nikki-m @HebigT
                                            last edited by

                                            @HebigT Yes, I did look into the M291 function, but sadly, I am still on the v3.3 (awaiting any update from Ooznest)!!
                                            Does this mean that there is no other way to program in a variable DOC? Apart from setting up numerous versions of the macro, each with a different value for the doc?

                                            HebigTundefined 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Unless otherwise noted, all forum content is licensed under CC-BY-SA