Posts

Showing posts with the label Python CNC

Holy Cow Python 2.7/wxPython/wxGlade Install!

Image
I started back into my work on Python CNC as the Bozeman Makerspace has a Shapeoko that my son wants to learn to use. I looked at a bunch of software packages and feel there is a need for a simple SVG based drawing program that has direct g-code output.  Sure you can use a plugin in Inkscape and there is  jscut but I want something that is a little parametric.  I imagine a program with a list of shapes on the right where you can link a milling function to each with a graphical display of the tool paths on the right. This is based on my own process and the tools I used to mill on my Bridgeport CNC.  I started with a CAD drawing and then built code from the drawing with my own Python objects.  Then after outputing the g-code I would import it into NCplot to verify the tool paths.  Then off to EMC2, now known as LinuxCNC, to run in air first and then on a test piece. For the Shapeoko the process is similar: SVG in Inkscape Load it in jscut Output the g-code Load it in GRBL

Rotation Around a Point

There are lots of code example that show rotation or a 2D point around the origin but what about around some arbitrary point? This is important if you are translating airfoils into G-Code... To do a rotation around a point without matrix math you translate the point to rotate around the origin (0,0,0), then rotate the point, and translate it back. So basically you subtract the location of the rotation point from the x coordinate, rotate the new point, and add the location of the rotation point back. Here it is in Python from math import * def rotate2d(degrees,point,origin): """ A rotation function that rotates a point around a point to rotate around the origin use [0,0] """ x = point[0] - origin[0] yorz = point[1] - origin[1] newx = (x*cos(radians(degrees))) - (yorz*sin(radians(degrees))) newyorz = (x*sin(radians(degrees))) (yorz*cos(radians(degrees))) newx = origin[0] newyorz = origin[1] return newx,newyorz

Parabola in G code

The following Python script produces a parabola in G-code. #This code produces g-code for a parabola using the equation #(y - k)2 = 4a(x - h). The parabola is open to positive x. #a = x coor of focus #k = x coor of back of parabola #h = y coor of focus #r = resolution #ymax, ymax = limits of iteration a = 2.0 k = 0.0 h = 0.0 ymax = 5.0 ymin = 0.0 resolution = 0.1 lastx = 0.0 lasty = h def frange3(start, end=None, inc=None): """ A range function, that accepts float increments... http://code.activestate.com/recipes/66472/ """ import math if end == None: end = start + 0.0 start = 0.0 else: start += 0.0 # force it to be a float if inc == None: inc = 1.0 count = int(math.ceil((end - start) / inc)) L = [None,] * count L[0] = start for i in xrange(1,count): L[i] = L[i-1] + inc return L #top half for ystep in frange3(ymax+resolution,ymin,-resolution): x = ( ((ystep - k)*(ystep - k)) + 4*a*h ) / (4*a) print "G01 X"+str(x) +" Y"+str(ystep)