My thoughts are solidifying a little bit regarding a "G code macro system". I think that I will roll my own, since I am a computer programmer.
I started writing perl code to perform standard milling tasks. For example, I wrote a function to print G code that would move to a given location, both for G00 as well as for G01 (trivial).
Then I wrote a perl function that would print G code to drill a hole, with optional pecking (drill to pecking depth, quickly withdraw, quickly return to drilling depth, and repeat until proper depth is reached).
For every standard type of task, like drill a bolt hole pattern, mill out a blind hole, mill out a through hole, etc, I will write a function to do that. I will build on functions, e.g. the bolt hole function will use a drilling function, etc.
I am sure that this will not cover "True 3D" curvy surfaces, like milling a statue of a naked woman in 4 axis machining, like on YouTube, but it will cover most of the actual projects that I will encounter.
I am attaching a function to drill a hole with pecking, and the resulting G code (all untested).
Code to drill, say, three holes of depth (-1) in points (0, 0), (2,3), and (3,3) at speed 5 and pecking depth of 0.3, would look like this perl code:
g_set_clear_height( 0 ); g_drill_hole( 0, 0, -1, 5, 0.3 ); g_drill_hole( 2, 3, -1, 5, 0.3 ); g_drill_hole( 3, 3, -1, 5, 0.3 );
This is much more understandable than many other alternatives.
I am sure that I do not really know how to use G codes, but I know that this is a good approach in general.
If it works well for me, I will release it under GPL.
i###################################################################### function sub g_drill_hole { my ($x, $y, $z, $speed, $pecking_depth) = @_; die "For drilling application, you need to do g_set_clear_height first" unless defined $_clear_height;
die "Drilling depth Z=$z should be LESS THAN safe height=$_clear_height." if $z > $_clear_height; Print "(Drill a hole in [$x, $y] depth of $z.)\n"; deeper; { Print "(withdraw to safe height)\n"; g_goto( undef, undef, $_clear_height ); Print "(go to starting point)\n"; g_goto( $x, $y ); if ( $pecking_depth ) { Print "(Drilling with pecking)\n"; my $cur_z = $_clear_height; my $i = 0; while( $cur_z > $z ) { $i++; print "\n"; if ( $cur_z - $pecking_depth > $z ) { Print "(Peck $i -- drill, clear chips, go back)\n"; deeper; { g_millto( undef, undef, $cur_z - $pecking_depth, $speed ); g_goto( undef, undef, $_clear_height ); g_goto( undef, undef, $cur_z - $pecking_depth ); } lower; $cur_z = $cur_z - $pecking_depth; } else { Print "(Last drilling step)\n"; g_millto( undef, undef, $z, $speed ); $cur_z = $z; } } } else { Print "(Drilling)\n"; g_millto( undef, undef, $z, $speed ); } Print "(Returning to safe height)\n"; g_goto( undef, undef, $_clear_height ); } lower; }
###################################################################### G Code
(Drill a hole in [3, 4] depth of 0.) (withdraw to safe height) (Go to point Z1 ) G00 Z1
(go to starting point) (Go to point X3 Y4 ) G00 X3 Y4
(Drilling with pecking)
(Peck 1 -- drill, clear chips, go back) (Mill to: Z0.7 at speed F5 ) G01 Z0.7 F5
(Go to point Z1 ) G00 Z1
(Go to point Z0.7 ) G00 Z0.7
(Peck 2 -- drill, clear chips, go back) (Mill to: Z0.4 at speed F5 ) G01 Z0.4 F5
(Go to point Z1 ) G00 Z1
(Go to point Z0.4 ) G00 Z0.4
(Peck 3 -- drill, clear chips, go back) (Mill to: Z0.1 at speed F5 ) G01 Z0.1 F5
(Go to point Z1 ) G00 Z1
(Go to point Z0.1 ) G00 Z0.1
(Last drilling step) (Mill to: Z0 at speed F5 ) G01 Z0 F5
(Returning to safe height) (Go to point Z1 ) G00 Z1