Experimental gcode interpreter accepting c++ syntax.

More
2 years 6 months ago #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 :
 

Attachment not found



Preview interpreter:
 

Attachment not found



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









 

Please Log in to join the conversation.

More
2 years 5 months ago #300703 by programador
Very good, congratulations on the initiative.
I am developing a G code generator in Python that transforms DXF files for a punch press. It is not being easy, there is a lack of professionals in the market for such a challenge.

Please Log in to join the conversation.

More
2 years 5 months ago #300861 by blazini36
Sounds cool, could solve some issues trying to work HAL controls into Gcode without using workarounds.

What are the actual plans for it? I assume it will be made available, is it designed to be run as an alternative to the standard interpreter? Integrated into GUIs etc..

Please Log in to join the conversation.

More
2 years 5 months ago #300890 by Grotius
@Programmador,

Very good, congratulations on the initiative.
I am developing a G code generator in Python that transforms DXF files for a punch press. It is not being easy, there is a lack of professionals in the market for such a challenge.


There is a good read in dxf library for c++, for python there is also a dxf lib. I think ezdxf.
Along the way, you will succeed somehow.

@BlazinI36

Sounds cool, could solve some issues trying to work HAL controls into Gcode without using workarounds.
Yeah, you can use c or c++ directly in the gcode file.
I was thinking to create a virtual ethercat slave, that is not a servo
or a stepper but a gcode interpreter.

What are the actual plans for it? I assume it will be made available, is it designed to be run as an alternative to the standard interpreter? Integrated into GUIs etc..
At the moment i have no time to develop it further as the trajectory planner has to be finished. After that
i maybe will go on this interpreter.

The whole idea for this test is, how should you create a interpreter. I have used a parser like muparser. But this is
a waste of time. The best parser so far i found is the gcc compiler.

I have no plans with it further at the moment. It's like a time stamp in my programming experience, maybe i can use
the knowlegde later on. But it sure has potential to be become fully functional.

Please Log in to join the conversation.

Time to create page: 0.085 seconds
Powered by Kunena Forum