#!/usr/bin/python # # Copyright 2010 Andy Shelley # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from Tkinter import * from math import * from cmath import * class Application (Frame): # initialise def __init__ (self, master=None): Frame.__init__ (self, master) self.grid () self.createWidgets () # create the dialog window def createWidgets (self): self.Gcode = [] self.EntryFrame = Frame (self,bd=5) self.EntryFrame.grid (row=0, column=1) self.lbl1 = Label (self.EntryFrame, text='Three Wheel Farris Curve') self.lbl1.grid (row=0, column=0, columnspan=2, sticky=W) self.lbl2 = Label (self.EntryFrame, text='Wheel 1 Radius ') self.lbl2.grid (row=1, column=0, sticky=W) self.A1Var = StringVar() self.A1 = Entry (self.EntryFrame, textvariable=self.A1Var ,width=5) self.A1Var.set ('1') self.A1.grid (row=1, column=1, sticky=W) self.lbl3 = Label (self.EntryFrame, text='Wheel 2 Radius') self.lbl3.grid (row=2, column=0, sticky=W) self.A2Var = StringVar() self.A2 = Entry (self.EntryFrame, textvariable=self.A2Var ,width=5) self.A2Var.set ('1') self.A2.grid (row=2, column=1, sticky=W) self.lbl4 = Label (self.EntryFrame, text='Wheel 3 Radius') self.lbl4.grid (row=3, column=0, sticky=W) self.A3Var = StringVar() self.A3 = Entry (self.EntryFrame, textvariable=self.A3Var ,width=5) self.A3Var.set ('1') self.A3.grid (row=3, column=1, sticky=W) self.lbl5 = Label (self.EntryFrame, text='Wheel 1 Speed') self.lbl5.grid (row=4, column=0, sticky=W) self.N1Var = StringVar() self.N1 = Entry (self.EntryFrame, textvariable=self.N1Var ,width=5) self.N1Var.set ('19') self.N1.grid (row=4, column=1, sticky=W) self.lbl6 = Label (self.EntryFrame, text='Wheel 2 Speed') self.lbl6.grid (row=5, column=0, sticky=W) self.N2Var = StringVar() self.N2 = Entry (self.EntryFrame, textvariable=self.N2Var ,width=5) self.N2Var.set ('17') self.N2.grid (row=5, column=1, sticky=W) self.lbl7 = Label (self.EntryFrame, text='Wheel 3 Speed') self.lbl7.grid (row=6, column=0, sticky=W) self.N3Var = StringVar() self.N3 = Entry (self.EntryFrame, textvariable=self.N3Var ,width=5) self.N3Var.set ('-2') self.N3.grid (row=6, column=1, sticky=W) self.lbl8 = Label (self.EntryFrame, text='Wheel 1 Phase') self.lbl8.grid (row=7, column=0, sticky=W) self.S1Var = StringVar() self.S1 = Entry (self.EntryFrame, textvariable=self.S1Var ,width=5) self.S1Var.set ('0') self.S1.grid (row=7, column=1, sticky=W) self.lbl9 = Label (self.EntryFrame, text='Wheel 2 Phase') self.lbl9.grid (row=8, column=0, sticky=W) self.S2Var = StringVar() self.S2 = Entry (self.EntryFrame, textvariable=self.S2Var ,width=5) self.S2Var.set ('0') self.S2.grid (row=8, column=1, sticky=W) self.lbl10 = Label (self.EntryFrame, text='Wheel 3 Phase') self.lbl10.grid (row=9, column=0, sticky=W) self.S3Var = StringVar() self.S3 = Entry (self.EntryFrame, textvariable=self.S3Var ,width=5) self.S3Var.set ('0') self.S3.grid (row=9, column=1, sticky=W) self.lbl11 = Label (self.EntryFrame, text='Steps Per Rev') self.lbl11.grid (row=10, column=0, sticky=W) self.StepsVar = StringVar() self.Steps = Entry (self.EntryFrame, textvariable=self.StepsVar ,width=5) self.StepsVar.set ('2001') self.Steps.grid (row=10, column=1, sticky=W) self.lbl12 = Label (self.EntryFrame, text='Scale Factor') self.lbl12.grid (row=11, column=0, sticky=W) self.ScaleVar = StringVar() self.Scale = Entry (self.EntryFrame, textvariable=self.ScaleVar ,width=5) self.ScaleVar.set ('20') self.Scale.grid (row=11, column=1, sticky=W) self.lbl14 = Label (self.EntryFrame, text='Preamble') self.lbl14.grid (row=14, column=0, sticky=W) self.PreambleVar = StringVar() self.Preamble = Entry (self.EntryFrame, textvariable=self.PreambleVar ,width=20) self.PreambleVar.set ('G17 G40 G61 G94') self.Preamble.grid (row=14, column=1, sticky=W) self.lbl15 = Label (self.EntryFrame, text='Postamble') self.lbl15.grid (row=15, column=0, sticky=W) self.PostambleVar = StringVar() self.Postamble = Entry (self.EntryFrame, textvariable=self.PostambleVar ,width=20) self.PostambleVar.set ('M30') self.Postamble.grid (row=15, column=1, sticky=W) self.lbl16 = Label (self.EntryFrame, text='Depth of Cut') self.lbl16.grid (row=16, column=0, sticky=W) self.DepthVar = StringVar () self.Depth = Entry (self.EntryFrame, textvariable=self.DepthVar ,width=5) self.DepthVar.set ('1.0') self.Depth.grid (row=16, column=1, sticky=W) self.lbl17 = Label (self.EntryFrame, text='Feed Rate') self.lbl17.grid (row=17, column=0, sticky=W) self.FeedVar = StringVar () self.Feed = Entry (self.EntryFrame, textvariable=self.FeedVar ,width=5) self.FeedVar.set ('400') self.Feed.grid (row=17, column=1, sticky=W) self.lbl18 = Label (self.EntryFrame, text='Units') self.lbl18.grid (row=18, column=0, sticky=W) self.UnitsVar = IntVar () Radiobutton (self.EntryFrame, text='mm', value=0, variable=self.UnitsVar)\ .grid (row=18, column=1, sticky = W) Radiobutton (self.EntryFrame, text='in', value=1, variable=self.UnitsVar)\ .grid (row=18, column=1) self.quitButton = Button (self, text='Generate Path',\ command=self.Farris) self.quitButton.grid (row=20, column=1) # generate the gcode def Farris (self): # get the parameters self.A1 = float (self.A1Var.get ()) self.A2 = float (self.A2Var.get ()) self.A3 = float (self.A3Var.get ()) self.N1 = float (self.N1Var.get ()) self.N2 = float (self.N2Var.get ()) self.N3 = float (self.N3Var.get ()) self.S1 = float (self.S1Var.get ()) self.S2 = float (self.S2Var.get ()) self.S3 = float (self.S3Var.get ()) self.Steps = float (self.StepsVar.get ()) self.Scale = float (self.ScaleVar.get ()) self.Postamble = self.PostambleVar.get () self.Depth = float (self.DepthVar.get ()) self.Feed = float (self.FeedVar.get ()) self.Units = int (self.UnitsVar.get ()) # sanitise the inputs self.Depth = abs (self.Depth) self.Feed = abs (self.Feed) self.Steps = 1.0 / abs (self.Steps) # preamble self.Gcode.append(self.PreambleVar.get()) # select absolute mode self.Gcode.append('G90') # select metric or imperial units if (self.Units == 0): self.Gcode.append('G21') else : self.Gcode.append('G20') # trace farris curve t = 0 while (t < 1): z = self.A1 * exp(2*pi*(self.N1*t+self.S1)*1j) + self.A2 * exp(2*pi*(self.N2*t+self.S2)*1j) + self.A3 * exp(2*pi*(self.N3*t+self.S3)*1j) if (t == 0): x = z.real * self.Scale y = z.imag * self.Scale # move to first position self.Gcode.append('G0 X%.4f Y%.4f' %(x, y)) # feed tool to depth self.Gcode.append('G0 Z0.0000') self.Gcode.append('G1 Z-%.4f F%.1f' %(self.Depth, self.Feed)) self.Gcode.append('G1 X%.4f Y%.4f F%.1f' %(z.real * self.Scale, z.imag * self.Scale, self.Feed)) t+= self.Steps # retract tool self.Gcode.append('G1 Z%.4f F%.1f' %(self.Depth, self.Feed)) # return to start position self.Gcode.append('G91') if (x < 0): x = abs (x) elif (x > 0): x*= -1 if (y < 0): y = abs (y) elif (y > 0): y*= -1 self.Gcode.append('G0 X%.4f Y%.4f' %(x, y)) # postamble self.Gcode.append(self.PostambleVar.get()) # output gcode to axis for line in self.Gcode: print line self.quit() app = Application () app.master.title ("Farris Curves") app.master.geometry ("300x420+300+100") app.mainloop ()