Skip to content

Commit

Permalink
simplification, addition of instruction, ...
Browse files Browse the repository at this point in the history
much code has been simplified and checked for correctness, the instruction `G0` has been added
  • Loading branch information
ludwig-austermann committed Aug 27, 2022
1 parent 406f0a0 commit 2fc9a74
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 250 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "gcodeplot"
version = "0.3.1"
authors = ["ludwig-austermann"]
edition = "2018"
version = "0.4.0"
authors = ["Ludwig Austermann <github.com/ludwig-austermann/gcodeplot>"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
nannou = "0.17.0"
clap = "3.0.0-beta.2"
pest = "2.1.3"
pest_derive = "2.1"
nannou = "0.18"
clap = { version = "3.2", features = ["derive"] }
pest = "2.3"
pest_derive = "2.3"
Binary file removed img/v0.2_screenshot_debugging.png
Binary file not shown.
Binary file added img/v0.4_screenshot_debugging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
*Note that this app purposely supports only a very minimal subset of g-code features, since it is primarily supposed for educational purposes.*

![Screenshot of version 0.2](img/v0.2_screenshot.png)
![Screenshot of debugging features 0.2](img/v0.2_screenshot_debugging.png)
![Screenshot of debugging features 0.4](img/v0.4_screenshot_debugging.png)

*The pictures show a screenshot without debugging features and a zoomed screenshot of debugging features.*

## Description

`gcodeplot` is a simulated plotter of [G-code](http://en.wikipedia.org/wiki/G-code) files. It supports only
- `G28`: **return to home** position
- `G0 X{} Y{}`: **move**, move to `(X,Y)` (from current position) (note that you probably want to use `G1` instead)
- `G1 X{} Y{}`: **linear move**, move directly to `(X,Y)` (from current position)
- `G2 X{} Y{} I{} J{}`: (part-)**circular move in clockwise direction**, move to `(X,Y)` (from current position) along a circle with center in `CURRENTPOS + (I,J)`
- `G3 X{} Y{} I{} J{}`: (part-)**circular move in anticlockwise direction**, move to `(X,Y)` (from current position) along a circle with center in `CURRENTPOS + (I,J)`
Expand All @@ -34,14 +36,15 @@ allows you to transform a file by translation and dilation.
In the graphical app, a few keyboard commands are enabled. To increase a value corresponding to a <kbd>key</kbd>, just press <kbd>key</kbd> and to decrease press <kbd>shift</kbd> + <kbd>key</kbd>. For bigger steps combine these combination with a further <kbd>ctrl</kbd>.

Furthermore, I introduced in Version 0.3.0 the ability to extend existing g-code files. Simply press
- <kbd>0</kbd> for `G0` mode
- <kbd>1</kbd> for `G1` mode
- <kbd>2</kbd> for `G2` mode
- <kbd>3</kbd> for `G3` mode
- <kbd>0</kbd> to exit the modes
- <kbd>esc</kbd> to exit the modes

and choose the coordinate with a left mouse click. One also can now undo and redo these added commands with <kbd>Z</kbd> and <kbd>Y</kbd> and save these changes to a new file with <kbd>S</kbd>. <kbd>P</kbd> changes the penmode and <kbd>H</kbd> returns to to home.

Last but not least, right-clicking prints the mouse coordinates to console.
Last but not least, right-clicking prints the mouse coordinates to console and <kbd>Q</kbd> quits the application.

## Room to improve

Expand All @@ -52,4 +55,5 @@ TODO:
- [ ] more file maniplulation features
- [ ] move in grid support
- [X] draw mode?
- [ ] more debug options, e.g. show coordinates
- [ ] more debug options, e.g. show coordinates
- [ ] autoscale the view, using for instance <kbd>A</kbd>.
9 changes: 5 additions & 4 deletions src/gcode.pest
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ num = @{ int ~ ("." ~ ASCII_DIGIT*)? ~ (^"e" ~ int)? }
int = { ("+" | "-")? ~ ASCII_DIGIT+ }

expr = { cmd? ~ COMMENT? }
cmd = _{ HOME | MOVE | PEN | ARC }
cmd = _{ HOME | LINEARMOVE | MOVE | PEN | ARC }
HOME = { "G28" }
MOVE = { "G1" ~ ((X ~ Y) | (Y ~ X)) }
MOVE = { ("G0" | "G00") ~ ((X ~ Y) | (Y ~ X)) }
LINEARMOVE = { ("G1" | "G01") ~ ((X ~ Y) | (Y ~ X)) }
ARC = { (CLKW | ANTICLKW) ~ (
(X ~ (
(Y ~ ((I ~ J) | (J ~ I))) |
Expand All @@ -24,8 +25,8 @@ ARC = { (CLKW | ANTICLKW) ~ (
(Y ~ ((I ~ X) | (X ~ I)))
))
) }
CLKW = { "G2" }
ANTICLKW = { "G3" }
CLKW = { ("G2" | "G02") }
ANTICLKW = { ("G3" | "G03") }
PEN = { "M280 P0 S" ~ num }

X = { "X" ~ num }
Expand Down
Loading

0 comments on commit 2fc9a74

Please sign in to comment.