Skip to content

Commit f436c0c

Browse files
committed
Initial commit
0 parents  commit f436c0c

19 files changed

+12205
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/target
2+
kcov*
3+
**/*.swp
4+
**/*.rs.bk
5+
tags
6+
**/*.rustfmt

.travis.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
language: rust
2+
sudo: true
3+
4+
addons:
5+
apt:
6+
update: true
7+
packages:
8+
- libcurl4-openssl-dev
9+
- libiberty-dev
10+
- libelf-dev
11+
- libdw-dev
12+
- binutils-dev
13+
- pkg-config
14+
- cmake
15+
- gcc
16+
- g++
17+
- jq
18+
19+
cache: cargo
20+
dist: trusty
21+
os:
22+
- linux
23+
- osx
24+
25+
# Run builds for all the supported trains
26+
rust:
27+
- nightly
28+
- beta
29+
- stable
30+
31+
# Add clippy
32+
before_script:
33+
- cargo install cargo-update || echo "cargo-update already installed"
34+
- cargo install cargo-travis || echo "cargo-travis already installed"
35+
- cargo install-update -a # update outdated cached binaries
36+
- if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then rustup component add clippy-preview --toolchain=nightly; fi
37+
- |
38+
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then
39+
cargo install cargo-kcov || echo "cargo-kcov already installed"
40+
cargo kcov --print-install-kcov-sh | bash
41+
fi
42+
43+
# The main build
44+
script:
45+
- cargo build
46+
- cargo test
47+
- if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then cargo clippy; fi
48+
- |
49+
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then
50+
cargo clean && cargo kcov
51+
fi
52+
53+
after_success:
54+
# Coverage report
55+
- |
56+
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then
57+
bash <(curl -s https://codecov.io/bash) &&
58+
echo "Uploaded code coverage"
59+
fi

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
### Added
9+
- Travis CI build script.
10+
- GCode example file.
11+
- This change log.
12+
- Readme.md
13+
- no-std friendly implementation
14+
15+
### Changed
16+
17+
[Unreleased]: https://github.com/ithinuel/gcode-rs/tree/no_std

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "gcode"
3+
version = "0.1.0"
4+
authors = ["Wilfried Chauveau <[email protected]>"]
5+
license = "MIT License"
6+
edition = "2018"
7+
# documentation = "..."
8+
# homepage = "..."
9+
repository = "https://github.com/ithinuel/gcode-rs"
10+
11+
[features]
12+
default = ["parse-expressions", "parse-parameters", "parse-comments"]
13+
no_std = []
14+
parse-expressions = []
15+
parse-parameters = []
16+
parse-comments = []
17+
# extended:
18+
# Support for 3d printer flavor
19+
# - no word restriction
20+
# - semi-colon comments
21+
extended = []
22+
23+
24+
# [dependencies.nom]
25+
# version = "^4"
26+
# default-features = false
27+
# features = []

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Wilfried Chauveau
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Readme.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# GCode Parser
2+
3+
This crate aims at providing a gcode parser to the rusty printer project (and other if it can fit).
4+
5+
## Features
6+
7+
- `parse-expressions` : enables parsing of expressions
8+
- `parse-comments` : generates an event when a comment (or a message) is parsed.
9+
- `parse-parameters` : enables parsing of parameters
10+
- `no_std` : Adds appropriate reference to `core` & `alloc`
11+
- `extended` : enables semi-colon comments and removes word letter restriction.
12+
13+
By default all three `parse-*` features are enabled.

assets/example1.gcode

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
(this program mills “Hello world” between X=0 and X=81 millimeters)
2+
n0010 g21 g0 x0 y0 z50 (top of part should be on XY plane)
3+
n0020 t1 m6 m3 f20 s4000 (use an engraver or small ball-nose endmill)
4+
n0030 g0 x0 y0 z2
5+
n0040 g1 z-0.5 (start H)
6+
n0050 y10
7+
n0060 g0 z2
8+
n0070 y5
9+
n0080 g1 z-0.5
10+
n0090 x 7
11+
n0100 g0 z2
12+
n0110 y0
13+
n0120 g1 z-0.5
14+
n0130 y10
15+
n0140 g0 z2
16+
n0150 x11 y2.5
17+
n0160 g1 z-0.5 (start e)
18+
n0170 x16
19+
n0190 g3 x13.5 y0 i-2.5
20+
n0200 g1 x16
21+
n0210 g0 z2
22+
n0220 x20 y0
23+
n0230 g1 z-0.5 (start l)
24+
n0240 y9
25+
n0250 g0 z2
26+
n0260 x26
27+
n0270 g1 z-0.5 (start l)
28+
n0280 y0
29+
n0290 g0 z2
30+
n0300 x32.5
31+
n0310 g1 z-0.5 (start o)
32+
n0320 g2 x32.5 j2.5
33+
n0330 g0 z2
34+
n0340 x45 y5
35+
n0350 g1 z-0.5 (start w)
36+
n0360 x47 y0
37+
n0370 x48.5 y3
38+
n0380 x50 y0
39+
n0390 x52 y5
40+
n0400 g0 z2
41+
n0410 x57.5 y0
42+
n0420 g1 z-0.5 (start o)
43+
n0430 g2 x57.5 j2.5
44+
n0440 g0 z2
45+
n0450 x64
46+
n0460 g1 z-0.5 (start r)
47+
n0470 y5
48+
n0480 y4
49+
n0490 g2 x69 r4
50+
n0500 g0 z2
51+
n0510 x73 y0
52+
n0520 g1 z-0.5 (start l)
53+
n0530 y9
54+
n0540 g0 z2
55+
n0550 x81
56+
n0560 g1 z-0.5 (start d)
57+
n0570 y0
58+
n0580 x79.5
59+
n0590 g2 j2.5 y5
60+
n0600 g1 x81
61+
n0610 g0 z50
62+
n0620 m2

assets/example2.gcode

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
n0010 g21 g1 x3 f20 (expression test)
2+
n0020 x [1 + 2] (x should be 3)
3+
n0030 x [1 - 2] (x should be -1)
4+
n0040 x [1 --3] (x should be 4)
5+
n0050 x [2/5] (x should be 0.40)
6+
n0060 x [3.0 * 5] (x should be 15)
7+
n0070 x [0 OR 0] (x should be 0)
8+
n0080 x [0 OR 1] (x should be 1)
9+
n0090 x [2 or 2] (x should be 1)
10+
n0100 x [0 AND 0] (x should be 0)
11+
n0110 x [0 AND 1] (x should be 0)
12+
n0120 x [2 and 2] (x should be 1)
13+
n0130 x [0 XOR 0] (x should be 0)
14+
n0140 x [0 XOR 1] (x should be 1)
15+
n0150 x [2 xor 2] (x should be 0)
16+
n0160 x [15 MOD 4.0] (x should be 3)
17+
n0170 x [1 + 2 * 3 - 4 / 5] (x should be 6.2)
18+
n0180 x sin[30] (x should be 0.5)
19+
n0190 x cos[0.0] (x should be 1.0)
20+
n0200 x tan[60.0] (x should be 1.7321)
21+
n0210 x sqrt[3] (x should be 1.7321)
22+
n0220 x atan[1.7321]/[1.0] (x should be 60.0)
23+
n0230 x asin[1.0] (x should be 90.0)
24+
n0240 x acos[0.707107] (x should be 45.0000)
25+
n0250 x abs[20.0] (x should be 20)
26+
n0260 x abs[-1.23] (x should be 1.23)
27+
n0270 x round[-0.499] (x should be 0)
28+
n0280 x round[-0.5001] (x should be -1.0)
29+
n0290 x round[2.444] (x should be 2)
30+
n0300 x round[9.975] (x should be 10)
31+
n0310 x fix[-0.499] (x should be -1.0)
32+
n0320 x fix[-0.5001] (x should be -1.0)
33+
n0330 x fix[2.444] (x should be 2)
34+
n0340 x fix[9.975] (x should be 9)
35+
n0350 x fup[-0.499] (x should be 0.0)
36+
n0360 x fup[-0.5001] (x should be 0.0)
37+
n0370 x fup[2.444] (x should be 3)
38+
n0380 x fup[9.975] (x should be 10)
39+
n0390 x exp[2.3026] (x should be 10)
40+
n0400 x ln[10.0] (x should be 2.3026)
41+
n0410 x [2 ** 3.0] #1=2.0 (x should be 8.0)
42+
n0420 ##1 = 0.375 (#1 is 2, so parameter 2 is set to 0.375)
43+
n0430 x #2 (x should be 0.375) #3=7.0
44+
n0440 #3=5.0 x #3 (parameters set in parallel, so x should be 7, not 5)
45+
n0450 x #3 #3=1.1 (parameters set in parallel, so x should be 5, not 1.1)
46+
n0460 x [2 + asin[1/2.1+-0.345] / [atan[fix[4.4] * 2.1 * sqrt[16.8]] /[-18]]**2]
47+
n0470 x sqrt[3**2 + 4**2] (x should be 5.0)
48+
n0480 m2

assets/example3.gcode

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
n0010 g20 (cycle test)
2+
n0020 g17 g43 h1 m3 s1234 f16 (start in XY-plane)
3+
n0030 g81 x3 y4 r0.2 z-1.1
4+
n0040 x1 y0 r0 g91 l3 (three more g81’s an inch apart)
5+
n0050 y-2 r0.1 (one more g81)
6+
n0060 g82 g90 x4 y5 r0.2 z-1.1 p0.6
7+
n0070 x2 z-3.0 (one more G82)
8+
n0080 g91 x-2 y2 r0 l4 (four more g82’s)
9+
n0090 g83 g90 x5 y6 r0.2 z-1.1 q0.21
10+
n0100 g84 x6 y7 r0.2 z-1.1
11+
n0110 g85 x7 y8 r0.2 z-1.1
12+
n0120 g86 x8 y9 r0.2 z-1.1 p902.61
13+
n0130 g87 x9 y10 r0.2 z-1.1 i0.231 j-0 k-3
14+
n0135 g91 x1 r0.2 z-1.1 i0.231 j-0 k-3
15+
n0140 g88 x10 y11 r0.2 z-1.1 p0.3333
16+
n0150 g89 x11 y12 r0.2 z-1.1 p1.272
17+
n0160 m4 (run spindle counterclockwise)
18+
n0170 g86 x8 y9 r0.2 z-1.1 p902.61
19+
n0180 g87 x9 y10 r0.2 z-1.1 i0.231 j-0 k-3
20+
n0190 g88 x10 y11 r0.2 z-1.1 p0.3333
21+
22+
n0220 g18 m3 (now run all cycles in the XZ-plane)
23+
n0230 g81 z3 x4 r0.2 y-1.1
24+
n0240 g91 z1 x0 r0 l3
25+
n0260 g82 g90 z4 x5 r0.2 y-1.1 p0.6
26+
n0280 g91 z-2 x2 r0 l4
27+
n0290 g83 g90 z5 x6 r0.2 y-1.1 q0.21
28+
n0300 g84 z6 x7 r0.2 y-1.1
29+
n0310 g85 z7 x8 r0.2 y-1.1
30+
n0320 g86 z8 x9 r0.2 y-1.1 p902.61
31+
n0330 g87 z9 x10 r0.2 y-1.1 k0.231 i-0 j-3
32+
n0335 g91 z1 r0.2 y-1.1 k0.231 i-0 j-3
33+
n0340 g88 z10 x11 r0.2 y-1.1 p0.3333
34+
n0350 g89 z11 x12 r0.2 y-1.1 p1.272
35+
36+
n0420 g19 (now run all cycles in the YZ-plane)
37+
n0430 g81 y3 z4 r0.2 x-1.1
38+
n0440 g91 y1 z0 r0 l3
39+
n0460 g82 g90 y4 z5 r0.2 x-1.1 p0.6
40+
n0480 g91 y-2 z2 r0 l4
41+
n0490 g83 g90 y5 z6 r0.2 x-1.1 q0.21
42+
n0500 g84 y6 z7 r0.2 x-1.1
43+
n0510 g85 y7 z8 r0.2 x-1.1
44+
n0520 g86 y8 z9 r0.2 x-1.1 p902.61
45+
n0530 g87 y9 z10 r0.2 x-1.1 j0.231 k-0 i-3
46+
n0535 g91 y1 r0.2 x-1.1 j0.231 k-0 i-3
47+
n0540 g88 y10 z11 r0.2 x-1.1 p0.3333
48+
n0550 g89 y11 z12 r0.2 x-1.1 p1.272
49+
50+
n1000 m2 (the end)

0 commit comments

Comments
 (0)