Perl script to make an encoder mounting plate

I am making the encoder mounting plates, on my manual mill, However, if I had a CNC mill, it would be easier. I was writing perl scripts to
generate G codes, making some "building block" functions that perform common milling tasks. Their examples are "drilling with optional pecking", milling out a round through hole (also plunging by steps, not the whole depth), etc.
To see a drawing and specifications of encoder mounting plate, go here:
http://igor.chudov.com/projects/Bridgeport-Series-II-Interact-2-CNC-Mill/08-Spreadsheet/
and in the spreadsheet, select "Encoder mounts".
Just for the sake of fun, I wrote a script to generate G-Code to make encoder mounts from rectangular parts. It outputs 400 lines of G-code (also attached). I would not use this script, since I would already have made all encoder plates, so I wrote this script for entertainment. I will give it a try, however.
This is ALL untested, but as soon as I have a Z axis working, I will test it, at first various pieces separately. I will also add code to round the corners of the mounting plates instead of having them square in shape.
##################################################################### script #!/usr/bin/perl
use strict; use warnings;
use GCodeMacros;
g_wait_for_tool( 'Center Drill' );
g_set_clear_height( 0 );
# Start Motor Mounting Holes with center drill g_drill_rectangle_pattern( 0.629, 0.6915, 3.2459, 3.3084, -0.1, 5 );
# Start Encoder Mounting Holes with center drill g_drill_hole( 1.5811, 1.794, -0.1 ); g_drill_hole( 2.2938, 1.794, -0.1 ); g_drill_hole( 1.9375, 2.4115, -0.1 );
# Mill a hole for motor shaft, 17.02mm. g_wait_for_tool( '3/16 inch end mill' ); g_mill_through_hole( 1.9375, 2, 17.02/g_inch, -5/8, 3/16 );
# Drill Motor Mounting Holes g_wait_for_tool( '5/32 inch drill bit' ); g_drill_rectangle_pattern( 0.629, 0.6915, 3.2459, 3.3084, -5/8, 5, 0.1);
# Drill Encoder Mounting Holes g_wait_for_tool( '#43 drill bit' ); g_drill_hole( 1.5811, 1.794, -5/8, 0.1 ); g_drill_hole( 2.2938, 1.794, -5/8, 0.1 ); g_drill_hole( 1.9375, 2.4115, -5/8, 0.1 );
g_end;
###################################################################### G-Code (WAITING FOR TOOL: Center Drill) M0
(Drilling a rectangle: [0.629, 0.6915], [0.629, 3.3084]) (Drill a hole in [0.629, 0.6915] depth of -0.1.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X0.629 Y0.6915 ) G00 X0.629 Y0.6915
(Drilling) (Mill to: Z-0.1 at speed F5 ) G01 Z-0.1 F5
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [0.629, 3.3084] depth of -0.1.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X0.629 Y3.3084 ) G00 X0.629 Y3.3084
(Drilling) (Mill to: Z-0.1 at speed F5 ) G01 Z-0.1 F5
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [3.2459, 3.3084] depth of -0.1.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X3.2459 Y3.3084 ) G00 X3.2459 Y3.3084
(Drilling) (Mill to: Z-0.1 at speed F5 ) G01 Z-0.1 F5
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [3.2459, 0.6915] depth of -0.1.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X3.2459 Y0.6915 ) G00 X3.2459 Y0.6915
(Drilling) (Mill to: Z-0.1 at speed F5 ) G01 Z-0.1 F5
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [1.5811, 1.794] depth of -0.1.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X1.5811 Y1.794 ) G00 X1.5811 Y1.794
(Drilling) (Mill to: Z-0.1 at speed F10 ) G01 Z-0.1 F10
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [2.2938, 1.794] depth of -0.1.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X2.2938 Y1.794 ) G00 X2.2938 Y1.794
(Drilling) (Mill to: Z-0.1 at speed F10 ) G01 Z-0.1 F10
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [1.9375, 2.4115] depth of -0.1.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X1.9375 Y2.4115 ) G00 X1.9375 Y2.4115
(Drilling) (Mill to: Z-0.1 at speed F10 ) G01 Z-0.1 F10
(Returning to safe height) (Go to point Z0 ) G00 Z0
(WAITING FOR TOOL: 3/16 inch end mill) M0
(Mill Thru Hole) G17 (Go to point Z0 ) G00 Z0
(Go to point X2.51382874015748 ) G00 X2.51382874015748
(Step 1 -- go down by 0.1875) (Mill to: Z-0.1875 at speed F2 ) G01 Z-0.1875 F2
(Mill Circle starting from point [angle 0]. G2 X1.36117125984252 R0.57632874015748 G2 X2.51382874015748 R0.57632874015748 (Step 2 -- go down by 0.1875) (Mill to: Z-0.375 at speed F2 ) G01 Z-0.375 F2
(Mill Circle starting from point [angle 0]. G2 X1.36117125984252 R0.57632874015748 G2 X2.51382874015748 R0.57632874015748 (Step 3 -- go down by 0.1875) (Mill to: Z-0.5625 at speed F2 ) G01 Z-0.5625 F2
(Mill Circle starting from point [angle 0]. G2 X1.36117125984252 R0.57632874015748 G2 X2.51382874015748 R0.57632874015748 (Final step 4 -- go down to final depth -0.625) (Mill to: Z-0.625 at speed F2 ) G01 Z-0.625 F2
(Mill Circle starting from point [angle 0]. G2 X1.36117125984252 R0.57632874015748 G2 X2.51382874015748 R0.57632874015748 (Go to point Z0 ) G00 Z0
(WAITING FOR TOOL: 5/32 inch drill bit) M0
(Drilling a rectangle: [0.629, 0.6915], [0.629, 3.3084]) (Drill a hole in [0.629, 0.6915] depth of -0.625.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X0.629 Y0.6915 ) G00 X0.629 Y0.6915
(Drilling with pecking)
(Peck 1 -- drill, clear chips, go back) (Mill to: Z-0.1 at speed F5 ) G01 Z-0.1 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.1 ) G00 Z-0.1
(Peck 2 -- drill, clear chips, go back) (Mill to: Z-0.2 at speed F5 ) G01 Z-0.2 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.2 ) G00 Z-0.2
(Peck 3 -- drill, clear chips, go back) (Mill to: Z-0.3 at speed F5 ) G01 Z-0.3 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.3 ) G00 Z-0.3
(Peck 4 -- drill, clear chips, go back) (Mill to: Z-0.4 at speed F5 ) G01 Z-0.4 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.4 ) G00 Z-0.4
(Peck 5 -- drill, clear chips, go back) (Mill to: Z-0.5 at speed F5 ) G01 Z-0.5 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.5 ) G00 Z-0.5
(Peck 6 -- drill, clear chips, go back) (Mill to: Z-0.6 at speed F5 ) G01 Z-0.6 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.6 ) G00 Z-0.6
(Last drilling step) (Mill to: Z-0.625 at speed F5 ) G01 Z-0.625 F5
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [0.629, 3.3084] depth of -0.625.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X0.629 Y3.3084 ) G00 X0.629 Y3.3084
(Drilling with pecking)
(Peck 1 -- drill, clear chips, go back) (Mill to: Z-0.1 at speed F5 ) G01 Z-0.1 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.1 ) G00 Z-0.1
(Peck 2 -- drill, clear chips, go back) (Mill to: Z-0.2 at speed F5 ) G01 Z-0.2 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.2 ) G00 Z-0.2
(Peck 3 -- drill, clear chips, go back) (Mill to: Z-0.3 at speed F5 ) G01 Z-0.3 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.3 ) G00 Z-0.3
(Peck 4 -- drill, clear chips, go back) (Mill to: Z-0.4 at speed F5 ) G01 Z-0.4 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.4 ) G00 Z-0.4
(Peck 5 -- drill, clear chips, go back) (Mill to: Z-0.5 at speed F5 ) G01 Z-0.5 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.5 ) G00 Z-0.5
(Peck 6 -- drill, clear chips, go back) (Mill to: Z-0.6 at speed F5 ) G01 Z-0.6 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.6 ) G00 Z-0.6
(Last drilling step) (Mill to: Z-0.625 at speed F5 ) G01 Z-0.625 F5
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [3.2459, 3.3084] depth of -0.625.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X3.2459 Y3.3084 ) G00 X3.2459 Y3.3084
(Drilling with pecking)
(Peck 1 -- drill, clear chips, go back) (Mill to: Z-0.1 at speed F5 ) G01 Z-0.1 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.1 ) G00 Z-0.1
(Peck 2 -- drill, clear chips, go back) (Mill to: Z-0.2 at speed F5 ) G01 Z-0.2 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.2 ) G00 Z-0.2
(Peck 3 -- drill, clear chips, go back) (Mill to: Z-0.3 at speed F5 ) G01 Z-0.3 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.3 ) G00 Z-0.3
(Peck 4 -- drill, clear chips, go back) (Mill to: Z-0.4 at speed F5 ) G01 Z-0.4 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.4 ) G00 Z-0.4
(Peck 5 -- drill, clear chips, go back) (Mill to: Z-0.5 at speed F5 ) G01 Z-0.5 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.5 ) G00 Z-0.5
(Peck 6 -- drill, clear chips, go back) (Mill to: Z-0.6 at speed F5 ) G01 Z-0.6 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.6 ) G00 Z-0.6
(Last drilling step) (Mill to: Z-0.625 at speed F5 ) G01 Z-0.625 F5
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [3.2459, 0.6915] depth of -0.625.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X3.2459 Y0.6915 ) G00 X3.2459 Y0.6915
(Drilling with pecking)
(Peck 1 -- drill, clear chips, go back) (Mill to: Z-0.1 at speed F5 ) G01 Z-0.1 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.1 ) G00 Z-0.1
(Peck 2 -- drill, clear chips, go back) (Mill to: Z-0.2 at speed F5 ) G01 Z-0.2 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.2 ) G00 Z-0.2
(Peck 3 -- drill, clear chips, go back) (Mill to: Z-0.3 at speed F5 ) G01 Z-0.3 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.3 ) G00 Z-0.3
(Peck 4 -- drill, clear chips, go back) (Mill to: Z-0.4 at speed F5 ) G01 Z-0.4 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.4 ) G00 Z-0.4
(Peck 5 -- drill, clear chips, go back) (Mill to: Z-0.5 at speed F5 ) G01 Z-0.5 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.5 ) G00 Z-0.5
(Peck 6 -- drill, clear chips, go back) (Mill to: Z-0.6 at speed F5 ) G01 Z-0.6 F5
(Go to point Z0 ) G00 Z0
(Go to point Z-0.6 ) G00 Z-0.6
(Last drilling step) (Mill to: Z-0.625 at speed F5 ) G01 Z-0.625 F5
(Returning to safe height) (Go to point Z0 ) G00 Z0
(WAITING FOR TOOL: #43 drill bit) M0
(Drill a hole in [1.5811, 1.794] depth of -0.625.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X1.5811 Y1.794 ) G00 X1.5811 Y1.794
(Drilling) (Mill to: Z-0.625 at speed F0.1 ) G01 Z-0.625 F0.1
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [2.2938, 1.794] depth of -0.625.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X2.2938 Y1.794 ) G00 X2.2938 Y1.794
(Drilling) (Mill to: Z-0.625 at speed F0.1 ) G01 Z-0.625 F0.1
(Returning to safe height) (Go to point Z0 ) G00 Z0
(Drill a hole in [1.9375, 2.4115] depth of -0.625.) (withdraw to safe height) (Go to point Z0 ) G00 Z0
(go to starting point) (Go to point X1.9375 Y2.4115 ) G00 X1.9375 Y2.4115
(Drilling) (Mill to: Z-0.625 at speed F0.1 ) G01 Z-0.625 F0.1
(Returning to safe height) (Go to point Z0 ) G00 Z0
(The End!) M2
Add pictures here
✖
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Ignoramus23878 wrote:

