" VIM script to post process LightBurn CNC laser GRBL gcode converting it to " plasma process gcode. Pre-requisite: In LB, select machine type GRBL-M3 for code " generation. " author: Lou Cipriano v3 12/01/21 " " Net actions: replace M3, M4, M5 gcode commands with plasma torch touchoff probes. " " 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 or M4 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 to the 'replace with \=subtext' message 'n' (No) to the first occurance " of replacing M3, then respond with 'a' (All) to the second occurance. " Do the same in the next message, which replaces the M5 commands. " The final message re ';end probe ITH' not found to end of file is normal, " just press Enter to finish the script. " " Define the function to VIM by adding stmt " ':source \plasmapp3.vim' " to the VIM Startup Settings file (menu Edit-Startup Settings) _vimrc. " Download VIM editor at vim.org. Use version 8.2 or better. " function MyPlasmaPP(isRampZ=1, isG90mode=0, isG20mode=0, ITH=1.7, PD=1.1, PH=a:ITH*2.0) " 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 has an " effect on the size of the pierce hole. A gouge effect can be made if Z " moves either ramp or plunge, but the timing varies for each. So make the " dwell dependent on the Z move type. :let s:PD = a:PD :let s:dwellPD = s:PD * (a:isRampZ ? 0.5 : 0.3) :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 :let s:TPT = 8.7 " 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 :) " load @q register with recorded keystroke seq to do the work... :set wrapscan :let @q = "gg/M5 /M3 jfFd$" :normal @q :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 :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+1.1) :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" :%s/\(M3\|M4\)/\=s:subtext/gc :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" :%s/M5/\=s:subtext/gc " 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. " " first turn off wrapscan (file wrapping during search) " then go to top of file and commence search and append. " The keystroke sequence is stored in a VIM register, terminated with a " recursive call, thus it loops to end of file. " The last recursive search for the tag line will result in a VIM not-found " error which is normal. :if a:isRampZ :set nowrapscan :normal gg :let @r = "/^;end probe ITH jj$a " :let @r .= "G93 " .. printf("F%.3f Z%.3f",s:zG93Feed,s:PH2ITH) .. " (ramp Z, remainder of PD)\n" :let @r .= "G94 (restore distance units move mode)\n" :let @r .= s:TrestoreFeedrate .. " (restore feedrate)" :let @r .= "@r" " to normal mode and make register macro replay recursive :normal @r :set wrapscan :endif :endfunction