I started working on adding a routine to webcontrol to perform gcode optimization. I stumbled upon a python implementation of travelling salesperson problem (TSP) that used genetic algorithm that I think will work with some adaptation since this isn’t precisely a TSP:
I made some modifications to it and I think it will work. But the real difficulty with gcode optimization turns out to be the parsing of the gcode and its re-assembly after the code is optimized. So I started this thread in hope knowledgeable people could provide some feedback and answer questions.
*Note:I’m putting aside optimizing gcode with tool changes, lasers, spindle control, relative positioning etc. until I can get gcode without any of them optimized.
In a CAM program, you typically set a traverse height that’s used for G0 moves. I can parse through gcode and determine what that value is and then use that to rebuild the G0 moves.
My first question: is there any reason to assume a gcode would have different traverse heights in G0 commands? That is, one G0 command uses 5 mm whereas another would use 7 mm? My thought is to just use the max Z value in a G0 command as the traverse height… this assumes that some silly CAM program would not just start off with a G0 Z25 but then use G0 Z5 when preparing to do a G0 XY? I wouldn’t want to use 25 for all the traverses when 5 is what the user wanted.
Right now I am breaking the gcode up into segments bracketed by G0/G00 commands… this leads to the following questions:
My second question: is there any reason to expect a CAM program to use a G0 Z command to move downward into a work piece? I would expect anything into a work piece to be a G1 Z command.
My third question: is there any reason to expect a CAM program to use a G0 Z command to move upward but not out completely out of a work piece? For example, during a move to cut a tab, might a gcode program use G0 Z+ to lift the bit to clear the tab? Since it’s not cutting material, maybe some CAM program might use max feed rate…