Code Monkey home page Code Monkey logo

mecode's Introduction

Mecode

Build Status

GCode for all

Mecode is 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 mecode is for you.

Basic Use

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

from mecode 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 mecode simply prints the generated GCode to stdout. If instead you want to generate a file, you can pass a filename and turn off the printing when instantiating the G object.

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

NOTE: 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('matplotlib'). mayavi is the default graphics backend.

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 mecode is with pip:

sudo pip install mecode

To install from source:

$ git clone https://github.com/jminardi/mecode.git
$ cd mecode
$ 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 Canopy or conda.

  • numpy
  • mayavi
  • matplotlib

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

Credits

This software was developed by the Lewis Lab at Harvard University.

mecode's People

Contributors

jminardi avatar sjkelly avatar razeh avatar jonvoxel8 avatar alexvalentine avatar monkeypants avatar leethomason avatar pizzyflavin avatar sean-v8 avatar fake-name avatar grinner avatar peets avatar

Watchers

James Cloos avatar SinoEmbedded avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.