" VIM script to post process LightBurn CNC laser GRBL gcode converting it to " plasma process gcode. " " Pre-requisite: In LB, select device type GRBL-M3 for code generation. " author: Lou Cipriano v4 12/29/21 " " Net actions: replace M3 and M5 gcode commands with plasma torch touchoff probes " and retracts respectively. " " Use vim find and replace (:s[ubstitute]) command globally in the file, along with " some recursive @register recorded keystroke sequences... " " Specifically, post process gcode file to change or add these functions: " 1. replace M3 with a block of gcode to begin a plasma cut. " 2. replace M5 with a block of gcode to end a plasma cut. " 3. optionally, add a timed and lateral move to the Z axis transition from Pierce Height " to Initial Torch Height, the lateral move being the " plasma lead-in cut, and the timed element being a component of the " Pierce Delay. These actions should reduce the risk of torch tip " collision with blowback dross during the pierce. " This Z ramp move is optional since there are some instances where LB " does not use a lead-in, such as during tab/bridge cutting and when not " programmed into the layer. " " Script Usage " The code is defined to run as a VIM user defined funtion MyPlasmaPP(), see " the arg list below in the function definition. " When editing your gcode file, simple press to enter command mode, then " type ':Call MyPlasmaPP()' enter. Override default args as desired. For " example - :Call MyPlasmaPP(1,1,1,2.0) " for case of gcode generated with Z ramp, G90 (absolute) coords, G20 (imperial) units, and you " desire an ITH of 2.0mm. ITH and PH are always specified in mm, but " converted in the script as needed to match the mode at time of use. " " Respond 'a' to the 'replace with \=subtext' message to change ALL occurances of M3 commands. " Do the same in the next message, which replaces all occurances of M5 commands. " Define the function to VIM by adding stmt " ':source \plasmapp4.vim' " to the VIM Startup Settings file (menu Edit-Startup Settings) _vimrc. " Download VIM editor at vim.org. Use version 8.2 or later. " the function defaults work well on mild steel 18ga to 10ga. function MyPlasmaPP(isRampZ=1, isG90mode=0, isG20mode=0, ITH=1.5, PD=1.1, PH=a:ITH*2.2) " Initial Torch Height or cutting height (ITH) in mm :let s:ITH = a:ITH " Pierce Height (PH) in mm :let s:PH = a:PH " Pierce Delay (PD) in seconds " This pierce method has Z is moving during pierce either in a ramp (w XY on lead=in) " or in a plunge when no lead-in. The dwell time while Z is static at beginning of pierce " is intended to account for most of the mechanical relay and pneumatic soleniod reaction " delays in the torch trigger circuit. After that dwell, beginning moving Z as the plasma " jet begins to pierce the metal. Movement of the torch at this time " provides for some control of the blowback pierce dross. For instance, a gouge effect can " be made if Z moves either ramp or plunge, but the timing varies for each, thus this " code not only splits the overall Pierce Delay value, but also makes the static dwell " dependent on the Z move type. :let s:PD = a:PD :let s:dwellPD = s:PD * (a:isRampZ ? 0.6 : 0.4) :let s:zG93Feed = 60.0 / (s:PD - s:dwellPD) "inverse time feed rate for G93 mode during Z ramp or plunge " Torch Probe Travel (TPT) in mm " This is the travel of the torch on the gravity fed Z carriage once the torch " tip contacts the top of material and until the probe switch is closed. :let s:TPT = 8.6 " Safe Retract (SR) in mm :let s:SR = 20 " M5 Safe Retract Delay (M5RD) in seconds :let s:M5RD = 1.0 :let s:PH2ITH = s:ITH - s:PH "calc distance and direction for transition from PH to ITH :let s:restoreMoveModes = "" " find the first feedrate and save it " feedrate must be last value in the line, it usually is :) " normal command is defined as follows: " gg (goto top of file), /^M3\r (find first M3 in col 1), jfF (down one line, " find F), d$ (delete to end of line and save Fnnn value to @- reg) exe "normal gg/^M3\rjfFd$" :let s:TrestoreFeedrate = @- "deleted chars are Feedrate as text data type, such as Fnnnn " handle absolute (G90) vs relative (G91) gcode move modes :if a:isG90mode :let s:PH2ITH = s:ITH "PH to ITH is now relative to Z0 :let s:restoreMoveModes .= "G90 " :endif " handle imperial (G20) vs metric (G21) gcode unit modes :if a:isG20mode :let s:PH2ITH /= 25.4 " PH2ITH was set in mm units, convert to imperial :let s:restoreMoveModes .= "G20 " :endif " Build the Torch Probe Touchoff gcode block that will replace the LB planted M3 command. " :let s:subtext = "\r;begin torch touchoff probe: " :let s:subtext .= printf("isRampZ=%d, ITH=%.1fmm, PD=%.1fs, PH=%.1fmm\r",a:isRampZ,s:ITH,s:PD,s:PH) :let s:subtext .= "G21 G91 (metric and relative)\r" :let s:subtext .= "G0 " .. printf("Z-%.3f",s:SR) .. " (Z down, undo previous safe retract)\r" :let s:subtext .= "G38.2 " .. printf("Z-%.3f",(s:TPT+s:ITH+2.0)) .. " F1000 (probe fast to find limit switch)\r" :let s:subtext .= "G0 Z5 (pull off limit switch, ready for slow probe)\r" :let s:subtext .= "G4 P0.400 (delay for probe switch debounce)\r" :let s:subtext .= "G38.2 Z-5 F50 (probe slow for accurate make on switch)\r" :let s:subtext .= "G0 " .. printf("Z%.3f",s:TPT) .. " (retract TPT, to top of material)\r" :let s:subtext .= "G92 Z0 (reset temp Z0 in case of absolute mode gcode file gen)\r" :let s:subtext .= "G0 " .. printf("Z%.3f",s:PH) .. " (retract to PH)\r" :let s:subtext .= "M3 (light it up)\r" :let s:subtext .= "G4 " .. printf("P%.3f (partial pierce delay; set THC DLY=>%.1f)\r",s:dwellPD,s:PD+0.7) :let s:subtext .= s:restoreMoveModes != "" ? s:restoreMoveModes .. " (restore changed modes)\r" : "" :if !a:isRampZ :let s:subtext .= "G1 G93 " .. printf("F%.3f Z%.3f",s:zG93Feed,s:PH2ITH) .. " (plunge Z, remainder of PD)\r" :let s:subtext .= "G94 (restore distance units move mode)\r" :let s:subtext .= s:TrestoreFeedrate .. " (restore feedrate)\r" :endif :let s:subtext .= ";end probe ITH\r" " Replace all instances of LB planted M3 commands in col 1 with the " Torch Probe Touchoff gcode block created above. :%s/^M3/\=s:subtext/c :let s:subtext = "\r;begin safe retract and ready for probing next cut ITH\r" :let s:subtext .= "G21 G91 (metric and relative)\r" :let s:subtext .= "M5 (put it out)\r" :let s:subtext .= "G4 " .. printf("P%.3f",s:M5RD) .. " (wait for THC to give Z control back to GRBL)\r" :let s:subtext .= "G0 " .. printf("Z%.3f",s:SR) .. " (fast retract to safe height)\r" :let s:subtext .= s:restoreMoveModes != "" ? s:restoreMoveModes .. " (restore changed modes)\r" : "" :let s:subtext .= ";end safe retract and ready ITH\r" " goto top of file, find the 2nd M5 in col 1, " then replace this and all subsequent LB planted M5 commands in col 1 " to the retract code block created above. exe "normal gg 2/^M5\r" :.,$s/^M5/\=s:subtext/c " if using lead-ins and desiring to ramp Z down during transition from PH to " ITH, then this code needs to append a few commands to the lead-in cut " Note that when using LB tabs or bridges, lead-ins are not applied to those " cuts, so consider cutting that layer separately and first, using the " isRampZ=0 arg " " append Z PH-to-ITH transition movement to the pierce XY cut, which should be a lead=in cut. " this effects a ramp down of Z to the ITH. Also, make this a 'timed' mode " feedrate rather than the usual distance mode feedrate. The time duration " of the cut is a component of the pierce delay, this further mitigates risk " of torch tip collision with pierce dross. :if a:isRampZ :let s:cmd = "jj$a " :let s:cmd .= "G93 " .. printf("F%.3f Z%.3f",s:zG93Feed,s:PH2ITH) .. " (ramp Z, remainder of PD)\r" :let s:cmd .= "G94 (restore distance units move mode)\r" :let s:cmd .= s:TrestoreFeedrate .. " (restore feedrate)" " append to lead-ins, which will follow the original M3 command, " which is now ';end probe ITH' beginning in col 1 :%g/^;end probe ITH/exe "normal" s:cmd :endif :endfunction