" 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 11/17/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. add the gcode Z axis move command to transition from Pierce Height " to Initial Torch Height. Combine this Z transition with the " plasma lead-in cut (XY) movement, thus this ramps the torch tip " down to ITH while moving laterally away from the pierce and resulting " dross blown back from the pierce. Thus the torch tip has less chance of " collision with the pierce dross. " " 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.7) " for case of gcode generated as G90 (absolute coords), G20 (imperial units), and you " desire an ITH of 1.7mm. 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(isG90mode=0, isG20mode=0, ITH=1.6, PD=1.0, PH=a:ITH*2.25) " 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 :let s:PD = a:PD " Torch Probe Travel (TPT) in mm :let s:TPT = 9.3 " Safe Retract (SR) in mm :let s:SR = 10 " M5 Safe Retract Delay (M5RD) in seconds :let s:M5RD = 1.0 :let s:PH2ITH = s:ITH - s:PH "make this distance and direction relative to PH :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 jfFly$" :normal @q :let s:TrestoreFeedrate = @" "yank'd as text data type " handle absolute (G90) vs relative (G91) gcode move modes :if a:isG90mode :let s:PH2ITH = s:ITH :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: " .. printf("ITH=%.1fmm, PD=%.1fs, PH=%.1fmm\r",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)) .. " F1000 (probe fast to find limit swtch)\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",s:PD) .. " (pierce delay, make THC delay => this+1.1)\r" :let s:subtext .= s:restoreMoveModes != "" ? s:restoreMoveModes .. " (restore changed modes)\r" : "" :let s:subtext .= "G1 F" .. s:TrestoreFeedrate .. " (restore feedrate)\r" :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 " 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 " " 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. :set nowrapscan :normal gg :let @r = "/;end probe ITH jj$a" .. printf("Z%.3f",s:PH2ITH) .. " (Z ramp down to ITH on lead-in cut)@r" :normal @r :set wrapscan :endfunction