Coder Social home page Coder Social 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 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 mecode
g = mecode.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 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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mecode's Issues

ImportError: cannot import name 'G' - (python3.5)

I am trying out mecode for the first time and using python3.5 for this. I have followed the install instructions corresponding to source install in the readme file. After the install I tried the following line in the command line on Ubuntu 16.04, I get the following error. I read an earlier issue where a python 3.4 compatibility was talked about, but has there been any update in this direction since? Or is mecode not compatible with python3 generally?

~$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mecode import G
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'G'

Absolute mode isn't sticky, leading to continuous relative/absolute transitions

I'm doing some gcode generation that uses entirely absolute moves.

Every single move winds up surrounded by a G90/G91 pair:


G90 ;absolute
G1 X5.000000 Y5.000000 Z5.600000
G91 ;relative
G90 ;absolute
G1 X5.750000 Y5.000000 Z5.600000
G91 ;relative
G90 ;absolute
G0 X5.750000 Y5.000000 Z16.000000
G91 ;relative
G1 F3.0
G90 ;absolute
G0 X6.250000 Y6.000000 Z16.000000
G91 ;relative
G90 ;absolute
G0 Y6.000000 Z5.750000
G91 ;relative
G90 ;absolute
G0 X6.250000 Y6.000000 Z5.750000
G91 ;relative
G90 ;absolute
G1 X6.000000 Y6.000000 Z5.750000
G91 ;relative

Looking at the code, this seems to be because nothing can ever set the gcode writer to absolute mode other then an explicit call to absolute().

It seems to me that if you call an absolute move call, it should set the state to absolute and leave it there, until any call to a relative motion function.

Meander doesn't work with new rename_axis command

In [1]: from mecode import G

In [2]: g = G()
G91

In [3]: g.rename_axis(z='A')

