Originally Posted by
gjvander
Would you mind posting a snippet of code to show how you do that?
Sure, although I've gotta warn you that it's kinda hard to read. This particular code was picked quickly from a big messy pile of old code; don't rely on it in to be bug-free! Also note that my style of using conditional execution branching causes fits for mach3's preview window, so the display is wonky, but the code executes as intended. This particular part doesn't have the math included for the roughing-cut adjustments, but if you can figure out what the code here is doing, you can figure out how to use the appropriate measurement to implement this pretty easily.
Code:
(*** BEGIN COPYRIGHT NOTICE. {7 text lines, including these two delimiting lines} ****)
(*** E2K 16-slot fixture wrapper, Copyright 2009, E2K Engineering, Inc. All rights reserved. ****)
(*** Permission granted for limited private reuse of this code in whole or part, provided ****)
(*** this entire copyright notice remains prominently included in all derived files. ****)
(*** Republication of this code, or portions thereof, is prohibited without authorization. ****)
(*** For republishing rights or commercial reuse permission, contact [email protected] ****)
(*** END COPYRIGHT NOTICE. {7 text lines, including these two delimiting lines} ****)
(*** This file is used as a generic template for designs cut on the)
(*** E2K 16-slot fixture )
( This parameter table is used to describe the EPM-1 16-part fixture )
( This fixture consists of two rows [along x] of 8 columns [along y])
( of parts, each held about 1 inch apart, with variances for mount holes, etc.)
(IsHere? X origin Y origin Z origin )
(initial table fixture offsets with nominal values)
#800 = -.1 #801 = 0.0 #802 = 0.0 #803 = 1.9
#810 = -.1 #811 = 0.0 #812 = 1.95 #813 = 1.9
#820 = -.1 #821 = 2.0 #822 = 0.0 #823 = 1.9
#830 = -.1 #831 = 2.0 #832 = 1.95 #833 = 1.9
#840 = -.1 #841 = 4.0 #842 = 0.0 #843 = 1.9
#850 = -.1 #851 = 4.0 #852 = 1.95 #853 = 1.9
#860 = -.1 #861 = 6.0 #862 = 0.0 #863 = 1.9
#870 = -.1 #871 = 6.0 #872 = 1.95 #873 = 1.9
#880 = -.1 #881 = 10.0 #882 = 0.0 #883 = 1.9
#890 = -.1 #891 = 10.0 #892 = 1.95 #893 = 1.9
#900 = -.1 #901 = 12.0 #902 = 0.0 #903 = 1.9
#910 = -.1 #911 = 12.0 #912 = 1.95 #913 = 1.9
#920 = -.1 #921 = 14.0 #922 = 0.0 #923 = 1.9
#930 = -.1 #931 = 14.0 #932 = 1.95 #933 = 1.9
#940 = -.1 #941 = 16.0 #942 = 0.0 #943 = 1.9
#950 = -.1 #951 = 16.0 #952 = 1.95 #953 = 1.9
(*********** Here is the main code section of the program ***********)
(**** First we probe the fixture to find out where everything is located ****)
m6 t99 g43 h99
#100 = 0 (the current fixture number is the main index loop variable)
M98 P100 L16 (probe all of the 16 fixtures)
(*** Now we have a table of parameters giving part fixture offsets ***)
(**** Next switch to 1/4" end mill and rough cut the top half of each part ****)
M6 T3 G43 H3 (select 1/4" 4-flute HSS end mill)
m3 s1450 f14 m8
g04 p4
#100 = 0
M98 P400 L16 (cut top half of each part with 1/4" mill)
(**** Now make pretty finishing cuts with the chamfering tool ****)
m6 t15 g43 h15 (switch to indexed chamfering mill)
m3 s742 f4 m8
g04 p4
#100 = 0
M98 P440 L16 (run chamfer tool once around each part)
(**** That's it for now*****)
m5 m9
g00 z 4
M30
(*************** Here are the subroutines that do all the real work *********)
(****************************************************************************)
O100 (probe for part location and store origin and presence info)
#201 = [800 + #100 * 10] (table row index for nominal locations of current part)
#301 = [600 + #100 * 10] (table row index for measured results of curent part)
#101 = #[#201 + 1] (get nominal part x left, in fixture coordinates)
#102 = #[#201 + 2] (get nominal part y front, in fixture coordinates)
#103 = #[#201 + 3] (get nominal part z top, in fixture coordinates)
g00 z [#103 + 0.3]
g00 x [#101 - 0.2] y [#102 + 0.25]
g00 z [#103 - 0.3]
g31 x [#101 + 0.1] f 5
g00 x [#101 - 0.15]
(Determine whether part is present by comparing probe result with destination)
(if we are within 0.005 of our probe destination, then no trip)
(set the result in parameter 3 as zero for part not present, or one for present)
#3 = [ROUND[ 0.498 + ABS[#101 + 0.1 - #2000]]]
M98 P[101 + #3 ] (now either finish probing part or move on to next)
#100 = [#100 + 1] (increment the primary loop index variable)
M99 (end of O100 subroutine)
(**************************************************************************)
O101 ( part not present - record results and move on )
#[#301 + 0] = 0 (flag part not present in table)
M99 (end of O101 subroutine)
(**************************************************************************)
O102 ( part is present - probe and record exact location)
#[#301 + 0] = 1 (flag part is present in table)
#[#301 + 1] = #2000 (store part x origin)
g00 y [#102 - 0.2]
g00 x [#101 + 0.25]
g31 y [#102 + 0.1] f 5
#[#301 + 2] = #2001 (store part y origin)
g00 y [#102 - 0.2]
g00 z [#103 + 0.3]
g00 y [#102 + 0.25]
g31 z [#103 - 0.2] f 2
#[#301 + 3] = #2002 (store part z top of stock)
g00 z [#103 + 0.2 ]
g10 L2 P[#100+10] X #[#301 + 1] Y #[#301 + 2] Z 0 (store fixture offsets for x&y)
M99 (end of O102 subroutine)
(**************************************************************************)
( this code is used to cut the top portion of the EPM1 prismatic shoe part)
(raw stock is presumed to be 1.9"x1"x1", inside a holder .7" deep)
(**************************************************************************)
(Main loop of the individual part rough cutting with 1/4" tool, top half)
O400
(first face off the top in two passes)
#84 = 0.0375 (z cut increment)
#87 = [1.9 - #84] (starting z cut depth)
g00 z 2.2
M98 P406 L2 (call the top facing routine to remove 0.075")
(now for the prism rough cutting)
(use depth interval of 0.025", each depth pass is .025" further away from center )
(prism extends from 1.825" down to 1.575")
(for the first pass, we leave 0.5" top square + 0.050" perimeter for chamfering)
(leave x,y=0.200-0.800 for pass 1 at z=1.800"; path is 0.100-0.900)
(leave x,y=0.050-0.950 for pass 9 at z=1.600"; path is -0.075-1.075)
#81 = 0.100 (first pass low side)
#82 = 0.900 (first pass high side)
#84 = 0.025 (axial cut depth increment)
#87 = 1.800 (current z depth)
M98 P407 L9 (call the prism rough cut subroutine)
g00 x 0.2 y -0.2 g00 z 1.85
#84 = 0.050 (axial cut depth increment)
#86 = 0.15625 (radius of corner relief)
#87 = 1.55 (current z cut depth)
g00 x #86 y -0.135 z #87
M98 P410 L5 (call the bottom left cornering routine to z=1.175)
g00 x -0.15
#87 = 1.55
g00 x -0.15 y [1.0 - #86] z #87
M98 P411 L5 (call the top left cornering routine to z=1.175)
g00 x -0.15
g00 y 1.15
#87 = 1.55
g00 x [1.0 - #86] y 1.15 z #87
M98 P412 L5 (call the top right cornering routine to z=1.175)
g00 x 1.15
#87 = 1.55
g00 x 1.2 y #86 z #87
M98 P413 L5 (call the bottom right cornering routine to z=1.175)
g00 y -0.15
g00 x -0.15 y -0.15 z 2
m5 m9
g0 z 4
m99
(********Th-Th-Th-That's all, folks*******)
(subroutine to face off the top of stock)
O406
g00 x 0.1 y -0.15
g00 z #87
g01 y 0.9
g01 x 0.9
g01 y 0.1
g01 x 0.3
g01 y 0.7
g01 x 0.7
g01 y 0.3
g01 x 0.45
g01 y 0.45
g01 x 0.55
g01 y 0.55
g00 z [#87 + 0.010]
g00 x 0.15 y -0.15
#87 = [#87 - #84]
M99
(subroutine to rough cut the prismatic tops in expanding squares)
O407
g00 z #87
g00 x #81 y -0.15
g01 y #82
g01 x #82
g01 y #81
g01 x #81
g00 y -0.15
#81 = [#81 - #84]
#82 = [#82 + #84]
#87 = [#87 - #84]
M99
(subroutine to make bottom left corner cuts)
O410
g01 x #86 y -0.125
g02 x -0.125 y #86 i 0 j #86
g00 x -0.15
#87 = [#87 - #84]
g00 z #87
g01 x -0.125
g03 x #86 y -0.125 i #86 j 0
g00 y -0.15
#87 = [#87 - #84]
g00 z #87
M99
(subroutine to make top left corner cuts)
O411
g00 x -0.125 y [1.0 - #86] z #87
g02 x #86 y 1.125 i #86 j 0
g00 y 1.15
#87 = [#87 - #84]
g00 z #87
g00 y 1.125
g03 x -0.125 y [1.0 - #86] i 0 j [0 - #86]
g00 x -0.15
#87 = [#87 - #84]
g00 z #87
M99
(subroutine to make top right corner cuts)
O412
g00 x [1.0 - #86] y 1.125 z #87
g02 x 1.125 y [1.0 - #86] i 0 j [0-#86]
g00 x 1.15
#87 = [#87 - #84]
g00 z #87
g00 x 1.125
g03 x [1.0 - #86] y 1.125 i [0-#86] j 0
g00 y 1.15
#87 = [#87 - #84]
g00 z #87
M99
(subroutine to make bottom right corner cuts)
O413
g00 x 1.125 y #86 z #87
g02 x [1.0 - #86] y -0.125 i [0-#86] j 0
g00 y -0.15
#87 = [#87 - #84]
g00 z #87
g00 y -0.125
g03 x 1.125 y #86 i 0 j #86
g00 x 1.15
#87 = [#87 - #84]
g00 z #87
M99
(subroutine to setup part fixture and call chamfer cut path sub)
O440
#77 = [0.375 + 0.008] (chamfer tool radius at bottom, 0.625 at wide point)
#87 = [1.575 - 0.005] (cut from the bottom of chamfer)
G59 P[#100 + 10]
M98 P450 L1
M99
(subroutine to run chamfer tool once around the block)
O450
g00 z #87
g01 x [0 - #77 - 0.05] y [0 - #77]
g01 x [1 + #77]
g01 y [1 + #77]
g01 x [0 - #77]
g01 y [0 - #77 - 0.05]
g00 x [0 - #77 - 0.05]
g00 z 2
M99
O949
g00 x-0.5 y0 z0
g02 x-0.5 y0 z0 i0.5 j0
g00 x0 y0 z0
m99