summaryrefslogtreecommitdiff
path: root/nc_files/ngcgui_lib/ihex.ngc
blob: 954d64c092c6a350f9f54ba0258479f1f9b648a2 (plain)
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
(require: angle at intersection of p1-2 and p1-4 must be obtuse)
(cw  traverse: p1,p2,p3,p4)
(ccw traverse: p1,p4,p3,p2)

(info: ihex: internal hexagon, cw/ccw dir, radius compensation)
o<ihex>  sub

#<toolno>   =  #1 (=1)
#<rpm>      =  #2 (=2000)
#<feedrate> =  #3 (=10)
#<dir>      =  #4 (=2 2conv | 3climb)
#<flatd>    =  #5 (distance across flats)
#<cutdepth> =  #6
#<zincr>    =  #7
#<zsafe>    =  #8 (=0.2)
#<zstart>   =  #9 (=0)
#<scale>    = #10 (=1)
#<rotate>   = #11 (=0)
#<xoff>     = #12 (=0)
#<yoff>     = #13 (=0)
#<spin_notify> = #14 (=0)
#<use_g43>     = #15 (=1)
#<h_for_g43>   = #16 (=0)
#<verbose>     = #17 (=0)

o<i0> if [#<scale> EQ 0]
        #<scale> = 1.0
        (debug, scale was 0, setting #<scale>)
o<i0> endif

o<loadtool> call [#<toolno>][#<use_g43>][#<h_for_g43>][#<verbose>]
#<tooldiam> =  [#5410 + .001]

o<dir> if [[#<dir> NE 2] AND [#<dir> NE 3]]
         (debug, ihex: direction must be 2 or 3 - EXITING)
         (print, ihex: direction must be 2 or 3 - EXITING)
         (AXIS,notify, ihex: direction must be 2 or 3 - EXITING)
         m2
o<dir> endif

#<f>      = [#<flatd>/2]
#<p>      = [#<f>/cos[30]]

#<pcos60> = [#<p> * cos[60]]
#<psin60> = [#<p> * sin[60]]

(p1 -> p2 -> is cw)
(apply scale,rotate, then offset to all input points)
#<x1>      = #<p>
#<y1>      = 0
o<move> call [#<x1>][#<y1>][#<rotate>][#<scale>][#<xoff>][#<yoff>]
#<x1>      = #<_move:x>
#<y1>      = #<_move:y>

#<x2>      = #<pcos60>
#<y2>      = [0 - #<psin60>]
o<move> call [#<x2>][#<y2>][#<rotate>][#<scale>][#<xoff>][#<yoff>]
#<x2>      = #<_move:x>
#<y2>      = #<_move:y>

#<x3>      = [0 - #<pcos60>]
#<y3>      = [0 - #<psin60>]
o<move> call [#<x3>][#<y3>][#<rotate>][#<scale>][#<xoff>][#<yoff>]
#<x3>      = #<_move:x>
#<y3>      = #<_move:y>

#<x4>      = [0 - #<p>]
#<y4>      = 0
o<move> call [#<x4>][#<y4>][#<rotate>][#<scale>][#<xoff>][#<yoff>]
#<x4>      = #<_move:x>
#<y4>      = #<_move:y>

#<x5>      = [0 -# <pcos60>]
#<y5>      = #<psin60>
o<move> call [#<x5>][#<y5>][#<rotate>][#<scale>][#<xoff>][#<yoff>]
#<x5>      = #<_move:x>
#<y5>      = #<_move:y>

#<x6>      = #<pcos60>
#<y6>      = #<psin60>
o<move> call [#<x6>][#<y6>][#<rotate>][#<scale>][#<xoff>][#<yoff>]
#<x6>      = #<_move:x>
#<y6>      = #<_move:y>

#<r>        = [#<tooldiam>/2]
#<cutdepth> = [0 - #<cutdepth>]
#<zincr>    = [0 - #<zincr>]

(get lengths and angles for connecting lines)
o<line> call [#<x1>][#<y1>][#<x2>][#<y2>]
#<phi12>    = #<_line:phi>
o<line> call [#<x2>][#<y2>][#<x3>][#<y3>]
#<len23>    = #<_line:len>
#<phi23>    = #<_line:phi>
#<cos23>    = #<_line:cos>
#<sin23>    = #<_line:sin>
o<line> call [#<x1>][#<y1>][#<x6>][#<y6>]
#<phi16>    = #<_line:phi>

o<line> call [#<x6>][#<y6>][#<x5>][#<y5>]
#<len65>    = #<_line:len>
#<phi65>    = #<_line:phi>
#<cos65>    = #<_line:cos>
#<sin65>    = #<_line:sin>

         g40 (cutter radius compensation off)
         f #<feedrate>
         s #<rpm> m3 (spindle cw)
o<if1>   if [#<spin_notify> GT 0]
o<spin>    call [#<rpm>]
o<if1>   endif
         g0 z#<zsafe>
         #<zcurrent> = #<zstart>
         #<pass>     = 1

o<wh010> while [#<zcurrent> GT #<cutdepth>]
              #<zcurrent> = [#<zcurrent> + #<zincr>]
o<wh020>   if [#<zcurrent> LT #<cutdepth>]
                #<zcurrent> = #<cutdepth>
o<wh020>   endif
o<wh030>   if [#<pass> GT 100]
             (debug, ihex: too many passes - EXITING)
             (print, ihex: too many passes - EXITING)
             (AXIS,notify, ihex: too many passes - EXITING)
             m2
o<wh030>   endif

o<dir00>   if [#<dir> EQ 2]
o<aaa10>     if [#<pass> EQ 1]
               (arc entry along line1-2 where corner 1 is obtuse)
               #<ax>  = [#<x1> + 1 * #<r> * cos[#<phi12>]] (entry)
               #<ay>  = [#<y1> + 1 * #<r> * sin[#<phi12>]]
               #<bx>  = [#<ax> + 2 * #<r> * sin[#<phi12>]] (preentry 1)
               #<by>  = [#<ay> - 2 * #<r> * cos[#<phi12>]]
               #<cx>  = [#<bx> + #<r> * cos[#<phi12>]]     (preentry 2)
               #<cy>  = [#<by> + #<r> * sin[#<phi12>]]
               #<vx>  = [0     - #<r> * sin[#<phi12>]]     (r vector)
               #<vy>  = [0     + #<r> * cos[#<phi12>]]
               g0  x #<cx> y #<cy> (preentry 1)
               g0  x #<bx> y #<by> (preentry 2)
/              g42 (cutter radius comp right of path)
               g2  x #<ax> y #<ay> i #<vx> j #<vy> (arc entry)
               #<xfinal_a> = [#<x2>]
               #<yfinal_a> = [#<y2>]
               (go along the 2-->3 line to exit)
               (angle between 1-->2 and 2-->3)
               (only necessary for acute angles)
               #<angle> = [180 + #<phi23> - #<phi12>]
               #<elen>  = [#<r> / ABS[TAN[#<angle>/2]]]
               #<k>     = [#<elen>/#<len23>]
               (print  angle=#<angle> elen=#<elen> k=#<k>)
o<aaa20>       if [#<k> GE 1]
                 (debug, ihex: can't get in final corner k=#<k> - EXITING)
                 (print, ihex: cant' get in final corner k=#<k> - EXITING)
                 (AXIS,notify, ihex: can't get in final corner - EXITING)
                 m2
o<aaa20>       endif
               #<xfinal_b> = [#<x2> + #<k> * #<len23> * #<cos23>]
               #<yfinal_b> = [#<y2> + #<k> * #<len23> * #<sin23>]
               g1 z #<zstart> (plunge)
o<aaa10>     endif
             x #<x2> y #<y2> z#<zcurrent>
             x #<x3> y #<y3>
             x #<x4> y #<y4>
             x #<x5> y #<y5>
             x #<x6> y #<y6>
             x #<x1> y #<y1>
             #<pass> = [#<pass> + 1]
o<dir00>   else (dir EQ 3 CCW)
o<bbb10>     if [#<pass> EQ 1]
               (arc entry along line4-1 where corner 1 is obtuse)
               #<ax>  = [#<x1> + 1 * #<r> * cos[#<phi16>]]       (entry)
               #<ay>  = [#<y1> + 1 * #<r> * sin[#<phi16>]]
               #<bx>  = [#<ax> - 2 * #<r> * sin[#<phi16>]]   (preentry 1)
               #<by>  = [#<ay> + 2 * #<r> * cos[#<phi16>]]
               #<cx>  = [#<bx> + #<r> * cos[#<phi16>]]       (preentry 2)
               #<cy>  = [#<by> + #<r> * sin[#<phi16>]]
               #<vx>  = [0 + #<r> * sin[#<phi16>]]           (r vector)
               #<vy>  = [0 - #<r> * cos[#<phi16>]]
               g0  x #<cx> y #<cy> (preentry 1)
               g0  x #<bx> y #<by> (preentry 2)
/              g41 (cutter radius comp left of path)
               g3  x #<ax> y #<ay> i #<vx> j #<vy> (arc entry)
               #<xfinal_a> = [#<x6>]
               #<yfinal_a> = [#<y6>]
               (go along the 4-->3 line to exit)
               (angle between 4-->3 and 1-->4)
               (only necessary for acute angles)
               #<angle> = [180 - #<phi16> + #<phi65>]
               #<elen>  = [#<r> / ABS[TAN[#<angle>/2]]]
               #<k>     = [#<elen>/#<len65>]
o<bbb20>       if [#<k> GE 1]
                 (debug, ihex: cant get in corner k=#<k> - EXITING)
                 (print, ihex: cant get in corner k=#<k> - EXITING)
                 (AXIS,notify, ihex: cant get in corner - EXITING)
                 m2
o<bbb20>       endif
               #<xfinal_b> = [#<x6> + 1.01* #<k> * #<len65> * #<cos65>]
               #<yfinal_b> = [#<y6> + 1.01* #<k> * #<len65> * #<sin65>]
               g1 z #<zstart> (plunge)
o<bbb10>     endif
             x #<x6> y #<y6> z#<zcurrent>
             x #<x5> y #<y5>
             x #<x4> y #<y4>
             x #<x3> y #<y3>
             x #<x2> y #<y2>
             x #<x1> y #<y1>
             #<pass> = [#<pass> + 1]
o<dir00>   endif

o<wh010> endwhile

         g1 x #<xfinal_a> y #<yfinal_a>
         g1 x #<xfinal_b> y #<yfinal_b>

         g0 z #<zsafe>
         g40
o<ihex> endsub