Skip to main content

Simple GCode generator

Project description

Wheecode

` Unit Tests

GCode for all

Wheecode is a fork of mecode, designed to simplify GCode generation. It is not a slicer, thus it can not convert CAD models to 3D printer ready code. It simply provides a convenient, human-readable layer just above GCode. If you often find yourself manually writing your own GCode, then wheecode is for you.

Basic Use

To use, simply instantiate the G object and use its methods to trace your desired tool path.

from wheecode import G
g = G()
g.move(10, 10)  # move 10mm in x and 10mm in y
g.arc(x=10, y=5, radius=20, direction='CCW')  # counterclockwise arc with a radius of 20
g.meander(5, 10, spacing=1)  # trace a rectangle meander with 1mm spacing between passes
g.abs_move(x=1, y=1)  # move the tool head to position (1, 1)
g.home()  # move the tool head to the origin (0, 0)

By default wheecode simply prints the generated GCode to stdout. If instead you want to generate a file, you can pass a filename when instantiating the G object.

g = G(outfile='path/to/file.gcode')

NOTE: When using the option direct_write=True or when writing to a file, g.teardown() must be called after all commands are executed. If you are writing to a file, this can be accomplished automatically by using G as a context manager like so:

with G(outfile='file.gcode') as g:
    g.move(10)

When the with block is exited, g.teardown() will be automatically called.

The resulting toolpath can be visualized in 3D using the mayavi or matplotlib package with the view() method:

g = G()
g.meander(10, 10, 1)
g.view()

The graphics backend can be specified when calling the view() method, e.g. g.view('mayavi').

Direct control via serial communication

With the option direct_write=True, a serial connection to the controlled device is established via USB serial at a virtual COM port of the computer and the g-code commands are sent directly to the connected device using a serial communication protocol:

import wheecode
g = wheecode.G(
    direct_write=True, 
    direct_write_mode="serial", 
    printer_port="/dev/tty.usbmodem1411", 
    baudrate=115200
)  # Under MS Windows, use printer_port="COMx" where x has to be replaced by the port number of the virtual COM port the device is connected to according to the device manager.
g.write("M302 S0")  # send g-Code. Here: allow cold extrusion. Danger: Make sure extruder is clean without filament inserted 
g.absolute()  # Absolute positioning mode
g.move(x=10, y=10, z=10, F=500)  # move 10mm in x and 10mm in y and 10mm in z at a feedrate of 500 mm/min
g.retract(10)  # Move extruder motor
g.write("M400")  # IMPORTANT! wait until execution of all commands is finished
g.teardown()  # Disconnect (close serial connection)

All GCode Methods

All methods have detailed docstrings and examples.

  • set_home()
  • reset_home()
  • feed()
  • dwell()
  • home()
  • move()
  • abs_move()
  • arc()
  • abs_arc()
  • rect()
  • meander()
  • clip()
  • triangular_wave()

Matrix Transforms

A wrapper class, GMatrix will run all move and arc commands through a 2D transformation matrix before forwarding them to G.

To use, simply instantiate a GMatrix object instead of a G object:

g = GMatrix()
g.push_matrix()      # save the current transformation matrix on the stack.
g.rotate(math.pi/2)  # rotate our transformation matrix by 90 degrees.
g.move(0, 1)         # same as moves (1,0) before the rotate.
g.pop_matrix()       # revert to the prior transformation matrix.

The transformation matrix is 2D instead of 3D to simplify arc support.

Renaming Axes

When working with a machine that has more than one Z-Axis, it is useful to use the rename_axis() function. Using this function your code can always refer to the vertical axis as 'Z', but you can dynamically rename it.

Installation

The easiest method to install wheecode is with pip:

pip install wheecode

To install from source:

$ git clone https://github.com/xloem/wheecode.git
$ cd wheecode
$ pip install -r requirements.txt
$ python setup.py install

Optional Dependencies

The following dependencies are optional, and are only needed for visualization. An easy way to install them is to use conda.

  • numpy
  • matplotlib
  • vpython
  • mayavi

TODO

  • add pressure box comport to __init__() method
  • build out multi-nozzle support
    • include multi-nozzle support in view method.
  • factor out aerotech specific methods into their own class
  • auto set MFO=100% before each print
  • add ability to read current status of aerotech
    • turn off omnicure after aborted runs
  • add formal sphinx documentation
  • create github page

Credits

This software was originally developed by the Lewis Lab at Harvard University, likely by Jack Minardi, and then forked and added on to by many people and organizations listed in the commit history.

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

wheecode-0.5.0.tar.gz (38.4 kB view details)

Uploaded Source

Built Distribution

wheecode-0.5.0-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file wheecode-0.5.0.tar.gz.

File metadata

  • Download URL: wheecode-0.5.0.tar.gz
  • Upload date:
  • Size: 38.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for wheecode-0.5.0.tar.gz
Algorithm Hash digest
SHA256 8a07854c5feb8f8d6bf947dda811cca0539b6eb42268cff32c1c10d6f7d38c34
MD5 c8a019640e8b380a9741267e9200dda3
BLAKE2b-256 98fe2a05443664d721b227ed538d1f609eab4fd148e53c43084c88a40c705211

See more details on using hashes here.

File details

Details for the file wheecode-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: wheecode-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for wheecode-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c65a4e0c0128ff1bb893d8a414b7587c929e47a2b8b8c28e35d223974f947a8e
MD5 d878966e1a600bef5dd250fb8a2d8e32
BLAKE2b-256 079de47ae264705c895464ae887b198e703b01b7531f16d0de9161a788128cce

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