Experimental gcode interpreter accepting c++ syntax.

More
19 Apr 2024 13:50 #298615 by Grotius
Hi,

Disclaimer : * this post is just for info. *

We all know the SAI "stand alone interpreter" from linuxcnc is quite complex.

Therefore i was investing some time in building a interpreter my self. I started using the muParser library
and wrote code to parse gcode. I was focussing on the hard part, like how to deal with nested while loops in the gcode.
I finally get that to work using a node structure. But how about the rest. Like integrating for loops, if, else, and everything else.

After 2 weeks, i decided to try something different. So i made 2 programs. The first program is a gcode parser, the second
program is a interpreter.
In my previous attempt i was trying to reinvent the wheel, but now the gcc compiler does the work for me.
All this code was working within 2 day's.

What is special about this gcode program builder in my opinion :
- It compiles gcode programs into a executable.
- It parses raw gcode into gcode the interpreter can read, like parsing G0 to G(0);
- Within the gcode, c++ code may be used. So when program run's you can just start your ethercat master from inside the gcode.
- Also all hal commands, and all possible c++ code solutions can be used. So in fact you can load and run a entire AI from the gcode.
- Sub programs may be compiled and run within the running gcode. This is a slower process, but is possible.
- Each gcode program that runs send's data to the interpreter trough shared memory.
- Sub programs may be called inside the gcode, they may run in seperate thread by using "&", or in the current program flow,
as a result, this could run multiple machines at the same time, as multiple gcode processes are running.
- Perfect syntax debugging trough the compile process.
- Gcode executables are closed source, so a customer may run the file, but can not directly edit or copy the file so easely.
- Time optimal solution, compiled code is fast.
- Compact and simple source code.

What is the interpreter doing :
- It opens and run's the given gcode executable file.
- It reads the shared memory, the gcode file is sending data struct to, and fills a local string buffer with the gcode commands.
- It displays the gcode commands in the program.
- It waits for ok signal when asked by the gcode program, this is for probing, or for other things that need a ok signal to go on.

Downsides:
- Gcode files are compiled machine code.

Preview gcode program builder :
 

Preview interpreter:
 

For now the interpreter runs in the user environment. No hal connection is made so far.









 
Attachments:
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

Time to create page: 0.144 seconds
Powered by Kunena Forum