http://igor.chudov.com/projects/Bridgeport-Series-II-Interact-2-CNC-Mill/08-Spreadsheet/
You do know that there are G-codes for things like peck drill cycles? Take a look at G73, G83 and other "canned cycles".
Add pictures here
✖
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

I will look at that, yes. I had no idea. But I figure that scripts let me be in control. I just looked at G83 and was kind of surprised that it does exactly what I programmed, exactly the way I did it. I may switch to G83 for peck drilling, indeed. But on the other hand, I like my flexibility.
i
Add pictures here
✖
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
On Jul 20, 11:25 am, Ignoramus23878 <ignoramus23...@NOSPAM. 23878.invalid> wrote:

In that case, use your code as a Macro, and the control can alias a G83 to call your code. In fact, that IS how the machines do it. The common Macros may be compiled in the machine.
Does your Peck cycle have variables for how close it rapids back into the hole? Not just slamming down to the exact point where it last drilled?
Also, some machines have variations on the G83, so that you can also have a variable amount of peck in the cycle. The type of cycle is selected by the optional J word for example, also they may include an optional retract distance after the hole is complete, and optional retract distance during the peck cycle.
If you have the routine aliased to a G83 then you will be (more) compatible with the eventual CAD CAM system you will want/need.
Add pictures here
✖
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Iggy, there's another approach you should be aware of called parametric programming. Using variables, math operands, conditional statements, etc. small powerful Gcode programs can quickly be written. this little program has a nested loop and keeps the mill busy for over half an hour:
;TEETH,ADJUST TRUE SOFT JAWS ;set second jaw back 0.100", third back 0.200"
%LAPPER = 0 %ZDEPTH = 0.5000
%START: %COUNTER = 0 %ZDEPTH = %ZDEPTH + 0.025 *;DEPTH OF CUT FOR EACH PASS %LAPPER = %LAPPER + 1
G92 X 0.00 Y 0.00 Z %ZDEPTH G90 G00 X 0.000 Y -0.250 Z 0.00
%LOOP: %COUNTER = %COUNTER + 1
G42 T 02 G01 X 0.008 Y 0.000 F 3.0 G01 X 0.122 Y 0.000 G03 X 0.096 Y 0.750 I -1.304 J 0.330 G01 X 0.000 Y 0.750 G02 X 0.008 Y 0.000 I -3.986 J -0.420 G01 X 0.008 Y -0.125 G01 G 40 X 0.2857 Y -0.25 G92 X 0.000 Y -0.25 Z 0.00
IF (%COUNTER LE 9) GOTO %LOOP
G54 G00 X 0.00 Y 0.00 Z 0.00
IF (%LAPPER LE 5) GOTO %START *;DO ALL TEETH 5 TIMES
Add pictures here
✖
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Looks interesting. What I know is that I have to learn all about this, but I am not yet sure if this is the way I want to use G codes.
i
Add pictures here
✖
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.