So, far the parameters are: :x = (not used) :z = The z endpoint. The start point is from the previous move. :k = The peck length. Pecks start from the Z start point. The last peck length is the distance between the z endpoint and the last full peck length. |
<span style="color: #007020; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">sys</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">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> |
z_range <span style="color: #666666">=</span> z_end <span style="color: #666666">-</span> z_start <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>(math<span style="color: #666666">.</span>fabs(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_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> |
<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) |
</pre></div> |
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. I need to add checks for valid x, z, and k values, such as, the z parameter value must be less than the z start position, k can not be negative. Remap has a feature that flags whether a parameter is optional or required, which I have not addressed yet. |
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. |
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. <html> <table> <tr> <td><img src="http://wiki.linuxcnc.org/uploads/Screenshot_G74_Peck_Drill-1.png"></td> <td> <!-- HTML generated using hilite.me --><div style="background: #f0f0f0; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">(G74 Peck Drilling Example) G7 (Dia<span style="color: #666666">.</span> Mode) G18 (XZ Plane) G90 (Absolute Distance Mode) G40 (Turn Cutter Compensation Off) G21 (units <span style="color: #007020; font-weight: bold">in</span> inches) G54 (Work Offset) G30 Z <span style="color: #60a0b0; font-style: italic">#5422 (Park Tool)</span> T <span style="color: #40a070">0707</span> S <span style="color: #40a070">500</span> (RPM) M8 (Coolant ON) M3 (Spindle ON, Forward) G0 X <span style="color: #40a070">0.000</span> G0 Z <span style="color: #40a070">25.000</span> G74 Z <span style="color: #40a070">0.000</span> K <span style="color: #40a070">8</span> F <span style="color: #40a070">200</span> M9 (Coolant OFF) M5 (Spindle OFF) G30 Z <span style="color: #60a0b0; font-style: italic">#5422 (Park Tool)</span> M30 (End of Program) </pre></div> </td> <td><p> </p></td> <td><img src="http://wiki.linuxcnc.org/uploads/Screenshot_G74_Face_Groove-1.png"></td> <td> <!-- HTML generated using hilite.me --><div style="background: #f0f0f0; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">(G74 Grooving Example) G7 (Dia<span style="color: #666666">.</span> Mode) G18 (XZ Plane) G90 (Absolute Distance Mode) G40 (Turn Cutter Compensation Off) G21 (units <span style="color: #007020; font-weight: bold">in</span> inches) G54 (Work Offset) G30 Z <span style="color: #60a0b0; font-style: italic">#5422 (Park Tool)</span> T <span style="color: #40a070">0707</span> S <span style="color: #40a070">500</span> (RPM) M8 (Coolant ON) M3 (Spindle ON, Forward) G0 X <span style="color: #40a070">10.000</span> G0 Z <span style="color: #40a070">20.000</span> G74 X <span style="color: #40a070">25.000</span> Z <span style="color: #40a070">10.000</span> K <span style="color: #40a070">3</span> F <span style="color: #40a070">200</span> M9 (Coolant OFF) M5 (Spindle OFF) G30 Z <span style="color: #60a0b0; font-style: italic">#5422 (Park Tool)</span> M30 (End of Program) </pre></div> </td> </tr> <tr> <td colspan=3>Peck Drill Example</td> <td colspan=2>Grooving Example</td> </tr> </table> </html> |
<span style="color: #60a0b0; font-style: italic">#"""</span> |
<span style="color: #60a0b0; font-style: italic">#"""</span> <span style="color: #4070a0; font-style: italic">"""</span> <span style="color: #4070a0; font-style: italic"> z_target = z_start - ((i + 1) * peck_length)</span> <span style="color: #4070a0; font-style: italic"> self.execute("G1 Z %s" % z_target)</span> <span style="color: #4070a0; font-style: italic"> z_backoff = z_target + backoff_length</span> <span style="color: #4070a0; font-style: italic"> self.execute("G0 Z %s" % z_backoff)</span> <span style="color: #4070a0; font-style: italic"> self.execute("G1 Z %s" % z_end)</span> <span style="color: #4070a0; font-style: italic"> self.execute("G0 Z %s" % z_start)</span> <span style="color: #4070a0; font-style: italic"> #"""</span> |
There are two sets of motion command blocks. One block uses g-code commands which get interpreted and converted to lower level machine commands. The other uses the low level commands directly. Remove the # in front of the begging #""" to comment the block of code out, or add # to the beginning """ to comment the block in. |