Sunday, July 4, 2010

HeeksCNC + python == APT360

One of my favorite CNC programming languages is APT360. It's a totally parametric way of creating gcode for cnc machines. It's also not very user friendly, if you don't use it all the time and get rusty, like I do. I'm a big fan of parametric programming and also a big fan of the python programming language. It's fairly easy for a non programming like me to get into and it's very popular, so there are many resources on the web for it.
In one of my previous blog entries, I mentioned that HeeksCNC uses python as the underlying scripting between the main C++ code and the post processed g-code. This week, Dan Heeks introduced a blank scipting object in HeeksCNC that lets the user create scripts in python and retain them in the order wanted in the HeeksCAD file. 'New Script Operation', as it's named in the HeeksCNC machining menu let's you do anything that you can think of in python and insert it into the Heeks python output.
As soon as I got my hands on the source code and compiled it, I started playing with parametric holes and helix operations.



Here is a small and very limited script for creating a helix in gcode:

def helix(x_cen,y_cen,z_depth,dia,pitch,z_clear):
    r=dia/2
    flush_nc()
    rapid(x=x_cen,y=y_cen)
    rapid(z=z_clear)
    feed(z=z_depth)
    feed(x=(x_cen+r))

    while (z_depth < z_clear):

        arc_ccw(x=(x_cen-r),y=y_cen,z=(z_depth+pitch*.5),i=-r,j=0)

        arc_ccw(x=(x_cen+r),y=y_cen,z=(z_depth+pitch),i=r,j=0)
        z_depth= z_depth+pitch
    feed(x=(x_cen))

d=.25
p=.125
zclr=.1
zdepth=-1.0
helix(.5,.5,zdepth,d,p,zclr)
helix(5.5,.5,zdepth,d,p,zclr)
helix(5.5,3.5,zdepth,d,p,zclr)
helix(.5,3.5,zdepth,d,p,zclr)

This snippet of code doesn't take into account anything having to do with tool radius/diameter.

Here you can see that I mixed script ops and a regular profile machining op:



Fun stuff!