Skip to content
A simple C++ G-code parser
C++ CMake
Branch: master
Clone or download
Latest commit e1e417e Aug 19, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gcode_samples Can parse linuxcnc without a problem Jul 9, 2017
src fix ix build issues Aug 18, 2018
test Commented out the file read time test Aug 4, 2017
.gitignore Added libgpr.dylib to .gitignore Aug 19, 2018
.travis.yml Added travis file Aug 19, 2018
CMakeLists.txt enable osx rpath Aug 18, 2018
LICENSE Added a license file Feb 14, 2017
README.md Changed list bold Dec 23, 2017

README.md

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.

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!

You can’t perform that action at this time.