Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to generate GCode with relative XY movement #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gcodeplot.inx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<param name="pen-up-speed" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Movement speed (mm/s):" _gui-description="Speed moving with pen up (Default: 40)">40</param>
<param name="pen-down-speed" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Draw speed (mm/s):" _gui-description="Speed moving with pen down (Default: 35)">35</param>
<param name="z-speed" type="float" min="-1000000" max="1000000" precision="1" _gui-text="Z-speed (mm/s):" _gui-description="Speed moving pen up/down (Default: 5)">5</param>
<param name="rel-code" type="bool" _gui-text="Generate relative GCode" _gui-description="Use relavite moves">false</param>
<param name="send-and-save" type="string" _gui-text="Serial port to send gcode to (blank not to send)" _gui-description="If you enter the name of your serial port here (e.g., COM4), then you can directly send the file to your device."></param>
<param name="send-speed" type="enum" _gui-text="Serial baud rate:" _gui-description="Baud rate of your serial device (Default: 115200)">
<item value="115200">115200</item>
Expand Down
33 changes: 27 additions & 6 deletions gcodeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def penColor(pens, pen):
else:
return (0.,0.,0.)

def emitGcode(data, pens = {}, plotter=Plotter(), scalingMode=SCALE_NONE, align = None, tolerance=0, gcodePause="@pause", pauseAtStart = False, simulation = False):
def emitGcode(data, pens = {}, plotter=Plotter(), scalingMode=SCALE_NONE, align = None, tolerance=0, gcodePause="@pause", pauseAtStart = False, simulation = False, relCode = False, incHoming = True):
if len(data) == 0:
return None

Expand Down Expand Up @@ -377,9 +377,15 @@ def park():
if lift:
gcode.extend(processCode(lift))
else:
if relCode:
gcode.append('G90 ;Absolute mode for Z movement')
gcode.append('G00 F%.1f Z%.3f; pen park !!Zpark' % (plotter.zSpeed*60., plotter.safeUpZ))
if relCode:
gcode.append('G91 ;Relative mode for XY movement')

park()
if relCode:
gcode.append('G91 ;Relative mode for XY movement')
if not simulation:
gcode.append('G00 F%.1f Y%.3f; !!Ybottom' % (plotter.moveSpeed*60., plotter.xyMin[1]))
gcode.append('G00 F%.1f X%.3f; !!Xleft' % (plotter.moveSpeed*60., plotter.xyMin[0]))
Expand Down Expand Up @@ -413,7 +419,11 @@ def penDown(force=False):
if plotter.downCommand:
gcode.extend(processCode(plotter.downCommand))
else:
if relCode:
gcode.append('G90 ;Absolute mode for Z movement')
gcode.append('G00 F%.1f Z%.3f; pen down !!Zwork' % (plotter.zSpeed*60., plotter.workZ))
if relCode:
gcode.append('G91 ;Relavite mode for XY-movement')
state.time += abs(state.curZ-plotter.workZ) / plotter.zSpeed
state.curZ = plotter.workZ

Expand All @@ -430,8 +440,13 @@ def flip(y):
else:
penUp(force=force)
if not simulation:
x = p[0]
y = p[1]
if relCode:
x -= state.curXY[0]
y -= state.curXY[1]
gcode.append('G0%d F%.1f X%.3f Y%.3f; %s !!Xleft+%.3f Ybottom+%.3f' % (
1 if down else 0, speed*60., p[0], p[1], "draw" if down else "move",
1 if down else 0, speed*60., x, y, "draw" if down else "move",
p[0]-plotter.xyMin[0], p[1]-plotter.xyMin[1]))
else:
start = state.curXY if state.curXY is not None else plotter.xyMin
Expand Down Expand Up @@ -771,7 +786,9 @@ def help(error=False):
comment = ";"
sendAndSave = False
directionAngle = None

relCode = False
incHoming = True

def maybeNone(a):
return None if a=='none' else a

Expand All @@ -785,7 +802,7 @@ def maybeNone(a):
'pause-at-start', 'no-pause-at-start', 'min-x=', 'max-x=', 'min-y=', 'max-y=',
'no-shading-avoid-outline', 'shading-darkest=', 'shading-lightest=', 'stroke-all', 'no-stroke-all', 'gcode-pause', 'dump-options', 'tab=', 'extract-color=', 'sort', 'no-sort', 'simulation', 'no-simulation', 'tool-offset=', 'overcut=',
'boolean-shading-crosshatch=', 'boolean-sort=', 'tool-mode=', 'send-and-save=', 'direction=', 'lift-command=', 'down-command=',
'init-code=', 'comment-delimiters=', 'end-code=' ], )
'init-code=', 'comment-delimiters=', 'end-code=', 'rel-code=' ], )

if len(args) + len(opts) == 0:
raise getopt.GetoptError("invalid commandline")
Expand Down Expand Up @@ -965,8 +982,12 @@ def maybeNone(a):
plotter.endCode = maybeNone(arg)
elif opt == '--comment-delimiters':
plotter.comment = maybeNone(arg)
elif opt == "--rel-code":
relCode = arg == "true"
elif opt == "--inc-homing":
incHoming = arg == "true"
else:
raise ValueError("Unrecognized argument "+opt)
raise ValueError("Unrecognized argument "+opt + " " + arg)
i += 1

except getopt.GetoptError as e:
Expand Down Expand Up @@ -1126,7 +1147,7 @@ def maybeNone(a):
g = emitHPGL(penData, pens=pens)
else:
g = emitGcode(penData, align=align, scalingMode=scalingMode, tolerance=tolerance,
plotter=plotter, gcodePause=gcodePause, pens=pens, pauseAtStart=pauseAtStart, simulation=svgSimulation)
plotter=plotter, gcodePause=gcodePause, pens=pens, pauseAtStart=pauseAtStart, simulation=svgSimulation, relCode = relCode, incHoming = incHoming)

if g:
dump = True
Expand Down