Giter Site home page Giter Site logo

gpr's Introduction

Synopsis

GPR is a small, MIT license, C++11 G-code parser. It is intended to provide the lowest level of parsing for G-code, breaking up raw G-code text into blocks consisting of comments and word-address style commands.

What is G-code?

G-code is the universal language of machine tools. It is used to control everything from mills and lathes to EDM machines and 3D printers.

Though the syntax and semantics of g-code are officially defined by ISO 6983 it is not really a single language. Different machine vendors implement different subsets of the standard and different non-standard extensions for their own equipment.

What everybody agrees on is that G-code programs consist of blocks, which are really just lines of text. Each block consists of:

  1. An optional block delete character '/'
  2. An optional line number
  3. Any number of words, parameter settings and comments
  4. An end of line marker (carriage return)

G-code emitted by modern CAM systems usually consists mostly of comments and words. For example the G-code program below has 4 blocks: 1 comment, and three movement commands.


(*** Toolpath 1 ***)
G0 X0.0 Y0.0 Z0.0
G1 X1.0 F23.0
G1 Z-1.0 F10.0

Since the interpretation of G-code commands varies from vendor to vendor this parser does not make any attempt to interpret G-code commands. It simply parses G-code and returns the parsed blocks.

G-code Dialects Supported

This parser has been tested on 5 different G-code samples which are in the gcode_samples folder

  1. RepRap: A common G-code dialect used by 3D printers like the monoprice select mini, the sample was produced by Cura.
  2. LinuxCNC: The sample in the github repo was produced for a 3 axis mill by an experimental CAM system from Stanford.
  3. Vectric: Generated by VCarve Pro for a CAMASTER router
  4. HAAS: Taken from a machinists forum post.
  5. Mazak: Produced by Mazak's Mazatrol to G-code converter.

Build Instructions

cmake .
make -j
./all-tests

Feedback

If you use this parser in your own project I would really like to hear from you about it. Let me know what you liked and what could be better, and if you like this parser please give the repo a star!

gpr's People

Contributors

code-beans avatar dillonhuff avatar tweakoz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gpr's Issues

parser.cpp segmentation error

Hi, @dillonhuff
Faced the problem of parsing this non-standard code. M76 X Or something like that, without the address at the end.

There is a segmentation error in the line 249.

string next_next = *(s.remaining() + 1);

Perhaps it's worth checking the presence of the address somehow?

if (s.remaining() + 1 != s.end()) {
    string next_next = *(s.remaining() + 1);

    if (!is_num_char(next_next[0])) {
        return parse_isolated_word(s);
    }

    return parse_word_address(s);
}
return parse_isolated_word(s);

"Library not loaded: @rpath/libgpr.dylib" when running tests/example

cmake .
make

then

$ ./all-tests
dyld[97154]: Library not loaded: @rpath/libgpr.dylib
  Referenced from: /Users/bramp/gpr/all-tests
  Reason: tried: '/usr/local/lib/libgpr.dylib' (no such file), '/usr/lib/libgpr.dylib' (no such file)
Abort trap: 6

Same issue with ./parse-gcode.

I don't understand dynamic linkers enough, but this is on a Mac.

Support the parsing of decimal gcode / sub codes

Prusa has a set of sub codes codes documented here. For example:

M862.1 P0.4 ; nozzle diameter check
M862.3 P "MK3S" ; printer model check

This appear in gcode files I generate with Prusa Slicer. gpr will parse them, but it seems to drop the decimal part, ".1", ".2", etc.

Wondering if it does text/numbers to Gcode

Hello,

I have a small question. I'm looking for a program that can run in a commandline that will output gcode from an input from a string (numbers and text). I was wondering if this does that?

Comments?

Nice code, but please make it a habbit to add comments.

What is a chunk?
What is a block?

How can I see the data in the debugger? (QT Creator)

Thanks :)

run all tests failed

I successfully build the code but when I run the all test, it gives me the error:

all-tests is a Catch v1.3.1 host application.
Run with -? for options

-------------------------------------------------------------------------------
Full sample parsing
  Parse HAAS sample
-------------------------------------------------------------------------------
/home/flexiv/Downloads/gpr/test/parser_tests.cpp:170
...............................................................................

/home/flexiv/Downloads/gpr/test/parser_tests.cpp:203: FAILED:
due to a fatal error condition:
  SIGSEGV - Segmentation violation signal

===============================================================================
test cases: 19 | 18 passed | 1 failed
assertions: 28 | 27 passed | 1 failed



It seems the parser did not succeed when handling the file HAAS_sample.NCF.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.