Face_Grooving - rmu75/linuxcnc-wiki GitHub Wiki
date: '2015-06-30T21:52:42' title: G74_-_Peck_Drilling/Face Grooving wiki_parent: G74 - Peck Drilling
(Page started 2015/06/27 Kirk Wallace)
... [RS274NGC] ... # REMAPPING REMAP=g74 modalgroup=1 argspec=xzk py=g740 ... [PYTHON] TOPLEVEL = python/toplevel.py PATH_PREPEND = python ...
#!/usr/bin/pythonimport remap
#!/usr/bin/pythonfrom interpreter import INTERP_OK import math
def g740(self, **words): # G74 is typically called like so: # G74 x ? z ? k ? (x = diameter, usually 0; z = hole endpoint; k = peck length)
<span style="color: #60a0b0; font-style: italic"># get position</span> <span style="color: #007020; font-weight: bold">if</span> (<span style="color: #007020">self</span><span style="color: #666666">.</span>params[<span style="color: #4070a0">'_lathe_diameter_mode'</span>]): <span style="color: #60a0b0; font-style: italic"># if is_lathe_mode</span> x_mode <span style="color: #666666">=</span> <span style="color: #40a070">2</span> <span style="color: #007020; font-weight: bold">else</span>: x_mode <span style="color: #666666">=</span> <span style="color: #40a070">1</span> x_start <span style="color: #666666">=</span> <span style="color: #007020">self</span><span style="color: #666666">.</span>params[<span style="color: #40a070">5420</span>] <span style="color: #666666">*</span> x_mode z_start <span style="color: #666666">=</span> <span style="color: #007020">self</span><span style="color: #666666">.</span>params[<span style="color: #40a070">5422</span>] <span style="color: #007020; font-weight: bold">if</span> <span style="color: #4070a0">'x'</span> <span style="color: #007020; font-weight: bold">in</span> words: x_end <span style="color: #666666">=</span> words[<span style="color: #4070a0">'x'</span>] <span style="color: #666666">*</span> x_mode <span style="color: #007020; font-weight: bold">else</span>: x_end <span style="color: #666666">=</span> x_start <span style="color: #666666">*</span> x_mode <span style="color: #007020; font-weight: bold">if</span> <span style="color: #4070a0">'z'</span> <span style="color: #007020; font-weight: bold">in</span> words: z_end <span style="color: #666666">=</span> words[<span style="color: #4070a0">'z'</span>] <span style="color: #007020; font-weight: bold">if</span> z_end <span style="color: #666666">></span> z_start: <span style="color: #007020; font-weight: bold">return</span> <span style="color: #4070a0">"G74 error - Z cannot be larger than the starting Z position"</span> <span style="color: #007020; font-weight: bold">else</span>: z_end <span style="color: #666666">=</span> z_start <span style="color: #007020; font-weight: bold">if</span> <span style="color: #4070a0">'k'</span> <span style="color: #007020; font-weight: bold">in</span> words: peck_length <span style="color: #666666">=</span> words[<span style="color: #4070a0">'k'</span>] <span style="color: #007020; font-weight: bold">if</span> peck_length <span style="color: #666666"><</span> <span style="color: #40a070">0</span>: <span style="color: #007020; font-weight: bold">return</span> <span style="color: #4070a0">"G74 error - K cannot be negative"</span> <span style="color: #007020; font-weight: bold">else</span>: peck_length <span style="color: #666666">=</span> <span style="color: #40a070">0</span> <span style="color: #007020; font-weight: bold">if</span> (<span style="color: #007020">self</span><span style="color: #666666">.</span>params[<span style="color: #4070a0">'_metric'</span>]): <span style="color: #60a0b0; font-style: italic"># if is_metric</span> backoff_length <span style="color: #666666">=</span> <span style="color: #40a070">0.50</span> <span style="color: #60a0b0; font-style: italic"># mm</span> rounding_fudge <span style="color: #666666">=</span> <span style="color: #40a070">0.0001</span> <span style="color: #007020; font-weight: bold">else</span>: backoff_length <span style="color: #666666">=</span> <span style="color: #40a070">0.020</span> <span style="color: #60a0b0; font-style: italic"># inch</span> rounding_fudge <span style="color: #666666">=</span> <span style="color: #40a070">0.00001</span> z_range <span style="color: #666666">=</span> math<span style="color: #666666">.</span>fabs(z_end <span style="color: #666666">-</span> z_start) <span style="color: #666666">-</span> rounding_fudge <span style="color: #60a0b0; font-style: italic"># rounding_fudge prevents extra peck</span> <span style="color: #007020; font-weight: bold">if</span> peck_length <span style="color: #666666">></span> <span style="color: #40a070">0</span>: num_pecks <span style="color: #666666">=</span> <span style="color: #007020">int</span>(z_range <span style="color: #666666">/</span> peck_length) <span style="color: #007020; font-weight: bold">else</span>: num_pecks <span style="color: #666666">=</span> <span style="color: #40a070">0</span> z_list <span style="color: #666666">=</span> [] <span style="color: #007020; font-weight: bold">for</span> i <span style="color: #007020; font-weight: bold">in</span> <span style="color: #007020">range</span>(num_pecks <span style="color: #666666">+</span> <span style="color: #40a070">1</span>): z_list<span style="color: #666666">.</span>append(z_start <span style="color: #666666">-</span> (i <span style="color: #666666">*</span> peck_length)) z_list<span style="color: #666666">.</span>append(z_end) <span style="color: #60a0b0; font-style: italic">#print "--kaw - z_list =", z_list</span> <span style="color: #007020; font-weight: bold">if</span> math<span style="color: #666666">.</span>fabs(x_end <span style="color: #666666">-</span> x_start) <span style="color: #666666">></span> rounding_fudge: <span style="color: #60a0b0; font-style: italic"># We're groove'n</span> <span style="color: #007020; font-weight: bold">for</span> i <span style="color: #007020; font-weight: bold">in</span> <span style="color: #007020">range</span>(num_pecks <span style="color: #666666">+</span> <span style="color: #40a070">1</span>): <span style="color: #007020">self</span><span style="color: #666666">.</span>execute(<span style="color: #4070a0">"G0 Z </span><span style="color: #70a0d0; font-style: italic">%s</span><span style="color: #4070a0">"</span> <span style="color: #666666">%</span> z_list[i]) <span style="color: #007020">self</span><span style="color: #666666">.</span>execute(<span style="color: #4070a0">"G1 Z </span><span style="color: #70a0d0; font-style: italic">%s</span><span style="color: #4070a0">"</span> <span style="color: #666666">%</span> z_list[i <span style="color: #666666">+</span> <span style="color: #40a070">1</span>]) <span style="color: #007020">self</span><span style="color: #666666">.</span>execute(<span style="color: #4070a0">"G1 X </span><span style="color: #70a0d0; font-style: italic">%s</span><span style="color: #4070a0">"</span> <span style="color: #666666">%</span> x_end) <span style="color: #007020">self</span><span style="color: #666666">.</span>execute(<span style="color: #4070a0">"G1 Z </span><span style="color: #70a0d0; font-style: italic">%s</span><span style="color: #4070a0">"</span> <span style="color: #666666">%</span> (z_list[i] <span style="color: #666666">+</span> backoff_length)) <span style="color: #007020">self</span><span style="color: #666666">.</span>execute(<span style="color: #4070a0">"G0 X </span><span style="color: #70a0d0; font-style: italic">%s</span><span style="color: #4070a0">"</span> <span style="color: #666666">%</span> x_start) <span style="color: #007020; font-weight: bold">else</span>: <span style="color: #60a0b0; font-style: italic"># We're drilling</span> <span style="color: #007020; font-weight: bold">for</span> i <span style="color: #007020; font-weight: bold">in</span> <span style="color: #007020">range</span>(num_pecks <span style="color: #666666">+</span> <span style="color: #40a070">1</span>): <span style="color: #007020">self</span><span style="color: #666666">.</span>execute(<span style="color: #4070a0">"G1 Z </span><span style="color: #70a0d0; font-style: italic">%s</span><span style="color: #4070a0">"</span> <span style="color: #666666">%</span> z_list[i <span style="color: #666666">+</span> <span style="color: #40a070">1</span>]) <span style="color: #007020">self</span><span style="color: #666666">.</span>execute(<span style="color: #4070a0">"G0 Z </span><span style="color: #70a0d0; font-style: italic">%s</span><span style="color: #4070a0">"</span> <span style="color: #666666">%</span> (z_list[i <span style="color: #666666">+</span> <span style="color: #40a070">1</span>] <span style="color: #666666">+</span> backoff_length)) <span style="color: #007020">self</span><span style="color: #666666">.</span>execute(<span style="color: #4070a0">"G0 Z </span><span style="color: #70a0d0; font-style: italic">%s</span><span style="color: #4070a0">"</span> <span style="color: #666666">%</span> z_start) <span style="color: #007020; font-weight: bold">return</span> INTERP_OK
The G74 routine above relies on an initial move to a starting position. This position is captured and used for x_start and z_start. The X and Z words in the G74 command are used for x_end and z_end. If x_start and x_end are equal, this invokes a plunge with chip break routine, otherwise a grooving routine is invoked. Since Python can round off floating point numbers, a "close enough" algorithm is use to test x_start and x_end equality. A check for peck_length > 0 is used to prevent a divide by zero error in the num_pecks calculation. Apparently, the x position parameter 5420 does not follow the lathe diameter mode, so we need to check for it and adjust x values. This needs testing, so beware. The z_range is adjusted a tiny bit so that an extra peck doesn't get added to the end. The peck algorithm counts the number of full pecks in z-range then adds a final z position of z_end. If the peck length fits evenly in z_range, the last full peck will happen to be at z_end, which we don't need because it's added later.
Peter Smid's book "CNC Programming Handbook, 3rd Edition" Page 222, covering G74 was used as a reference: https://books.google.com/books?id=w7-jBgAAQBAJ&pg=PA222
Parameters are:
X = Optional. Leaving X off or setting it equal to the start position invokes a face plunge with chip break routine, usually used for drilling or face plunge grooving. For grooving, this is the end X position. The X start position is were the tool was just before invoking G74. Grooving will need a tool that can cut on its side. Care is needed in limiting the area of the side cut by limiting the K peck depth value. The X value will need to be adjusted by the cutter width to get the desired groove width. In other words: groove width = (x_end - x_start) + cutter width. Z = Required. Z is the Z endpoint, or hole or face groove depth. The start position is were the tool was just before invoking G74. K = Required. The peck length. Pecks start from the Z start position. The last peck length is the distance between the z endpoint and the last full peck length.
![]() |
(G74 Peck Drilling Example) G7 (Dia. Mode) G18 (XZ Plane) G90 (Absolute Distance Mode) G40 (Turn Cutter Compensation Off) G21 (units in inches) G54 (Work Offset) (G74 Grooving Example)
o<g740>sub The above could use some input parameter checking. The loop does a needless back-off if the the peck length fits evenly in the Z range. Maybe a while z_target > z_end loop would be better. #!/usr/bin/python |