In [4]: g.meander(10,10,1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-c5f81a8c0d8a> in <module>()
----> 1 g.meander(10,10,1)

/Users/jack/code/mine/mecode/mecode/main.pyc in meander(self, x, y, spacing, start, orientation, tail)
    533         self.relative()
    534         for _ in range(int(passes)):
--> 535             self.move(**{major_name: (sign * major)})
    536             self.move(**{minor_name: spacing})
    537             sign = -1 * sign

/Users/jack/code/mine/mecode/mecode/main.pyc in move(self, x, y, z, **kwargs)
    289 
    290         """
--> 291         self._update_current_position(x=x, y=y, z=z, **kwargs)
    292 
    293         args = self._format_args(x, y, z, **kwargs)

/Users/jack/code/mine/mecode/mecode/main.pyc in _update_current_position(self, mode, x, y, z, **kwargs)
    720                 self.current_position['z'] += z
    721             for dimention, delta in kwargs.items():
--> 722                 self.current_position[dimention] += delta
    723         else:
    724             if x is not None:

TypeError: unsupported operand type(s) for +=: 'float' and 'NoneType'

Python 3 Compatibility

I'd like to be able to use Python3. The line below typically helps bridge between Python 2 and Python 3.

from __future__ import absolute_import, division, print_function, unicode_literals

it also seems Mayavi does not work with Python 3 yet, see enthought/mayavi#84.

Will this break anything on the windows computers?

real time control using mecode.G(direct_write=True, direct_write_mode="serial") with fix

Steps to reproduce issue

  1. connect your computer (via USB2.0) to a controller board featuring a Microchip Atmega AVR microcontroller that is designed to reset upon serial connection and that runs marlin firmware.
  2. Run a Python3 script (I use the Python 3.7 interpreter CPython under MS Windows 10 64 bit) which contains a mecode.G(direct_write=True) command, e.g. listing 1:
import mecode
g = mecode.G(direct_write=True, direct_write_mode="serial", printer_port="COM3", baudrate=115200)   # realtime communication via serial communication at port COMx (with x=3) under MS Windows. See https://github.com/jminardi/mecode/blob/master/mecode/main.py .
g.write("M302 S0")   # send g-Code. Here: allow cold extrusion. Danger: Make sure extruder is clean without filament inserted 
g.move(10, 10, 10)   # move 10mm in x and 10mm in y and 10mm in z
g.retract(10)   # move extruder motor

Expected behaviour:

  • I expected that all stepper motors would move
  • I would like to find documentation on how to create a socket and get its port number in order to use it with mecode.G(direct_write=True) as an alternative

Observed behaviour:

  • Missing documentation on how to use mecode.G(direct_write=True)
  • console output: G91 and some Error
  • controller board resets, but no motor movement.

Possible Solution:
Use my fork of mecode which provides fixes (see branch serial_fix)
and add the following lines of code after the last command of the Python script that communicates with the controller board (e.g. append to listing 1, see above):

import time
time.sleep(12)

If someone confirms my issues I can create a pull request

grbl support

The Printer class works with a printer running on a Marlin firmware (I guess). How can support for the grbl be added ?

A tryout of the following code

import mecode

g = mecode.G(
    direct_write=True,
    direct_write_mode="serial",
    printer_port="/dev/ttyACM0",
    baudrate=115200
)
g.write("$H")
g.move(x=10, y=10)
g.teardown()

...returns G91 ;relative in the terminal before freezing.

KeyboardInterrupt returns this:

^CTraceback (most recent call last):
  File "move.py", line 7, in <module>
    baudrate=115200
  File "/home/me/.local/miniconda3/envs/mecode_env/lib/python3.7/site-packages/mecode/main.py", line 238, in __init__
    self.setup()
  File "/home/me/.local/miniconda3/envs/mecode_env/lib/python3.7/site-packages/mecode/main.py", line 337, in setup
    self.write('G91 {}relative'.format(self.comment_char))
  File "/home/me/.local/miniconda3/envs/mecode_env/lib/python3.7/site-packages/mecode/main.py", line 981, in write
    self._p.connect()
  File "/home/me/.local/miniconda3/envs/mecode_env/lib/python3.7/site-packages/mecode/printer.py", line 151, in connect
    sleep(0.01)  # wait until the start message is recieved.
KeyboardInterrupt

Thx for hints and help !

P.S. This script from the grbl repo could maybe hold the solution.

Passed file handle is closed on exit.

Basically, I want to not print to stdout, and not have a actual file.

The correct way to do this is to use a stringio file-like-object:

	sbuf = StringIO.StringIO()
	sbuf.mode = "w"
	with mecode.G(outfile=sbuf, print_lines=False) as g:
		pass

	ret = sbuf.getvalue()

This fails with:

Traceback (most recent call last):
  File "scan_gcode_gen.py", line 154, in <module>
    scan_generate(**pla)
  File "scan_gcode_gen.py", line 112, in scan_generate
    return generate_plane(**kwargs)
  File "scan_gcode_gen.py", line 44, in generate_plane
    ret = sbuf.getvalue()
  File "/usr/lib/python2.7/StringIO.py", line 269, in getvalue
    _complain_ifclosed(self.closed)
  File "/usr/lib/python2.7/StringIO.py", line 40, in _complain_ifclosed
    raise ValueError, "I/O operation on closed file"
ValueError: I/O operation on closed file

Basically, if the user passes in a file handle, it should not be closed by the library.

G.view() does not work with arcs

Using the 'Basic Use' code in main.py, appended with a g.view(), the arc doesn't seem to be working correctly; instead of an arc, it just makes a straight line. I'm not sure if I am using it incorrectly or if it is working incorrectly.

image

Also:
g.arc(x=10, y=5, radius=20, direction='CCW') # counterclockwise arc with a radius of 5
The radius parameter is set to 20 but the comment says otherwise. This is in the 'Basic Use' code

Some error using the library on python 3.8.2

mecode/main.py:1067: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if self.x_axis is not 'X' and x is not None:
mecode/main.py:1069: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if self.y_axis is not 'Y' and y is not None:
mecode/main.py:1071: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if self.z_axis is not 'Z' and z is not None:

I have to substitute the is not with != for python 3.8.2

Regards

Carlo D.

Memory leak in serial mode

The following loop that simply moves back and forth will slowly consume more and more memory, presumably until it crashes.

g = G(direct_write_mode='serial')
while True:
    g.move(10, 0)
    g.move(-10, 0)

The problem is that the Printer class is storing every line ever sent in _buffer and doesn't clear it out until disconnecting.

Outfile fails on file-like objects


	sbuf = StringIO.StringIO()
	with mecode.G(outfile=sbuf, print_lines=False) as g:
		pass

This fails:

Traceback (most recent call last):
  File "scan_gcode_gen.py", line 154, in <module>
    scan_generate(**pla)
  File "scan_gcode_gen.py", line 112, in scan_generate
    return generate_plane(**kwargs)
  File "scan_gcode_gen.py", line 41, in generate_plane
    with mecode.G(outfile=sbuf, print_lines=False) as g:
  File "/usr/local/lib/python2.7/dist-packages/mecode/main.py", line 202, in __init__
    self.setup()
  File "/usr/local/lib/python2.7/dist-packages/mecode/main.py", line 298, in setup
    self._write_header()
  File "/usr/local/lib/python2.7/dist-packages/mecode/main.py", line 927, in _write_header
    self._write_out(lines=fd.readlines())
  File "/usr/local/lib/python2.7/dist-packages/mecode/main.py", line 906, in _write_out
    self._write_out(line)
  File "/usr/local/lib/python2.7/dist-packages/mecode/main.py", line 909, in _write_out
    if 'b' in self.out_fd.mode:  # encode the string to binary if needed
AttributeError: StringIO instance has no attribute 'mode'

Basically, the mode attribute is not a part of the required interface for file-like objects, and you can't rely on it being present.

The proper solution here is obviously to switch to python 3, because it explicitly fixes issues like this.

For the moment, just probing with hasattr() should be a decent work-around.

Hexagonal Meander

It would be great to build an infill pattern of regular hexagons that would be fully parameterized such that hexagon size and overall pattern footprint could easily be tailored.

Script with mecode.G(direct_write=True, direct_writemode='serial') stops printer before print finished

With a longer mecode script than the example script I gave in issue #66 , the printer is stopped before the print is finished.

Steps to reproduce:

  1. Connect your computer (via USB2.0) to a controller board that runs marlin firmware.
  2. Note the USB serial port the printer is connected to (in my case COM3
  3. Run a Python script with the following content :
import mecode
import time

g = mecode.G(direct_write=True, direct_write_mode="serial", printer_port="COM3", baudrate=115200, print_lines=False)
g.write("M302 S0")   # send g-Code. Here: allow cold extrusion. Danger: Make sure extruder is clean without filament inserted 
g.write("G28")
g.absolute()
g.abs_move(x=10, y=10, z=200)   # move 10mm in x and 10mm in y and 200mm in z. This takes more than 12 sec
g.retract(10)   # move extruder motor
time.sleep(12) # wait 12 sec

Expected behaviour:
Printer should be stopped only after all commands were executed completely.

Actually observed behaviour:
Printer gets stopped in the middle of the print, after the time specified in the last line of the above Python script (12 sec).

Workaround:
change the last line of the above Python script from time.sleep(12) to:

time.sleep(999)

However, this blocks the serial connection for a long time, even if the print is finished earlier. Any better ideas?

"python setup.py install" errors out (Python 3.4)

running install
running bdist_egg
running egg_info
creating mecode.egg-info
writing top-level names to mecode.egg-info\top_level.txt
writing dependency_links to mecode.egg-info\dependency_links.txt
writing mecode.egg-info\PKG-INFO
writing manifest file 'mecode.egg-info\SOURCES.txt'
reading manifest file 'mecode.egg-info\SOURCES.txt'
writing manifest file 'mecode.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\mecode
copying mecode\main.py -> build\lib\mecode
copying mecode\matrix.py -> build\lib\mecode
copying mecode\printer.py -> build\lib\mecode
copying mecode\profilometer_parse.py -> build\lib\mecode
copying mecode\utils.py -> build\lib\mecode
copying mecode__init__.py -> build\lib\mecode
creating build\lib\mecode\devices
copying mecode\devices\base_serial_device.py -> build\lib\mecode\devices
copying mecode\devices\efd_pressure_box.py -> build\lib\mecode\devices
copying mecode\devices\keyence_line_scanner.py -> build\lib\mecode\devices
copying mecode\devices\keyence_micrometer.py -> build\lib\mecode\devices
copying mecode\devices\keyence_profilometer.py -> build\lib\mecode\devices
copying mecode\devices__init__.py -> build\lib\mecode\devices
creating build\bdist.win32
creating build\bdist.win32\egg
creating build\bdist.win32\egg\mecode
creating build\bdist.win32\egg\mecode\devices
copying build\lib\mecode\devices\base_serial_device.py -> build\bdist.win32\egg
mecode\devices
copying build\lib\mecode\devices\efd_pressure_box.py -> build\bdist.win32\egg\me
code\devices
copying build\lib\mecode\devices\keyence_line_scanner.py -> build\bdist.win32\eg
g\mecode\devices
copying build\lib\mecode\devices\keyence_micrometer.py -> build\bdist.win32\egg
mecode\devices
copying build\lib\mecode\devices\keyence_profilometer.py -> build\bdist.win32\eg
g\mecode\devices
copying build\lib\mecode\devices__init__.py -> build\bdist.win32\egg\mecode\dev
ices
copying build\lib\mecode\main.py -> build\bdist.win32\egg\mecode
copying build\lib\mecode\matrix.py -> build\bdist.win32\egg\mecode
copying build\lib\mecode\printer.py -> build\bdist.win32\egg\mecode
copying build\lib\mecode\profilometer_parse.py -> build\bdist.win32\egg\mecode
copying build\lib\mecode\utils.py -> build\bdist.win32\egg\mecode
copying build\lib\mecode__init__.py -> build\bdist.win32\egg\mecode
byte-compiling build\bdist.win32\egg\mecode\devices\base_serial_device.py to bas
e_serial_device.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode\devices\efd_pressure_box.py to efd_p
ressure_box.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode\devices\keyence_line_scanner.py to k
eyence_line_scanner.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode\devices\keyence_micrometer.py to key
ence_micrometer.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode\devices\keyence_profilometer.py to k
eyence_profilometer.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode\devices__init__.py to init.cpyt
hon-34.pyc
byte-compiling build\bdist.win32\egg\mecode\main.py to main.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode\matrix.py to matrix.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode\printer.py to printer.cpython-34.pyc

byte-compiling build\bdist.win32\egg\mecode\profilometer_parse.py to profilomete
r_parse.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode\utils.py to utils.cpython-34.pyc
byte-compiling build\bdist.win32\egg\mecode__init__.py to init.cpython-34.p
yc
installing package data to build\bdist.win32\egg
running install_data
Traceback (most recent call last):
File "setup.py", line 18, in
maintainer_email='[email protected]',
File "C:\Python34\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\setuptools\command\install.py", line 67, i
n run
self.do_egg_install()
File "C:\Python34\lib\site-packages\setuptools\command\install.py", line 109,
in do_egg_install
self.run_command('bdist_egg')
File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\setuptools\command\bdist_egg.py", line 181
, in run
self.do_install_data()
File "C:\Python34\lib\site-packages\setuptools\command\bdist_egg.py", line 133
, in do_install_data
self.call_command('install_data', force=0, root=None)
File "C:\Python34\lib\site-packages\setuptools\command\bdist_egg.py", line 147
, in call_command
self.run_command(cmdname)
File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\distutils\command\install_data.py", line 56, in run
dir = convert_path(f[0])
File "C:\Python34\lib\distutils\util.py", line 127, in convert_path
raise ValueError("path '%s' cannot end with '/'" % pathname)
ValueError: path './mecode/' cannot end with '/'

README.md typo

The README.md has this line:

g.arc(x=10, y=5, radius=20, direction='CCW') # counterclockwise arc with a radius of 5

Isn't that a counterclockwise arc, ending at x=10, y=5 with a radius of 20?

Feature: Triangular Meander

This is an issue for discussion/PRs on triangular meandering.

Things we want to do:

  • Print a triangular meander
  • Print as single path (Adjust bounds)
  • Handle volumetric offsetting at nodes

triangular meander

output to textfile not working only until line 4306

hey im generating gcode like this within a jupyter notebook:

from mecode import G
import random
import numpy as np

gridsize=[20,20]
gridlength=15
repeat=4

# new function to draw a line
def drawline(x,y):
    # find top right corner
    gridlengthmult=.8#random.randint(1,2)
    topleftcorner=[x*gridlength,y*gridlength]
    # move to top left corner

    print(";topleftcorner"+str(topleftcorner))
    # choose random corner
    lrtb=[random.randint(0,1),random.randint(0,1)]#left right top bottom choose random corner
    # find startpoint in global coordinates
    startpoint=[topleftcorner[0]+lrtb[0]*gridlength*gridlengthmult,topleftcorner[1]+lrtb[1]*gridlength*gridlengthmult]
    print(";startpoint"+str(startpoint))
    # find endpoint in global coordinates
    endpoint=[topleftcorner[0]+(1-lrtb[0])*gridlength*gridlengthmult,topleftcorner[1]+(1-lrtb[1])*gridlength*gridlengthmult]
    print(";endpoint"+str(endpoint))
    # do arcmovement
    x_dim=endpoint[0]-startpoint[0]
    y_dim=endpoint[1]-startpoint[1]
    print(";x_dim"+str(x_dim))
    print(";y_dim"+str(y_dim))
    g.move(startpoint[0],startpoint[1])
    g.move(z=0)
    g.relative()
    g.arc(x=x_dim,y=y_dim,radius=gridlength*gridlengthmult)
    g.absolute()
    g.move(z=10)

#g = G()
g= G("hello.gcode",header="header.gcode",footer="footer.gcode")
g.absolute()
g.abs_move(z=10)
# loop through grid
for x in range(gridsize[0]):
    for y in range(gridsize[1]):
        for z in range(repeat):
            drawline(x,y)

and the output is always missing a few characters on line 4306. weirdly enough.

This doesnt happen when i output to the console. It seems that sometimes the output after 4306 is even from the last time the code ran.

First line is not drawn

When using g.view() the move from the origin to the first move point isn't shown. The position_history should be pre-populated with the origin as the first location.

header and footer

when I run the py file it always add the default header and footer, which is not recognized by my printer (H2). I need to manually delete does for the code to work. what are the header and footer for?

Zero-length movements prevent visualization.

Zero-length movement commands (either zero-length relative moves or absolute moves to the previous position) will prevent proper visualization in MayaVi because it can't calculate their normals.

This is especially a problem for extruder-only commands because they never have any xyz movement. For example, calling g.extrude(5) or g.move(e=5).

Transformation Matrix Stack

A transformation hierarchy similar to that used by the Processing language for rendering using a stack of coordinate transform matrices may be useful in mecode.

This would consist of two primary functions: push_matrix() and pop_matrix(), which manipulate a stack of matrix transforms which are all applied to the currently used coordinates.

For example, it may be useful to define some printed feature in local absolute (or relative) coordinates but print the feature in multiple places with different rotations, etc. The main code would push the transform matrix for a unique position/orientation of the feature to the stack, call the code to print the feature, then pop the transform off the stack and continue in its "world" coordinates. Then all the code for the feature can operate in "local" coordinates.

In implementation, this functionality can be achieved by using relative movements for all such subfeatures, but calculating the relative distances from coordinate counter variables which correspond to local absolute position. The manipulation of these counters is based on the current transformation matrix stack.

This system allows for an elegant coordinate systems hierarchy, with features and sub features defined intuitively in their local coordinates systems.

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.