Permalink
Browse files

Added docs, configurable prefix and suffix files, option to choose to…

… output to file instead of stdout and 5D support.
  • Loading branch information...
1 parent dd6df64 commit 35b9afbc08a5347d90e18b55383e026f4ee355db @ErikDeBruijn committed Dec 13, 2010
Showing with 69 additions and 54 deletions.
  1. +16 −0 scripts/lampshade/README.txt
  2. +53 −54 scripts/lampshade/lampshade.py
@@ -34,3 +34,19 @@ object!).
Good luck, and have fun!
-a
+
+==== Troubleshooting ====
+
+Q: It says something about "Cannot find module Image", what should I do?
+A: You probably don't have PIL (Python Image Library).
+ You can install this from a terminal. With Ubuntu you can apt-get python-pil. On Linux and the Mac you can compile this yourself.
+
+ $ wget http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
+(or look for a newer version here: http://effbot.org/downloads/#pil )
+ $ tar xzf Imaging-1.1.7.tar.gz
+ $ cd Imaging-1.1.7
+ $ python setup.py build
+ $ sudo python setup.py install
+
+
+
@@ -21,47 +21,21 @@
import sys
import Image
-prefix = """
-(Cupcake ABS default skeinforge profile)
-(homing routing)
-M104 S220 T0 (Temperature to 220 celsius)
-G21 (Metric FTW)
-G90 (Absolute Positioning)
-G92 X0 Y0 Z0 (You are now at 0,0,0)
-(You have failed me for the last time, MakerBot)
-G0 Z15 (Move up for test extrusion)
-M108 S255 (Extruder speed = max)
-M6 T0 (Wait for tool to heat up)
-G04 P5000 (Wait 5 seconds)
-M101 (Extruder on, forward)
-G04 P5000 (Wait 5 seconds)
-M103 (Extruder off)
-M01 (The heater is warming up and will do a test extrusion. Click yes after you have cleared the nozzle of the extrusion.)
-G0 Z0 (Go back to zero.)
-(end of start.)
-"""
-
-suffix = """
-(end of the file, cooldown routines)
-M104 S0
-G91
-G1 Z10
-"""
-
-suffixABP = """
-(end of the file, cooldown routines)
-G1 X0 Y50 F3300.0 (move to ejection position)
-M106 (conveyor on)
-G04 P10000 (wait 10 seconds)
-M107 (conveyor off)
-G1 X0 Y0 F3300.0 (recenter platform)
-G1 X0 Y0 Z0 F3300.0 (recenter platform)
-M104 S0 (shut off extruder if last cycle)
-(CYCLE BEGINS ANEW)
-"""
-
-
-# Do not edit
+prefixFile= "start.gcode"
+suffixFile= "end.gcode"
+suffixFileABP = "end-ABP.gcode"
+absoluteExtrusion = 0.0
+
+def output(str):
+ if outFile:
+ if str:
+ outFile.write(str+"\n")
+ else:
+ print output
+
+def loadFileToString(fileName):
+ f = open(fileName,"r")
+ return f.read()
def makeSpiralPoints(radius):
"Returns an array of points defining a spiral from the inside out"
@@ -80,13 +54,17 @@ def makeSpiralPoints(radius):
def makeBottom(layer):
"Generate a spiral bottom"
- global rBottomMm
+ global rBottomMm, absoluteExtrusion
z = layerHeight * layer
points = makeSpiralPoints(rBottomMm+extrusionWidth)
if (layer % 2) == 0:
points.reverse()
for p in points:
- print "G1 X%f Y%f Z%f F%f" % (p[0],p[1],z,baseFeedrate)
+ outStr = "G1 X%f Y%f Z%f F%f" % (p[0],p[1],z,baseFeedrate)
+ if options.extrusionRate:
+ absoluteExtrusion = options.extrusionRate + absoluteExtrusion
+ outStr = outStr + " E%f" % (absoluteExtrusion)
+ output(outStr)
def init():
global layerCount, rDeltaPerLayer, anglePerSegment
@@ -110,43 +88,58 @@ def getXYZ(layer,segment,roff=0.0):
return (x,y,z)
def makeSegment(layer, segment, value, earlyShutoff = 0):
+ global absoluteExtrusion
invvalue = 1.0-value
feedrate = baseFeedrate * ((invvalue * maxAdjustment) + value)
start = getXYZ(layer, segment-1)
end = getXYZ(layer,segment)
- return "G1 X%f Y%f Z%f F%f" % (end[0],end[1],end[2],feedrate)
+ outStr = "G1 X%f Y%f Z%f F%f" % (end[0],end[1],end[2],feedrate)
+ if options.extrusionRate:
+ absoluteExtrusion = options.extrusionRate + absoluteExtrusion
+ outStr = outStr + " E%f" % absoluteExtrusion
+ output(outStr)
def makeShape():
- print prefix
- print "M101"
- print "(Base)"
+ global absoluteExtrusion
+ output(loadFileToString(options.prefixFile))
+ output("M101")
+ output("(Base)")
for i in range(0,bottomLayers):
makeBottom(i)
if bottomLayers > 0:
# add single-layer seal
- print "(Adding seal along bottom)"
+ output("(Adding seal along bottom)")
for segment in range(0, segments):
r = rBottomMm - extrusionWidth
angle = anglePerSegment * segment
z = bottom + layerHeight
x = -math.sin(angle) * r
y = math.cos(angle) * r
- print "G1 X%f Y%f Z%f F%f" % (x,y,z,baseFeedrate)
- print "(Sides)"
+ outStr = "G1 X%f Y%f Z%f F%f" % (x,y,z,baseFeedrate)
+ if options.extrusionRate:
+ absoluteExtrusion = options.extrusionRate + absoluteExtrusion
+ outStr = outStr + " E%f" % absoluteExtrusion
+ output("(Sides)")
for layer in range(0,int(layerCount)):
for segment in range(0, segments):
x = segment
y = (im.size[1] - int(float(im.size[1]*layer)/layerCount)) - 1
- print makeSegment(layer, segment, pixels[x,y]/256.0)
- print "M103"
+ output(makeSegment(layer, segment, pixels[x,y]/256.0))
+ output("M103")
if abp:
- print suffixABP
+ output(loadFileToString(suffixFileABP))
else:
- print suffix
+ output(loadFileToString(options.suffixFile))
usage = "usage: %prog [options] image.png"
parser = OptionParser(usage = usage)
+parser.add_option("-o","--output-file",type="string",dest="outputFile",
+ help="output filename (default is standard output)",default="out.gcode")
+parser.add_option("-p","--prefix",type="string",dest="prefixFile",
+ help="prefix file",default=prefixFile)
+parser.add_option("-s","--suffix",type="string",dest="suffixFile",
+ help="the suffix file, will be added at the end.",default=suffixFile)
parser.add_option("-r","--radius",type="float",dest="radius",
help="set the top and bottom radius of a right cylinder")
parser.add_option("-l","--layerheight",type="float",dest="layerheight",
@@ -173,6 +166,8 @@ def makeShape():
parser.add_option("-f","--feedrate",type="float",dest="feedrate",
help="set the base feedrate",
default=34.5)
+parser.add_option("-e","--extrusion-rate",type="float",dest="extrusionRate",
+ help="set the extrusion rate, and adds E-codes")
#parser.add_option("--rexp",type="string"
(options,args) = parser.parse_args()
@@ -181,6 +176,9 @@ def makeShape():
parser.print_help()
exit()
+outFile = ""
+if options.outputFile:
+ outFile = open(options.outputFile,"w")
extrusionWidth = 0.5
bottomLayers = options.bottom
rBottomMm = options.rbot
@@ -201,3 +199,4 @@ def makeShape():
init()
makeShape()
+outFile.close()

0 comments on commit 35b9afb

Please sign in to comment.