Skip to content

A (intentionally limitted) simulated 2D-plotter for g-code files.

Notifications You must be signed in to change notification settings

ludwig-austermann/gcodeplot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gcodeplot

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 Screenshot of debugging features 0.4

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

Description

gcodeplot is a simulated plotter of G-code files. It supports only

  • G28: return to home position
  • G0 X{NUM} Y{NUM}: move, move to (X,Y) (from current position) (note that you probably want to use G1 instead)
  • G1 X{NUM} Y{NUM}: linear move, move directly to (X,Y) (from current position)
  • G2 X{NUM} Y{NUM} I{NUM} J{NUM}: (part-)circular move in clockwise direction, move to (X,Y) (from current position) along a circle with center in CURRENTPOS + (I,J)
  • G3 X{NUM} Y{NUM} I{NUM} J{NUM}: (part-)circular move in anticlockwise direction, move to (X,Y) (from current position) along a circle with center in CURRENTPOS + (I,J)
  • M280 P0 S{NUM}: Set the pen as follows, if S>=40 down (which means it can draw) and else up
  • ;{}: comment, which can be put on seperate line or after a regular command

Parsing Abilities

The gcode parser allows for arbitrary many, including zero, spacing characters (' ' & '\t') between instruction name and argument name and between argument name and number expression. It is also allowed to change the order of arguments. For example this is allowed:

G0   X  10  Y  20
G1   Y  10  X  20
G1X20Y50

Furthermore are number expressions treated as 32 bit floats internally and parsed as such, which allows the following expressions:

G1 X 00001 Y 1.000
G1 X 0.1e5 Y 1e-2

Arguments And Features

The application is programmed in rust with the nannou library for displaying and the pest library for parsing. It supports the following command line arguments:

  • INPUT (required): sets the gcode file to plot
  • -d {}, --debug {}: This enables debugging and can take values up to 3. While running, this can be changed with the key D
  • -s {}, --scale {}: This scales the whole view. While running you can access it with the +(might be = on your PC) and - keys
  • -g {}, --gridsize: This describes the gridsize used. While running you can access it with the key G
  • the flag --hot, for hot reloading of the gcode file. Alternatively you can update in the app with R
  • and other arguments as --treshold, --wwidth and -wheight.

It furthermore supports a subcommand transform, which allows you to transform a file by translation and dilation.

Keyboard Commands And Editing Features

In the graphical app, a few keyboard commands are enabled. To increase a value corresponding to a key, just press key and to decrease press shift + key. For bigger steps combine these combination with a further ctrl.

Furthermore, I introduced in Version 0.3.0 the ability to extend existing g-code files. Simply press

  • 0 for G0 mode
  • 1 for G1 mode
  • 2 for G2 mode
  • 3 for G3 mode
  • esc to exit the modes

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

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

Room To Improve

While the app can be used for many purposes, it is in a early development phase. Tests are missing and not everything is programmed the clever way. If you want to improve it feel welcome to contribute.

TODO:

  • better loop management for hot reloading
  • more file maniplulation features
  • move in grid support
  • draw mode?
  • more debug options, e.g. show coordinates
  • autoscale the view, using for instance A.
  • gcode to svg output
  • support R argument:
  • support G90/G91: rel. & abs. coordinates
  • support U{}/V{}: rel. coordinates
  • support G90.1/G91.1: rel. & abs. coordinates for I and J arguments
  • support G68/G69: coordinate rotation
  • support O{}, M98, M99, P{}, M2: to handle subprograms
  • support L
  • support for switching features on and off in a config toml file
  • support for opinionated formating off a file, with options: minimal,