-
Notifications
You must be signed in to change notification settings - Fork 97
/
arcgen-mill.py
290 lines (235 loc) · 12.3 KB
/
arcgen-mill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env python
"""
Arc Generator G-Code Generator
Version 1.8
Copyright (C) <2008> <John Thornton>
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 3 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, see <http://www.gnu.org/licenses/>.
e-mail me any suggestions to "bjt 128 at gmail dot com"
If you make money using this software
you must donate $20 USD to a local food bank
or the food police will get you! Think of others from time to time...
To make it a menu item in Ubuntu use the Alacarte Menu Editor and add
the command python YourPathToThisFile/face.py
make sure you have made the file execuatble by right
clicking and selecting properties then Permissions and Execute
To use with LinuxCNC see the instructions at:
https://github.com/linuxcnc/simple-gcode-generators
Inspired by Sebastian Jardi Estadella's addition to send the output to gEdit
I've decided to incorporate it into Arc Buddy and make some additions that
should make this program actually useful.
The following instructions are for Ubuntu 10.04
Open Gedit and navigate to Edit > Preferences > Plugins and check off
External Tools to add them to your menu.
Go to Tools > Manage External Tools and click on the page with a star in the
lower left corner above the Help button. This adds a new Tool. Change the name
of New Tool to something that makes sense to you like Arc Buddy and hit Enter
to save the new name. Add a shortcut key if you like. Change Output: to
Insert at cursor position. In the Edit: box change line 1 to:
python full/path/to/arcbuddy/arcbuddy.py
Close the External Tools Manager and your ready to use Arc Buddy in Gedit
after you close and reopen Gedit.
When your creating G code in Gedit go to Tools > External Tools > Arc Buddy
Add the required data and click Show Me to see or click Send to send the
output to Gedit.
"""
from Tkinter import *
from math import *
import os
IN_AXIS = os.environ.has_key("AXIS_PROGRESS_BAR")
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.PreviewFrame = Frame(self,bd=5)
self.PreviewFrame.grid(row=0, column=0)
self.PreviewCanvas = Canvas(self.PreviewFrame,width=300, height=300, bg='white')
self.PreviewCanvas.grid(sticky=N+S+E+W)
self.XLine = self.PreviewCanvas.create_line(75,150,225,150)
self.YLine = self.PreviewCanvas.create_line(150,75,150,225)
self.Deg0 = self.PreviewCanvas.create_text(245, 150, text='0 X+')
self.Deg90 = self.PreviewCanvas.create_text(150, 60, text='Y+\n90')
self.Deg180 = self.PreviewCanvas.create_text(50, 150, text='X- 180')
self.Deg270 = self.PreviewCanvas.create_text(150, 240, text='270\nY-')
self.EntryFrame = Frame(self,bd=5)
self.EntryFrame.grid(row=0, column=1)
self.st00 = Label(self.EntryFrame, text='Figure out the G2/3 Code')
self.st00.grid(row=0, column=0, columnspan=2)
self.st01 = Label(self.EntryFrame, text='X Center of Arc')
self.st01.grid(row=1, column=0)
self.XArcCenterVar = StringVar()
self.XArcCenter = Entry(self.EntryFrame, textvariable=self.XArcCenterVar ,width=15)
self.XArcCenter.grid(row=1, column=1)
self.st02 = Label(self.EntryFrame, text='Y Center of Arc')
self.st02.grid(row=2, column=0)
self.YArcCenterVar = StringVar()
self.YArcCenter = Entry(self.EntryFrame, textvariable=self.YArcCenterVar ,width=15)
self.YArcCenter.grid(row=2, column=1)
self.st03 = Label(self.EntryFrame, text='Diameter of Arc')
self.st03.grid(row=3, column=0)
self.ArcDiameterVar = StringVar()
self.ArcDiameter = Entry(self.EntryFrame, textvariable=self.ArcDiameterVar ,width=15)
self.ArcDiameter.grid(row=3, column=1)
self.st04 = Label(self.EntryFrame, text='Start Angle')
self.st04.grid(row=4, column=0)
self.StartAngleVar = StringVar()
self.StartAngle = Entry(self.EntryFrame, textvariable=self.StartAngleVar ,width=15)
self.StartAngle.grid(row=4, column=1)
self.st05 = Label(self.EntryFrame, text='End Angle')
self.st05.grid(row=5, column=0)
self.EndAngleVar = StringVar()
self.EndAngle = Entry(self.EntryFrame, textvariable=self.EndAngleVar ,width=15)
self.EndAngle.grid(row=5, column=1)
self.st05 = Label(self.EntryFrame, text='Direction')
self.st05.grid(row=6, column=0)
self.DirectionVar = IntVar()
Radiobutton(self.EntryFrame, text='CCW', value=0, variable=self.DirectionVar)\
.grid(row=6, column=1, sticky = W)
Radiobutton(self.EntryFrame, text='CW', value=1, variable=self.DirectionVar)\
.grid(row=6, column=1, sticky = E)
self.st07 = Label(self.EntryFrame, text='Feed Value')
self.st07.grid(row=7, column=0)
self.FeedRateVar = StringVar()
self.FeedRate = Entry(self.EntryFrame, textvariable=self.FeedRateVar ,width=15)
self.FeedRate.grid(row=7, column=1)
self.sp00 = Label(self.EntryFrame, text=' ')
self.sp00.grid(row=8)
self.st06 = Label(self.EntryFrame, text='Starting Point for the Arc')
self.st06.grid(row=9, column=0, columnspan=2)
self.StartPointVar = StringVar()
self.StartPoint = Entry(self.EntryFrame, width=30, textvariable = self.StartPointVar)
self.StartPoint.grid(row=10, column=0, columnspan=2)
self.st06 = Label(self.EntryFrame, text='G Code for the Arc')
self.st06.grid(row=11, column=0, columnspan=2)
self.ArcCodeVar = StringVar()
self.ArcCode = Entry(self.EntryFrame, width=35, textvariable = self.ArcCodeVar)
self.ArcCode.grid(row=12, column=0, columnspan=2)
self.sp01 = Label(self.EntryFrame, text=' ')
self.sp01.grid(row=13)
self.DoItButton = Button(self.EntryFrame, text='Show Me', command=self.DoIt)
self.DoItButton.grid(row=14, column=0)
self.ToClipboard = Button(self.EntryFrame, text='To Clipboard', command=self.CopyClipboard)
self.ToClipboard.grid(row=14, column=1)
if IN_AXIS:
self.quitButton = Button(self, text='Write to AXIS and Quit',\
command=self.WriteToAxis)
else:
self.quitButton = Button(self, text='Quit', command=self.quit)
self.sendArcButton = Button(self, text='Send All', command=self.SendAll)
self.sendArcButton.grid(row=13, column=0)
self.sendAllButton = Button(self, text='Send Arc', command=self.SendArc)
self.sendAllButton.grid(row=13, column=1)
self.quitButton.grid(row=13, column=2, sticky=S)
def DoIt(self):
# draw the arc
try:
self.PreviewCanvas.delete(self.ArcId)
except AttributeError:
pass
self.XArcCenterN = float(self.XArcCenterVar.get())
self.YArcCenterN = float(self.YArcCenterVar.get())
self.ArcStart = float(self.StartAngleVar.get())
self.ArcEnd = float(self.EndAngleVar.get())
self.ArcDirection = int(self.DirectionVar.get())
if self.ArcDirection == 0: #CCW
if self.ArcStart < self.ArcEnd:
self.ArcDegrees = self.ArcEnd - self.ArcStart
elif self.ArcStart > self.ArcEnd:
self.ArcDegrees = (360 - self.ArcStart) + self.ArcEnd
elif self.ArcStart == self.ArcEnd:
self.ArcDegrees = 360
self.ArcId = self.PreviewCanvas.create_arc(75,75,225,225,extent=self.ArcDegrees,\
start=self.ArcStart, style='arc')
elif self.ArcDirection == 1: # CW
if self.ArcStart > self.ArcEnd:
self.ArcDegrees = self.ArcStart - self.ArcEnd
elif self.ArcStart < self.ArcEnd:
self.ArcDegrees = (360 - self.ArcEnd) + self.ArcStart
elif self.ArcStart == self.ArcEnd:
self.ArcDegrees = 360
self.ArcId = self.PreviewCanvas.create_arc(75,75,225,225,extent=self.ArcDegrees,\
start=self.ArcEnd, style='arc')
# generate the G code
self.ArcRadius = float(self.ArcDiameterVar.get())/2
# find the X and Y start point and offset
if self.ArcStart <= 90: # Quadrant 1
self.XStart = self.XArcCenterN + (self.ArcRadius * cos(radians(self.ArcStart)))
self.YStart = self.YArcCenterN + (self.ArcRadius * sin(radians(self.ArcStart)))
self.StartPointVar.set('X%3.4f Y%3.4f' %(self.XStart, self.YStart))
self.IOffset = -(self.XStart - self.XArcCenterN)
self.JOffset = -(self.YStart - self.YArcCenterN)
elif self.ArcStart > 90 and self.ArcStart <= 180: # Quadrant 2
self.XStart = self.XArcCenterN - (self.ArcRadius*sin(radians(self.ArcStart-90)))
self.YStart = self.YArcCenterN + (self.ArcRadius*cos(radians(self.ArcStart-90)))
self.StartPointVar.set('X%3.4f Y%3.4f' %(self.XStart, self.YStart))
self.IOffset = abs(self.XStart - self.XArcCenterN)
self.JOffset = -(self.YStart - self.YArcCenterN)
elif self.ArcStart > 180 and self.ArcStart <= 270: # Quadrant 3
self.XStart = self.XArcCenterN - (self.ArcRadius*cos(radians(self.ArcStart-180)))
self.YStart = self.YArcCenterN - (self.ArcRadius*sin(radians(self.ArcStart-180)))
self.StartPointVar.set('X%3.4f Y%3.4f' %(self.XStart, self.YStart))
self.IOffset = abs(self.XStart - self.XArcCenterN)
self.JOffset = abs(self.YStart - self.YArcCenterN)
elif self.ArcStart > 270 and self.ArcStart <= 360: # Quadrant 4
self.XStart = self.XArcCenterN + (self.ArcRadius*sin(radians(self.ArcStart-270)))
self.YStart = self.YArcCenterN - (self.ArcRadius*cos(radians(self.ArcStart-270)))
self.StartPointVar.set('X%3.4f Y%3.4f' %(self.XStart, self.YStart))
self.IOffset = -(self.XStart - self.XArcCenterN)
self.JOffset = -(self.YStart - self.YArcCenterN)
# find the X and Y end point
if self.ArcEnd <= 90: # Quadrant 1
self.XEnd = self.XArcCenterN + (self.ArcRadius * cos(radians(self.ArcEnd)))
self.YEnd = self.YArcCenterN + (self.ArcRadius * sin(radians(self.ArcEnd)))
self.ArcEndPoint = 'X%3.4f Y%3.4f' %(self.XStart, self.YStart)
elif self.ArcEnd > 90 and self.ArcEnd <= 180: # Quadrant 2
self.XEnd = self.XArcCenterN - (self.ArcRadius*sin(radians(self.ArcEnd-90)))
self.YEnd = self.YArcCenterN + (self.ArcRadius*cos(radians(self.ArcEnd-90)))
self.ArcEndPoint = 'X%3.4f Y%3.4f' %(self.XStart, self.YStart)
elif self.ArcEnd > 180 and self.ArcEnd <= 270: # Quadrant 3
self.XEnd = self.XArcCenterN - (self.ArcRadius*cos(radians(self.ArcEnd-180)))
self.YEnd = self.YArcCenterN - (self.ArcRadius*sin(radians(self.ArcEnd-180)))
self.ArcEndPoint = 'X%3.4f Y%3.4f' %(self.XStart, self.YStart)
elif self.ArcEnd > 270 and self.ArcEnd <= 360: # Quadrant 4
self.XEnd = self.XArcCenterN + (self.ArcRadius*sin(radians(self.ArcEnd-270)))
self.YEnd = self.YArcCenterN - (self.ArcRadius*cos(radians(self.ArcEnd-270)))
self.ArcEndPoint = 'X%3.4f Y%3.4f' %(self.XStart, self.YStart)
if self.ArcDirection == 0: # CCW
self.ArcCodeVar.set('G3 X%.4f Y%.4f I%.4f J%.4f' \
%(self.XEnd, self.YEnd, self.IOffset, self.JOffset))
elif self.ArcDirection == 1: # CW
self.ArcCodeVar.set('G2 X%.4f Y%.4f I%.4f J%.4f' \
%(self.XEnd, self.YEnd, self.IOffset, self.JOffset))
self.gcode = 'F' + self.FeedRateVar.get() + '\n'
self.gcode += 'G0 '+ self.StartPointVar.get() + '\n'
self.gcode += self.ArcCodeVar.get() + '\n'
self.gcode += 'M2'
def CopyClipboard(self):
self.ArcCode.clipboard_clear()
self.ArcCode.clipboard_append(self.ArcCode.get())
def WriteToAxis(self):
sys.stdout.write(self.gcode)
self.quit()
def SendArc(self):
self.DoIt()
sys.stdout.write(self.ArcCode.get() + "\r\n")
self.quit()
def SendAll(self):
self.DoIt()
if self.FeedRateVar.get() <> '':
sys.stdout.write('F' + self.FeedRateVar.get() + "\r\n")
sys.stdout.write('G1 ' + self.StartPoint.get() + "\r\n")
sys.stdout.write(self.ArcCode.get() + "\r\n")
self.quit()
app = Application()
app.master.title("Mill Arc Generator 1.8")
app.mainloop()