Skip to main content

Generate time dependent boundary conditions from a .gcode file.

Project description

pyGCodeDecode

LOGO

License: MIT tests GitHub Release

Python Black isort 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.

Workflow

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: marlin_jerk

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
    
  2. Load your setup .yaml file through:

     setup = gcode_interpreter.setup(filename=r"e./pygcodedecode/data/default_printer_presets.yaml")
    
  3. Select your printer from the setup by name:

     setup.select_printer("prusa_mini")
    
  4. You can optionally set or modify custom properties after loading the setup:

     setup.set_property({"layer_cue": "LAYER_CHANGE"})
    
  5. 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:

    simulation.plot_3d()

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

    generate_abaqus_event_series(
            simulation=simulation,
            filpath="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,  # Milimeters
    "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" / "G3: {-} Arc/Circle move, please disable this command in your Slicer 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-0.2.2.tar.gz (36.6 kB view details)

Uploaded Source

Built Distribution

pyGCodeDecode-0.2.2-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pygcodedecode-0.2.2.tar.gz
  • Upload date:
  • Size: 36.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for pygcodedecode-0.2.2.tar.gz
Algorithm Hash digest
SHA256 8f9a7f60ac5787fa342a4a6aad00dd550d7b826aa197b7076047644285ad1c3f
MD5 3dc32319bd8cae27f800b07387608096
BLAKE2b-256 48ab728f0d532c3e41a6253844755c007a9c2cc3c0e0a13cc9a114e541d131ac

See more details on using hashes here.

File details

Details for the file pyGCodeDecode-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyGCodeDecode-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 635aab82143253a9a7230ee38aa460282dfeb95ba3c79acccd948ab79ce4a78e
MD5 a735833689ca715f0967df3b1079e368
BLAKE2b-256 c581c5aa136c89b846d22fe39c72356be558bbd3564c6dd5225b47fccf349f77

See more details on using hashes here.

Supported by

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