G-code preprocessor/meta-language - Page 1
Forum section: electronics / general

author: Bertho
author_rank: Regular Contributor
timestamp: October 20, 2013, 02:35:26 pm
content: Hi all,I've been writing G-code for CNC milling a bit, but it is a real pain and gets very messy. Even with subroutines and variables, it gets a real pain when the program gets larger. Looking on the web for a "meta"-language or preprocessor for G-code came up with no real hits that were useful.Does anybody know of a meta-language/preprocessor for making G-code programs? I amnotlooking for CAD/CAM software packages. However, I am looking for a structured (context-free) formulation that easily maps to G-code. A language that is writable andreadable.--Greetings Bertho

author: MarkL
author_rank: Unknown
timestamp: November 04, 2013, 03:24:47 am
content: Take a look here:http://wiki.linuxcnc.org/cgi-bin/wiki.pl?CamThere are links to G-code generators for a bunch of different source languages that you might feel more comfortable with (C, Tcl/Tk, and python to name a few).G-code is pretty awful, I would agree, but I hold my nose and write in it anyway. It's the best way to make the machine do *exactly* what you want.

author: Bertho
author_rank: Regular Contributor
timestamp: November 04, 2013, 04:15:34 am
content: I did look at linuxcnc and there was nothing there that could satisfy me.Therefore, I wrote my own meta language: gcmc - G-Code Meta CompilerIt is a script interpreter and a context free grammar using the procedural programming language paradigm. It has complete vector calculation support and lists to trace paths easily.You can find my meta compiler athttp://www.vagrearg.org/content/gcmc

author: awallin
author_rank: Frequent Contributor
timestamp: November 04, 2013, 06:01:34 am
content: You might look at APThttp://en.wikipedia.org/wiki/APT_%28programming_language%29Are you milling PCBs? Is there a good open-source program for producing G-code from gerber-files?AW

author: Bertho
author_rank: Regular Contributor
timestamp: November 04, 2013, 09:42:12 am
content: I did look at APT. APT falls is the same category as gcode: archaic. It made my eyes and brain hurt when I saw it.As said, I solved my problem by writing a language from the ground up.

author: johnwa
author_rank: Frequent Contributor
timestamp: November 05, 2013, 06:48:52 am
content: Quote from: Bertho on November 04, 2013, 04:15:34 amIt seems this is a common problem, I did something quite similar a while ago for my CNC router. I was using TurboCNC as the interpreter, which fortunately supports indirect variable references. I basically just treated the G-code interpreter as an 'assembler', and wrote my own little 'compiler', for a BASIC-like language with global and local variables, and functions with parameters and return values.Unfortunately, I found the large programs that it generated tended to uncover some bugs in TurboCNC, and I eventually lost interest in it. It is good to see that there are a few more options available now for CNC programming.Oh, and for the OP: It is possible to run the C preprocessor on things other than C source files - this might be a possibility if you only want something simple.

author: Bertho
author_rank: Regular Contributor
timestamp: November 05, 2013, 11:41:31 am
content: Quote from: johnwa on November 05, 2013, 06:48:52 amYes, the problem seems more common. However, a basic-like language was not enough for me. I wanted a full-fledged language without the need for line numbers or context dependent stuff. Also, I wanted complete vector calculations in the language.QuoteHm, uncovering bugs in the gcode interpreter is bad if they do not get fixed (I use LinuxCNC). Luckily, I only generate very basic movement commands; very low-level. It should reduce the possibility of hitting any kind of errors.QuoteYou can run a C-preprocessor on anything. The question is whether it is a good idea ;-)

author: Bertho
author_rank: Regular Contributor
timestamp: November 24, 2013, 06:22:52 pm
content: I've been working incrementally to improve on my original design for the meta compiler. The current version 1.4.0 has backends to generate G-code, SVG and DXF files from the same script. Now gcmc can be used not only for mills and lathes, but also for laser cutters and all things I have not yet thought about.There are several screenshots with script-source links on the gcmc homepage athttp://www.vagrearg.org/content/gcmc#screenshotsand you can get the gcmc source/executable files from there too.Examples:and