Author Topic: G-code preprocessor/meta-language  (Read 7562 times)

0 Members and 1 Guest are viewing this topic.

Offline BerthoTopic starter

  • Regular Contributor
  • *
  • Posts: 96
  • Country: 00
G-code preprocessor/meta-language
« on: October 20, 2013, 02:35:26 pm »
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 am not looking 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 and readable.

--
Greetings Bertho
 

Online MarkL

  • Supporter
  • ****
  • Posts: 2330
  • Country: us
Re: G-code preprocessor/meta-language
« Reply #1 on: November 04, 2013, 03:24:47 am »
Take a look here:

  http://wiki.linuxcnc.org/cgi-bin/wiki.pl?Cam

There 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.
 

Offline BerthoTopic starter

  • Regular Contributor
  • *
  • Posts: 96
  • Country: 00
Re: G-code preprocessor/meta-language
« Reply #2 on: November 04, 2013, 04:15:34 am »
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 Compiler
It 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 at http://www.vagrearg.org/content/gcmc
 

Offline awallin

  • Frequent Contributor
  • **
  • Posts: 694
Re: G-code preprocessor/meta-language
« Reply #3 on: November 04, 2013, 06:01:34 am »
You might look at APT
http://en.wikipedia.org/wiki/APT_%28programming_language%29

Are you milling PCBs? Is there a good open-source program for producing G-code from gerber-files?

AW
 

Offline BerthoTopic starter

  • Regular Contributor
  • *
  • Posts: 96
  • Country: 00
Re: G-code preprocessor/meta-language
« Reply #4 on: November 04, 2013, 09:42:12 am »
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.
 

Offline johnwa

  • Frequent Contributor
  • **
  • Posts: 255
  • Country: au
    • loopgain.net - a few of my projects
Re: G-code preprocessor/meta-language
« Reply #5 on: November 05, 2013, 06:48:52 am »
Therefore, I wrote my own meta language: gcmc - G-Code Meta Compiler
It 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.

It 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.
 

Offline BerthoTopic starter

  • Regular Contributor
  • *
  • Posts: 96
  • Country: 00
Re: G-code preprocessor/meta-language
« Reply #6 on: November 05, 2013, 11:41:31 am »
It 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.
Yes, 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.

Quote
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.
Hm, 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.

Quote
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.
You can run a C-preprocessor on anything. The question is whether it is a good idea ;-)
 

Offline BerthoTopic starter

  • Regular Contributor
  • *
  • Posts: 96
  • Country: 00
Re: G-code preprocessor/meta-language
« Reply #7 on: November 24, 2013, 06:22:52 pm »
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 at http://www.vagrearg.org/content/gcmc#screenshots and you can get the gcmc source/executable files from there too.

Examples:

and

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf