AXIS: EMC2 Blog|
Blog
About AXIS Get EMC2 Documentation Translations ETCH CNC Developer Homepages: Chris Radek Jeff Epler Related sites: linuxcnc.org linuxcnc wiki | « Updating Configuration Files for the development version of EMC2 | Newest entries | jdi.py: Just Do It » Tcl makes a nice g-code preprocessor. I've proposed this twice before, but everyone seems to think I'm joking---I'm actually a bit serious. Because Tcl is an existing language, it has set rules for parsing, execution, variable scoping, and all those other hard things about computer language design. By finding a way to let simple g-code snippets pass through unaltered, but also escape to the full Tcl language, you get power and familiarity with very little effort. Here's an example, which will mill a set of slots in an efficient manner (first from left to right, then from right to left):
A ".gcl" file (pending a better choice of name---I'm told this extension
is already used for GNU common lisp files) is processed by "gcode.tcl"
to create a .ngc file output. Almost any g-code program which does not
use square brackets or variables will be unchanged when processed, but
Tcl variables and control structures like the for-loop shown here, may
also be used. Specifically, the .gcl file is processed just like a
"source"'d .tcl file, but when an unknown Tcl command is encountered
(one not built-in or defined by a 'proc'), and it starts with one of the
characters In the set "GMXYZABC(", it is copied to the output.
Tcl has not only integer and floating-point numbers, but also strings, lists, and arrays. Tcl extensions can be written in C, C++, and other languages, so an interface to a library like CGAL could be implemented, easing the work of writing code to mill irregular pockets. And finally, the Tk graphical toolkit is accessible by simply putting 'package require Tk' in your .gcl file, allowing the program to include its own user-prompting facility. The downsides to any "preprocess to linear g-code" method is that infinite programs cannot be written (though in fact, you can write O-words to the output of a gcl program), and that program logic cannot depend on the result of a probe operation (though again you can still "escape" to O-words). These may be required features for a few people, but probably not for most. Files currently attached to this page:
|
| [æ] |