https://github.com/martinfrances107/gcode-nom
Visualize G-code files
https://github.com/martinfrances107/gcode-nom
byte-array grammer nom parse parser parser-combinator rust validator
Last synced: 19 days ago
JSON representation
Visualize G-code files
- Host: GitHub
- URL: https://github.com/martinfrances107/gcode-nom
- Owner: martinfrances107
- Created: 2024-10-31T22:21:31.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-04-01T22:04:53.000Z (27 days ago)
- Last Synced: 2025-04-09T23:09:52.113Z (19 days ago)
- Topics: byte-array, grammer, nom, parse, parser, parser-combinator, rust, validator
- Language: G-code
- Homepage:
- Size: 30.2 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gcode-nom
Rust 2021 Edition.
A library containing a full set of [nom](https://crates.io/crates/nom) parsers for decoding gcode files.
Both .gcode files and binary .bgcode files are recognized.
Based on this library the workspace contains a series of visualization tools
* gcode2obj - Generates "WaveFront Obj" files.
* gcode2svg - Generates SVG files.
* gcodeExtractThumbs - Extracts the images embedded in a binary-gcode file.
* bgcodeViewer - Generates a report by turning on all the logging and them attempts to parse the file.I intend the parsers to be as strictly compliant as possible. This is under-going rapid development. Please create issues here, or send me gcode files which expose unimplemented sections.
See [nom](https://crates.io/crates/nom) - "A byte-oriented, zero-copy, parser combinator library"
## Changelog
Between version 0.4 and 0.5 a major performance misconception was unpicked.
A 9.9MByte file is processed 60 times faster. Now in 1.3secs
[ See the assets folder associated with this repository "gear-holder-print-in-place_04n_022mm_pla_mk4_6h49m.bgcode" ]
## Tools
### gcode2obj
Generates obj files.
Pass the gcode file into StdIn - the obj file is sent to StdOut :-
```bash
cd gcode2obj
cargo run --release -- < ./assets/benchy.gcode > benchy.obj
```If a filename is passed in as a command line parameter then a obj file will be dumped to StdOut.
```bash
cd gocode2obj
cargo run --release -- ../assets/X\ 6x6_0.15mm_PLA_MK3S_1h55m.gcode > X.obj
```Which for example can be imported into blender for visualization.


Within blender :-1) This obj has been "Imported".
2) Converted into a "Curve".
3) Finally a circular bevel object has been applied to make the object solid [ A circle to represent a 0.1mm fibre].## gcode2svg
Generate svg files

### How to use
Pass the gcode file into StdIn - the SVG file is sent to StdOut :-
```bash
cd gcode2svg
cargo run --release -- < ./assets/benchy.gcode > benchy.svg
```If a filename is passed in as a command line parameter then a svg file will be dumped to StdOut.
```bash
cd gocode2svg
cargo run --release -- ../assets/X\ 6x6_0.15mm_PLA_MK3S_1h55m.gcode > X.svg
```### gcodeExtractThumbs
Iterates over all the embedded thumbnail block and save the images to disk
```bash
cargo run --release -- ../assets/both\ parts.bgcode
```### bgcodeViewer
Strict checking of binaries. validates blocks checksums, ensures 'block' parameters values are within valid ranges.
Pass the gcode file into StdIn - A summary file is written to StdOut
```rust
cd bgcodeViewer
cargo run --release < ../assets/both\ parts.bgcode > summary.txt
```## Future work
see [TODO](TODO.md)
A Bevy app?