-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgcode_contour_circles.py
More file actions
269 lines (235 loc) · 9.1 KB
/
gcode_contour_circles.py
File metadata and controls
269 lines (235 loc) · 9.1 KB
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
from gcode import GCode, UnseenFormatter
class GCode_Contour_Circle(GCode):
""" create a circle contour """
def __init__ (self, cfg, version="GCode_Contour_Circle V0.1"):
super().__init__(cfg, version)
@staticmethod
def helicalHole(self, x, y, i, j, r, td, f, dt, ds, contour='on', dir='CW'):
"""[create a helical hole ]
Args:
x ([float]): [center x]
y ([float]): [center y]
i ([float]): [i value]
j ([float]): [j value]
r ([float]): [radius]
td ([float]): [tool diameter]
f ([float]): [feed]
dt ([float]): [depth total]
ds ([float]): [depth step]
contour (str, optional): [description]. Defaults to 'on'.
dir (str, optional): [description]. Defaults to 'CW'.
"""
"""
dr = np.arange(0.0, dt, ds)
dd = dt - dr.max()
# if max value of array is less than depth total, insert depth_total
if dd >= 0.0:
dr = np.append(dr, (dt))
# due to a helical circel it smoother to put max() value again to array
# than during milling this last step is done twice
dr = np.append(dr, (dt))
"""
dr = self.getDepthStepRangeArray((dt, ds))
comment = f"-- helical hole start --"
last_z = 0
self.addComment(comment, leadingBlank=True, endingBlank=True)
# calculate start position
# x position + radius (set Cutter to right)
# y position is not changed
x += r
ic = i # tool compensation
jc = j # tool compensation
if contour == 'on':
pass
elif contour == 'outside':
ic += td / 2.0
x += td / 2.0
elif contour == 'inside':
ic -= td / 2.0
x -= td / 2.0
#
# go to start position
# independend if CW or CCW, we start from x + radisu
self.addGCode(self._cfg.GCODES['lin_move_xyf'], args={'x':x, 'y':y , 'feed':f })
self.addGCode(self._cfg.GCODES['lin_move_zf'], args={'z':0, 'feed':f })
for z in dr:
# first item in dr-array is allways 0. so first milling arc is at z0 and than we start to go deeper
# last two items are allways at the same z position, this is to avoid an unsmooth end shape
if dir == 'CW':
# note if CW than I-Value is negativ
self.addGCode(self._cfg.GCODES['arc_int_cw_ijz'],args={'i':-abs(ic), 'j':-abs(jc), 'z':-z}, indent=3 )
else:
# note if CCW than I-Value is positiv
self.addGCode(self._cfg.GCODES['arc_int_ccw_ijz'],args={'i':-abs(ic), 'j':-abs(jc), 'z':-z}, indent=3)
last_z = z
pass
comment = f"-- helical hole end --"
self.addComment(comment, leadingBlank=True, endingBlank=True)
pass
def generateGcode(self, data):
"""
{'pre_gcode': 'G90 G64 G17 G40 G49', 'post_gcode': 'G00 Z10 F100 M2',
'center_point': '1',
'unit': 'mm', 'direction': 'CCW',
'cutter_compensation': 'on', 'depth_step': '0.5', 'depth_total': '33',
'feed_g00_xy': '600', 'feed_g00_z': '400', 'feed_g01_xy': '300', 'feed_g01_z': '15',
'z_start': '3.0', 'z_safety': '15.0',
'tool_dia':'3.0',
'tool_id' : '1',
'speed' : '20000',
---- specific from project -----
'diameter' : '12'
}
Args:
data ([type]): [description]
"""
xy = [0,0]
diameter = float(data['diameter'])
radius = diameter / 2.0
(xy, tool_comp, range) = self.addStandardGCodes(
data,
comments= {
"intro" : {
"text" : 'GCode_Contour_Circle. Version {0} - {1}',
"args" : [
"V0.1",
"12-2021"
]
},
"c1" : {
"text" : 'Helical circle diameter {0}{1}, milling contour {2}, cutting direction {3}',
"args" : [
data['diameter'],
data['unit'] ,
data['cutter_compensation'],
data['direction']
]
}
}
)
comment = f"Start project milling"
self.addComment(comment, leadingBlank=True, endingBlank=True)
#
x = xy[0]
y = xy[1]
r = float(data['diameter']) / 2.0
td = float(data['tool_dia'] )
i = r
j = 0
f = self.lin_move_xy
dt = self.depth_total
ds = self.depth_step
#
# let's use the statci method
self.helicalHole(self, x, y, i, j, r, td, f, dt, ds, self.contour, self.dir)
self.finish(0,0)
pass
class GCode_Contour_Arc(GCode):
""" create a sharp cornerd rectangle """
def __init__ (self, cfg, version="GCode_Contour_Circle V0.1"):
super().__init__(cfg, version)
@staticmethod
def generateArcGCode(self, xy, radius, start_end_angle, td, f, depth, contour='on', dir='CW'):
"""[summary]
Args:
xy ([array]): [x,y]
radius ([type]): [radius of arc]
start_end_angle ([array]): [[angle_left, angle_right]
td ([type]): [tool diameter]
f ([type]): [feed]
depth ([type]): [depth_totoal, depth_step]
contour (str, optional): ['on', 'outside', 'inside']. Defaults to 'on'.
dir (str, optional): ['CW', 'CCW']. Defaults to 'CW'.
"""
dr = self.getDepthStepRangeArray(depth)
# p1 = start point (used with G00/G01)
# p2 = end point (used with G02)
if contour == "inside":
radius -= float(td/2.0)
elif contour == "outside":
radius += float(td/2.0)
p1_x = round(radius * math.cos(math.radians(start_end_angle[0])),5)
p1_y = round(radius * math.sin(math.radians(start_end_angle[0])),5)
p2_x = round(radius * math.cos(math.radians(start_end_angle[1])),5)
p2_y = round(radius * math.sin(math.radians(start_end_angle[1])),5)
comment = f"contour = {contour}, new radius = {radius} with calculated tool diameter {td}/2"
last_z = 0
self.addComment(comment, leadingBlank=True, endingBlank=True)
comment = f"-- create an arc --"
last_z = 0
self.addComment(comment, leadingBlank=True, endingBlank=True)
for z in dr:
comment = f"-- z={z} --"
self.addComment(comment, leadingBlank=True, endingBlank=True, indent=3)
# go to start position
self.addGCode(
self._cfg.GCODES['rapid_move_xyzf'],
args={'x':p1_x, 'y':p1_y, 'z':self.z_start, 'feed':self.rapid_move_xy},
indent=3
)
self.addGCode(
self._cfg.GCODES['lin_move_zf'],
args={'z':-z, 'feed':self.lin_move_xy},
indent=3
)
self.addGCode(
self._cfg.GCODES['arc_int_cw'],
args={'x':p2_x, 'y':p2_y, 'i':(p1_x * -1), 'j':(p1_y*-1), 'z':-z},
indent=3
)
self.addGCode(
self._cfg.GCODES['lin_move_zf'],
args={'z':self.z_start, 'feed':self.rapid_move_z},
indent=3
)
last_z = z
pass
def generateGcode(self, data):
radius = data['radius']
angle_start = data['angle_start']
angle_end = data['angle_end']
self.setObjectData(data)
xy = [0,0]
(xy, tool_comp, range) = self.addStandardGCodes(
data,
comments= {
"intro" : {
"text" : 'GCode_Contour_Arc. Version {0} - {1}',
"args" : [
"V0.1",
"12-2021"
]
},
"c1" : {
"text" : 'Start at angle w1 {0}° and end at angle {1}° and radius {2}',
"args" : [
angle_start,
angle_end,
radius
]
},
"c2" : {
"text" : 'cutting depth {0} with step rate {1}, milling contour {2}, cutting direction {3}',
"args" : [
self.depth_total,
self.depth_step,
self.contour,
self.dir
]
}
}
)
self.generateArcGCode(self,
xy=xy,
radius=round(float(radius),4),
start_end_angle=[float(angle_start), float(angle_end)],
td=float(self.tool_dia),
f=self.lin_move_xy,
depth=[float(self.depth_total), float(self.depth_step)],
contour=self.contour,
dir=self.dir
)
self.finish(0,0)
pass
pass
pass