Sunday, April 15, 2012

Cloud CADCAM via twisted python

I have been working a bit with Julian Todd of FreeSteel . We have started working on a way of serving out toolpaths, using his 'Slicer' routine from a server. The server takes triangle vertices in and returns tool location paths, for waterline type machining. Julian is very familiar with twisted python and plans on using it for his own server. At the moment, I am running his library locally.

Here is an image of a part that I designed in FreeCAD and applied this 'Slicer' scheme to:

The python code that I used for this doesn't post process into actual g-code, but it could.

import Mesh
import Part,FreeCAD
from FreeCAD import Base,Vector
import freesteelpy as kernel

s1 = s[0]
m1 = s1.Object
m1.Mesh.write("/home/danfalck/") #write the triangle list to a file
f1 = m1.Mesh.Facets #returns out a list of facets

fssurf = kernel.FsSurf.New()
for f in f1:
fssurf.PushTriangle(f.Points[0][0],f.Points[0][1],f.Points[0][2], f.Points[1][0],f.Points[1][1],f.Points[1][2], \

def doit(fssurf, z , rad):

fshoriztoolsurf = kernel.FsHorizontalToolSurface.New()
fshoriztoolsurf.AddCylinder(rad, z, 10.0, 0) #cylinder radius, lower Z, upper Z, how the cylinder is connected to the rest of the tool -tangential etc.
fsimplicitarea = kernel.FsImplicitArea.New(0)
fsimplicitarea.SetContourConditions(0.99, -1.0, 0.002, 2, -1.0, 0.9)
fsweave = kernel.FsWeave.New()
fsweave.SetShape(-25, 25, -25, 25,.1) #(-x, -y, x , y of bounding area, last arg is granularity of path)

fspath2x = kernel.FsPath2X.New(0)
fspath2x.RecordContour(fsweave, False, 0, 0.0)


[ (fspath2x.GetD(i,0), fspath2x.GetD(i,1)) for i in range(fspath2x.GetNpts()) ]

[ (fspath2x.GetD(i,0), fspath2x.GetD(i,1), fspath2x.GetD(i,2)) for i in range(fspath2x.GetNpts()) ]

pt0 = (fspath2x.GetD(0,0), fspath2x.GetD(0,1), fspath2x.GetD(0,2))

c = Part.Compound([])

for i in range(fspath2x.GetNpts()-1):
line = ( Part.makeLine( (fspath2x.GetD(i,0), fspath2x.GetD(i,1), fspath2x.GetD(i,2) ) , ( fspath2x.GetD(i+1,0), fspath2x.GetD(i+1,1), fspath2x.GetD(i+1,2) ) ) )


rad = 1.0
startdepth = 2.5
zdepth = -3.0
stepdown = .25
steps = startdepth

while startdepth >= zdepth:
z = startdepth
startdepth =startdepth-stepdown

Sorry for the poor formatting of the source code- I need to figure that out soon.