Skip to main content

Generate time dependent boundary conditions from a .gcode file.

Project description

pyGCodeDecode

LOGO

License: MIT PyPI - Version Docu Badge

tests

Repo DOI Paper_DOI

Python Ruff pre-commit

What is this repository for?

For the analysis of GCode, slicers or dedicated analyzer tools, such as Prusa Slicer or gCodeViewer, merely display target process parameters. The actual process velocity however is determined by the firmware of the printer. Velocities are expected to deviate significantly from the target velocity at times of acceleration and deceleration. pyGCodeDecode aims to model the machine's actual behavior and visualize its influence. A visual comparison between the simulated acceleration approach and the raw GCode target velocity is shown below.

comparison

This package reads the target trajectory firmware settings changes from a GCode file. Subsequently, it simulates a motion planner with acceleration and jerk or junction control respectively. The more accurate modeling is achieved by replicating grbl's and its derivatives' firmware-specific movement planner solutions, such as "Classic Jerk" and "Junction Deviation", as an interpretation for Jerk. The simulation result is a description of the nozzle and extrusion axis position and velocity over time and is easily accessible for further analysis. For example it can be used to generate time dependent boundary conditions, needed in additive manufacturing simulations for the Fused Filament Fabrication (FFF) process. The package includes 3D plotting functions, so it can be used to visualize local velocities before printing to improve your process understanding.

Install pyGCodeDecode

It is recommended that you first create a virtual Python-environment, e.g. using the venv-module built into Python. You can clone the repository and run

pip install .

from inside the root directory. Alternatively you can simply install from PyPI:

pip install pyGCodeDecode

If you plan to contribute to the development, install in development mode and with the additional dependencies:

pip install -e .[DEVELOPER]

You may want to verify the installation and version. Inside your environment, just run:

python -c "import pyGCodeDecode
print(pyGCodeDecode.__version__)"

This should return the correct version.

Running the CLI

pyGCD comes with a simplistic CLI to quickly run the provided examples or plot some G-Code without writing a script first. If you want to see something quickly, activate the venv where pyGCD is installed and run:

pygcd run_example brace

You can also run and plot your own G-Code with:

pygcd plot --gcode <PATH>

Creating a script using pyGCD

Example simulations are provided in ./examples/ and can be modified to suit your needs. If you want to start from scratch, the following instructions will help you setup and run a simulation.

Define your printer defaults in a .yaml file

For example, the definition may look like this: ./pyGCodeDecode/data/default_printer_presets.yaml:

prusa_mini:
        # general properties
        nozzle_diam: 0.4
        filament_diam: 1.75
        # default settings
        p_vel: 35
        p_acc: 1250
        jerk: 8
        # axis max speeds
        vX: 180
        vY: 180
        vZ: 12
        vE: 80
        firmware: prusa

The default settings usually are machine specific and often can be read from the printer using a serial connection by sending a GCode command. You can use M503 for Marlin, Prusa and some other firmwares.

Use pyGCD to run a GCode Simulation

An easy way to use pyGCD is by creating a .py file to set up and run the simulation.

  1. Import the package and modules you want to use:
from pyGCodeDecode import gcode_interpreter
  1. Load your setup .yaml file through:
setup = gcode_interpreter.setup(filename=r"./pyGCodeDecode/data/default_printer_presets.yaml", printer="prusa_mini")
  1. You can optionally set or modify custom properties after loading the setup:
setup.set_property({"layer_cue": "LAYER_CHANGE"})
  1. Finally, run the simulation by providing a GCode and passing the setup defined before:
simulation = gcode_interpreter.simulation(filename=r"example\example.gcode", initial_machine_setup=setup)

Access the Results

The simulation object contains the simulation results, you can access them through various methods:

Get the individual axis values (position and velocity) at a certain time (e.g. after 2.6 s) to use it in further simulation by:

simulation.get_values(t=2.6)

You can visualize the GCode by plotting it in 3D:

from pyGCodeDecode.plotter import plot_3d
plot_3d(simulation)

pyGCD can also be used to create files defining an event series for ABAQUS simulations.

from pyGCodeDecode.abaqus_file_generator import generate_abaqus_event_series

generate_abaqus_event_series(
        simulation=simulation,
        filepath="path/to/event_series.csv"
)

For more in depth information have a look into the documentation.

Supported GCode commands

Fully supported commands:

"G0": {"E": None, "X": None, "Y": None, "Z": None, "F": None},  # non extrusion move
"G1": {"E": None, "X": None, "Y": None, "Z": None, "F": None},  # extrusion move
"G4": {"P": None, "S": None},  # Dwell
"M82": None,  # E absolute
"M83": None,  # E relative
"G20": None,  # inches
"G21": None,  # millimeters
"G90": None,  # absolute positioning
"G91": None,  # relative positioning
"G92": {"E": None, "X": None, "Y": None, "Z": None},  # set position
";": None,  # comment

Only partially supported commands:

"M203": {"E": None, "X": None, "Y": None, "Z": None},  # max feedrate *read only
"M204": {"P": None, "R": None, "S": None, "T": None},  # starting acceleration *P only
"M205": {"E": None, "J": None, "S": None, "X": None, "Y": None, "Z": None},  # advanced settings *X only
"G10": {"S": None}, # read only
"G11": None, # read only

Known unsupported commands that may cause issues:

"G2" : {-}, # clockwise arc/circle move, please disable this command in your slicer's settings
"G3" : {-}, # counter-clockwise arc/circle move, please disable this command in your slicer's settings

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygcodedecode-1.5.0.tar.gz (4.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygcodedecode-1.5.0-py3-none-any.whl (4.2 MB view details)

Uploaded Python 3

File details

Details for the file pygcodedecode-1.5.0.tar.gz.

File metadata

  • Download URL: pygcodedecode-1.5.0.tar.gz
  • Upload date:
  • Size: 4.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pygcodedecode-1.5.0.tar.gz
Algorithm Hash digest
SHA256 4fc276050915dbe326b5772a5f4c95e42187d46fadd344b3c2c5c732bcbed6a3
MD5 b373eacdd997dd131c183ffbd5632017
BLAKE2b-256 087890f157232b6eb94fbc72d1c0b076f4a6e0eced4f8beaff345ce18abf2ff3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygcodedecode-1.5.0.tar.gz:

Publisher: publish_to_pypi.yaml on FAST-LB/pyGCodeDecode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygcodedecode-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: pygcodedecode-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pygcodedecode-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59cc64cbcfdb4523f4cadeec542a7e6e7bfe152ecb3804b81960c5c222686f25
MD5 4439c8c9084ccf2305dcda49192ebf18
BLAKE2b-256 3d4f9580b1ef0815929c4404885ca7c69ed2a8504ae6a73a9b20e6cba6b7cb01

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygcodedecode-1.5.0-py3-none-any.whl:

Publisher: publish_to_pypi.yaml on FAST-LB/pyGCodeDecode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page