Skip to content

Commit

Permalink
Migrated to new framework (multipass.py)
Browse files Browse the repository at this point in the history
  • Loading branch information
thegaragelab committed Jul 28, 2015
1 parent 975b3d4 commit 521400d
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions multipass.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env python
#----------------------------------------------------------------------------
# 28-Jul-2015 ShaneG
#
# Updated for the new framework
#
# 29-Jun-2015 ShaneG
#
# Convert a NGC file into multiple passes to achieve the cut.
#----------------------------------------------------------------------------
from sys import argv
from optparse import OptionParser
from gcode import ZLevel, loadGCode, saveGCode
from util import *

#--- Usage information
USAGE = """
Expand All @@ -15,64 +19,59 @@
Where:
--cut depth specify the target cut depth
--cut depth the total cut depth
--safe depth specify the safe distance for moves between cuts
--step depth the maximum depth to cut during a single pass
--output filename the name of the file to write the results to
"""

GCODE_PREFIX = """
G21 (Use mm)
G90 (Set Absolute Coordinates)
G0 Z%0.4f (Move clear of the board first)
(end of prefix)
"""

GCODE_SUFFIX = """
(Operation complete)
G0 X0 Y0 Z%0.4f
M2
%
"""
#--- Defaults
CONTROL = {
"cut": -2.0,
"safe": 3.0,
"step": -1.0,
}

#--- Main program
if __name__ == "__main__":
# Set up program options
parser = OptionParser()
parser.add_option("-c", "--cut", action="store", type="float", dest="cut_depth")
parser.add_option("-s", "--safe", action="store", type="float", dest="safe_depth")
parser.add_option("-t", "--step", action="store", type="float", dest="step_depth")
parser.add_option("-o", "--output", action="store", type="string", dest="output_file")
parser.add_option("-c", "--cut", action="store", type="float", dest="cut")
parser.add_option("-s", "--safe", action="store", type="float", dest="safe")
parser.add_option("-t", "--step", action="store", type="float", dest="step")
parser.add_option("-o", "--output", action="store", type="string", dest="output")
options, args = parser.parse_args()
# Check positional arguments
if len(args) <> 1:
print USAGE.strip() % argv[0]
exit(1)
# Make sure required arguments are present
for req in ("cut_depth", "safe_depth", "step_depth", "output"):
if eval("options.%s" % req) is None:
for req in ("step", "output"):
if getattr(options, req, None) is None:
print "ERROR: Missing required argument '%s'" % req
print USAGE.strip() % argv[0]
exit(1)
source = args[0]
# Get defaults and load the file
CONTROL = getSettings(CONTROL, options)
original = loadGCode(source, BoxedLoader(start = GCommand("G00 X0 Y0"), end = GCommand("M02"), inclusive = False))
# Determine the size of each step
steps = 1
while (options.cut_depth / steps) > options.step_depth:
steps = steps + 1
delta = options.cut_depth / steps
if CONTROL['cut'] < CONTROL['step']:
steps = int(round(0.5 + (CONTROL['cut'] / CONTROL['step']), 0))
delta = CONTROL['cut'] / steps
depth = delta
# Now process the file
original = loadGCode(source, stripped = True)
result = list()
result = GCode()
for x in range(steps):
processor = ZLevel(depth, options.safe_depth)
result.extend(processor.apply(original))
print " Generating pass at Z = %0.4f" % depth
result.append(original.clone(ZLevel(safe = CONTROL['safe'], cut = depth)))
depth = depth + delta
# Write the output
saveGCode(
options.output_file,
options.output,
result,
prefix = GCODE_PREFIX % options.safe_depth,
suffix = GCODE_SUFFIX % options.safe_depth
prefix = CONTROL['prefix'],
suffix = CONTROL['suffix']
)

0 comments on commit 521400d

Please sign in to comment.