ihex.ngc
1 (require: angle at intersection of p1-2 and p1-4 must be obtuse) 2 (cw traverse: p1,p2,p3,p4) 3 (ccw traverse: p1,p4,p3,p2) 4 5 (info: ihex: internal hexagon, cw/ccw dir, radius compensation) 6 o<ihex> sub 7 8 #<toolno> = #1 (=1) 9 #<rpm> = #2 (=2000) 10 #<feedrate> = #3 (=10) 11 #<dir> = #4 (=2 2conv | 3climb) 12 #<flatd> = #5 (distance across flats) 13 #<cutdepth> = #6 14 #<zincr> = #7 15 #<zsafe> = #8 (=0.2) 16 #<zstart> = #9 (=0) 17 #<scale> = #10 (=1) 18 #<rotate> = #11 (=0) 19 #<xoff> = #12 (=0) 20 #<yoff> = #13 (=0) 21 #<spin_notify> = #14 (=0) 22 #<use_g43> = #15 (=1) 23 #<h_for_g43> = #16 (=0) 24 #<verbose> = #17 (=0) 25 26 o<i0> if [#<scale> EQ 0] 27 #<scale> = 1.0 28 (debug, scale was 0, setting #<scale>) 29 o<i0> endif 30 31 o<loadtool> call [#<toolno>][#<use_g43>][#<h_for_g43>][#<verbose>] 32 #<tooldiam> = [#5410 + .001] 33 34 o<dir> if [[#<dir> NE 2] AND [#<dir> NE 3]] 35 (debug, ihex: direction must be 2 or 3 - EXITING) 36 (print, ihex: direction must be 2 or 3 - EXITING) 37 (AXIS,notify, ihex: direction must be 2 or 3 - EXITING) 38 m2 39 o<dir> endif 40 41 #<f> = [#<flatd>/2] 42 #<p> = [#<f>/cos[30]] 43 44 #<pcos60> = [#<p> * cos[60]] 45 #<psin60> = [#<p> * sin[60]] 46 47 (p1 -> p2 -> is cw) 48 (apply scale,rotate, then offset to all input points) 49 #<x1> = #<p> 50 #<y1> = 0 51 o<move> call [#<x1>][#<y1>][#<rotate>][#<scale>][#<xoff>][#<yoff>] 52 #<x1> = #<_move:x> 53 #<y1> = #<_move:y> 54 55 #<x2> = #<pcos60> 56 #<y2> = [0 - #<psin60>] 57 o<move> call [#<x2>][#<y2>][#<rotate>][#<scale>][#<xoff>][#<yoff>] 58 #<x2> = #<_move:x> 59 #<y2> = #<_move:y> 60 61 #<x3> = [0 - #<pcos60>] 62 #<y3> = [0 - #<psin60>] 63 o<move> call [#<x3>][#<y3>][#<rotate>][#<scale>][#<xoff>][#<yoff>] 64 #<x3> = #<_move:x> 65 #<y3> = #<_move:y> 66 67 #<x4> = [0 - #<p>] 68 #<y4> = 0 69 o<move> call [#<x4>][#<y4>][#<rotate>][#<scale>][#<xoff>][#<yoff>] 70 #<x4> = #<_move:x> 71 #<y4> = #<_move:y> 72 73 #<x5> = [0 -# <pcos60>] 74 #<y5> = #<psin60> 75 o<move> call [#<x5>][#<y5>][#<rotate>][#<scale>][#<xoff>][#<yoff>] 76 #<x5> = #<_move:x> 77 #<y5> = #<_move:y> 78 79 #<x6> = #<pcos60> 80 #<y6> = #<psin60> 81 o<move> call [#<x6>][#<y6>][#<rotate>][#<scale>][#<xoff>][#<yoff>] 82 #<x6> = #<_move:x> 83 #<y6> = #<_move:y> 84 85 #<r> = [#<tooldiam>/2] 86 #<cutdepth> = [0 - #<cutdepth>] 87 #<zincr> = [0 - #<zincr>] 88 89 (get lengths and angles for connecting lines) 90 o<line> call [#<x1>][#<y1>][#<x2>][#<y2>] 91 #<phi12> = #<_line:phi> 92 o<line> call [#<x2>][#<y2>][#<x3>][#<y3>] 93 #<len23> = #<_line:len> 94 #<phi23> = #<_line:phi> 95 #<cos23> = #<_line:cos> 96 #<sin23> = #<_line:sin> 97 o<line> call [#<x1>][#<y1>][#<x6>][#<y6>] 98 #<phi16> = #<_line:phi> 99 100 o<line> call [#<x6>][#<y6>][#<x5>][#<y5>] 101 #<len65> = #<_line:len> 102 #<phi65> = #<_line:phi> 103 #<cos65> = #<_line:cos> 104 #<sin65> = #<_line:sin> 105 106 g40 (cutter radius compensation off) 107 f #<feedrate> 108 s #<rpm> m3 (spindle cw) 109 o<if1> if [#<spin_notify> GT 0] 110 o<spin> call [#<rpm>] 111 o<if1> endif 112 g0 z#<zsafe> 113 #<zcurrent> = #<zstart> 114 #<pass> = 1 115 116 o<wh010> while [#<zcurrent> GT #<cutdepth>] 117 #<zcurrent> = [#<zcurrent> + #<zincr>] 118 o<wh020> if [#<zcurrent> LT #<cutdepth>] 119 #<zcurrent> = #<cutdepth> 120 o<wh020> endif 121 o<wh030> if [#<pass> GT 100] 122 (debug, ihex: too many passes - EXITING) 123 (print, ihex: too many passes - EXITING) 124 (AXIS,notify, ihex: too many passes - EXITING) 125 m2 126 o<wh030> endif 127 128 o<dir00> if [#<dir> EQ 2] 129 o<aaa10> if [#<pass> EQ 1] 130 (arc entry along line1-2 where corner 1 is obtuse) 131 #<ax> = [#<x1> + 1 * #<r> * cos[#<phi12>]] (entry) 132 #<ay> = [#<y1> + 1 * #<r> * sin[#<phi12>]] 133 #<bx> = [#<ax> + 2 * #<r> * sin[#<phi12>]] (preentry 1) 134 #<by> = [#<ay> - 2 * #<r> * cos[#<phi12>]] 135 #<cx> = [#<bx> + #<r> * cos[#<phi12>]] (preentry 2) 136 #<cy> = [#<by> + #<r> * sin[#<phi12>]] 137 #<vx> = [0 - #<r> * sin[#<phi12>]] (r vector) 138 #<vy> = [0 + #<r> * cos[#<phi12>]] 139 g0 x #<cx> y #<cy> (preentry 1) 140 g0 x #<bx> y #<by> (preentry 2) 141 / g42 (cutter radius comp right of path) 142 g2 x #<ax> y #<ay> i #<vx> j #<vy> (arc entry) 143 #<xfinal_a> = [#<x2>] 144 #<yfinal_a> = [#<y2>] 145 (go along the 2-->3 line to exit) 146 (angle between 1-->2 and 2-->3) 147 (only necessary for acute angles) 148 #<angle> = [180 + #<phi23> - #<phi12>] 149 #<elen> = [#<r> / ABS[TAN[#<angle>/2]]] 150 #<k> = [#<elen>/#<len23>] 151 (print angle=#<angle> elen=#<elen> k=#<k>) 152 o<aaa20> if [#<k> GE 1] 153 (debug, ihex: can't get in final corner k=#<k> - EXITING) 154 (print, ihex: cant' get in final corner k=#<k> - EXITING) 155 (AXIS,notify, ihex: can't get in final corner - EXITING) 156 m2 157 o<aaa20> endif 158 #<xfinal_b> = [#<x2> + #<k> * #<len23> * #<cos23>] 159 #<yfinal_b> = [#<y2> + #<k> * #<len23> * #<sin23>] 160 g1 z #<zstart> (plunge) 161 o<aaa10> endif 162 x #<x2> y #<y2> z#<zcurrent> 163 x #<x3> y #<y3> 164 x #<x4> y #<y4> 165 x #<x5> y #<y5> 166 x #<x6> y #<y6> 167 x #<x1> y #<y1> 168 #<pass> = [#<pass> + 1] 169 o<dir00> else (dir EQ 3 CCW) 170 o<bbb10> if [#<pass> EQ 1] 171 (arc entry along line4-1 where corner 1 is obtuse) 172 #<ax> = [#<x1> + 1 * #<r> * cos[#<phi16>]] (entry) 173 #<ay> = [#<y1> + 1 * #<r> * sin[#<phi16>]] 174 #<bx> = [#<ax> - 2 * #<r> * sin[#<phi16>]] (preentry 1) 175 #<by> = [#<ay> + 2 * #<r> * cos[#<phi16>]] 176 #<cx> = [#<bx> + #<r> * cos[#<phi16>]] (preentry 2) 177 #<cy> = [#<by> + #<r> * sin[#<phi16>]] 178 #<vx> = [0 + #<r> * sin[#<phi16>]] (r vector) 179 #<vy> = [0 - #<r> * cos[#<phi16>]] 180 g0 x #<cx> y #<cy> (preentry 1) 181 g0 x #<bx> y #<by> (preentry 2) 182 / g41 (cutter radius comp left of path) 183 g3 x #<ax> y #<ay> i #<vx> j #<vy> (arc entry) 184 #<xfinal_a> = [#<x6>] 185 #<yfinal_a> = [#<y6>] 186 (go along the 4-->3 line to exit) 187 (angle between 4-->3 and 1-->4) 188 (only necessary for acute angles) 189 #<angle> = [180 - #<phi16> + #<phi65>] 190 #<elen> = [#<r> / ABS[TAN[#<angle>/2]]] 191 #<k> = [#<elen>/#<len65>] 192 o<bbb20> if [#<k> GE 1] 193 (debug, ihex: cant get in corner k=#<k> - EXITING) 194 (print, ihex: cant get in corner k=#<k> - EXITING) 195 (AXIS,notify, ihex: cant get in corner - EXITING) 196 m2 197 o<bbb20> endif 198 #<xfinal_b> = [#<x6> + 1.01* #<k> * #<len65> * #<cos65>] 199 #<yfinal_b> = [#<y6> + 1.01* #<k> * #<len65> * #<sin65>] 200 g1 z #<zstart> (plunge) 201 o<bbb10> endif 202 x #<x6> y #<y6> z#<zcurrent> 203 x #<x5> y #<y5> 204 x #<x4> y #<y4> 205 x #<x3> y #<y3> 206 x #<x2> y #<y2> 207 x #<x1> y #<y1> 208 #<pass> = [#<pass> + 1] 209 o<dir00> endif 210 211 o<wh010> endwhile 212 213 g1 x #<xfinal_a> y #<yfinal_a> 214 g1 x #<xfinal_b> y #<yfinal_b> 215 216 g0 z #<zsafe> 217 g40 218 o<ihex> endsub