Skip to content

Commit 46ef984

Browse files
authored
Merge pull request #40 from toolpath/maker_macro
Maker macro
2 parents 49d8aba + 077de46 commit 46ef984

30 files changed

Lines changed: 2295 additions & 2 deletions

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,57 @@ After you have loaded the tool, if no M argument (default) or an M1 argument is
623623

624624
Example MDI Command: G65 "UNLOAD" T10
625625

626-
626+
## Maker Macro Usage
627+
628+
These macros, in their base form with human readable file names, must be put in the top level of whatever program you want to run.
629+
Typically this means leaving them in the root folder of the machine and running all programs from there.
630+
Though you could keep copies of these macros in sub-folders to run from them if you want.
631+
632+
Some users may want to use the `maker_macro_m##` feature of the control.
633+
This lets you put files with that naming convention into the `maker_macros` folder on the control,
634+
and then call those macros via an Mcode from any folder.
635+
636+
If you do this, then instead of calling --- for example -- `G65 "PROBEBORE"` you instead call `M810`.
637+
So its up to you to remember the mapping somehow.
638+
639+
We've provided a python script that converts all the named files into the maker macro format for you.
640+
That file, `build_maker_macros.py` can be run to convert all macros into the maker_macro format.
641+
The script places all the new files inside the `maker_macro` folder.
642+
Note that the script first DELETES EVERYTHING inside that folder, so do not make any manual edits to those files.
643+
They will be lost.
644+
Any edits need to be made in the top level macro files, and then propagated to the `maker_macro_m##` files via the
645+
build script.
646+
647+
The mapping of file name to maker_macro is:
648+
649+
'CALIBRATEPROBEBLOCK':801,
650+
'CALIBRATEPROBERING':802,
651+
'CALIBRATEPROBEZ':803,
652+
'CALIBRATETOOLSET':804,
653+
'CHECKPOSITIONALTOLERANCE':805,
654+
'COMPZEROPOINT':806,
655+
'COPYWCS':807,
656+
'FINDCOR':808,
657+
'LOADTOOL':809,
658+
'PROBEBORE':810,
659+
'PROBECIRCULARBOSS':811,
660+
'PROBECONFIG':812,
661+
'PROBEINSIDECORNER':813,
662+
'PROBERECTANGULARBOSS':814,
663+
'PROBEY':815,
664+
'PROBEYWEB':816,
665+
'PROBEXSLOT':817,
666+
'PROBEPOCKET':818,
667+
'UNLOADTOOL':819,
668+
'PROBEXYANGLE':820,
669+
'PROBEOUTSIDECORNER':821,
670+
'PROBEXWEB':822,
671+
'PROBEYSLOT':823,
672+
'PROBEX':824,
673+
'TOOLSET':825,
674+
'PROTECTEDMOVE':826,
675+
'SAFESPIN':827,
676+
'PROBEZ':828
627677

628678
## TODO
629679

@@ -633,7 +683,6 @@ Example MDI Command: G65 "UNLOAD" T10
633683
- Add a macro to check min/max values against soft-limits (would also like to add this to my post processor)
634684
- Add probe runout compensation into the calibration: Rotate the spindle 180 degrees with M19P180. Then re-do calibration and compare results to compute runout. Need to figure out the math for how to compensate for it during probing.
635685
- Add probe Angle routines (i.e. probe a wall and compute its angle, so you can rotate the X/Y axes)
636-
- Add 4th Axis probing routines
637686
- Add wear comp macros or wear comp to existing macros
638687

639688

build_maker_macros.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import os
2+
import sys
3+
import re
4+
5+
6+
MACRO_FILES_NAME_MAP = {
7+
'CALIBRATEPROBEBLOCK':801,
8+
'CALIBRATEPROBERING':802,
9+
'CALIBRATEPROBEZ':803,
10+
'CALIBRATETOOLSET':804,
11+
'CHECKPOSITIONALTOLERANCE':805,
12+
'COMPZEROPOINT':806,
13+
'COPYWCS':807,
14+
'FINDCOR':808,
15+
'LOADTOOL':809,
16+
'PROBEBORE':810,
17+
'PROBECIRCULARBOSS':811,
18+
'PROBECONFIG':812,
19+
'PROBEINSIDECORNER':813,
20+
'PROBERECTANGULARBOSS':814,
21+
'PROBEY':815,
22+
'PROBEYWEB':816,
23+
'PROBEXSLOT':817,
24+
'PROBEPOCKET':818,
25+
'UNLOADTOOL':819,
26+
'PROBEXYANGLE':820,
27+
'PROBEOUTSIDECORNER':821,
28+
'PROBEXWEB':822,
29+
'PROBEYSLOT':823,
30+
'PROBEX':824,
31+
'TOOLSET':825,
32+
'PROTECTEDMOVE':826,
33+
'SAFESPIN':827,
34+
'PROBEZ':828
35+
}
36+
37+
38+
MAKER_MACRO_FOLDER = 'maker_macros'
39+
40+
41+
########################################################
42+
# Helper functions
43+
########################################################
44+
45+
# we'll use these regex's a lot, so we want to precompile them
46+
# instead of building them on the fly each time
47+
def build_regexs(name_map):
48+
"""
49+
make a precompiled regex for each macro file
50+
and store it with the macro name and new number.
51+
"""
52+
regex_map = []
53+
for name, number in name_map.items():
54+
pattern = re.compile(r'(G65\s+")' + re.escape(name) + r'(")')
55+
regex_map.append((name, number, pattern))
56+
57+
return regex_map
58+
59+
60+
def find_all_caps_no_ext(directory="."):
61+
"""
62+
Return a list of filenames in the specified directory that:
63+
- Have no file extension.
64+
- Have a name that is entirely uppercase letters.
65+
"""
66+
matching_files = []
67+
# Loop through all entries in the directory
68+
for filename in os.listdir(directory):
69+
full_path = os.path.join(directory, filename)
70+
# Ensure that we're checking only files, not directories.
71+
if os.path.isfile(full_path):
72+
# Split the filename into base and extension
73+
base, ext = os.path.splitext(filename)
74+
# Check for no extension and all uppercase letters in the base name.
75+
if ext == "" and base and base == base.upper():
76+
matching_files.append(filename)
77+
return matching_files
78+
79+
80+
########################################################
81+
# Build the make_macro_m## files
82+
########################################################
83+
84+
#empty out the maker_macro folder of any existing file
85+
86+
# Loop through all entries in the folder
87+
for filename in os.listdir(MAKER_MACRO_FOLDER):
88+
file_path = os.path.join(MAKER_MACRO_FOLDER, filename)
89+
# Check if it is a file (ignoring directories)
90+
if os.path.isfile(file_path):
91+
os.remove(file_path)
92+
93+
MACRO_TO_MAKER_MACRO_LIST = build_regexs(MACRO_FILES_NAME_MAP)
94+
95+
for (file_name, file_m_number, _) in MACRO_TO_MAKER_MACRO_LIST:
96+
# Read the file contents
97+
# print ("editing ", file_name)
98+
with open(file_name, 'r') as file:
99+
content = file.read()
100+
101+
# fond all instances of G65 calls and replace with M calls
102+
for (name, m_number, pattern) in MACRO_TO_MAKER_MACRO_LIST:
103+
# Replace occurrences of the old file name with the new one
104+
content = pattern.sub(f'M{m_number}', content)
105+
106+
# write the new maker macro file
107+
file_path = os.path.join(MAKER_MACRO_FOLDER, f'maker_macro_m{file_m_number}')
108+
with open(file_path, "w") as file:
109+
# print("writing ", file_path)
110+
file.write(content)
111+
112+
113+
###################################################################
114+
# Testing to make sure we didn't miss any files, or add extra ones
115+
###################################################################
116+
117+
# Compare computed file list to the dictionary keys by converting both to sets.
118+
computed_files_set = set(find_all_caps_no_ext())
119+
provided_files_set = set(MACRO_FILES_NAME_MAP.keys())
120+
121+
macro_files_found = find_all_caps_no_ext()
122+
123+
# MACROS in the folder, but missing from the MAP
124+
missing_files = computed_files_set - provided_files_set
125+
# MACROS in the map, but missing from the folder
126+
extra_files = provided_files_set - computed_files_set
127+
128+
if missing_files:
129+
print('###############################################################')
130+
print("ERROR: The MACRO_FILES_NAME_MAP is missing the following files: ")
131+
for name in missing_files:
132+
print(' ', name)
133+
print('###############################################################')
134+
print()
135+
if extra_files:
136+
print('###############################################################')
137+
print("ERROR: The MACRO_FILES_NAME_MAP has following non existent files: ")
138+
for name in extra_files:
139+
print(' ', name)
140+
print('###############################################################')
141+
print()
142+
# give a return code of 1 so the test fail
143+
if (missing_files or extra_files):
144+
print("Self Tests Failed")
145+
sys.exit(1)

maker_macros/maker_macro_m801

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2024 Toolpath Labs Inc., Justin Gray, and Josh Smith
2+
3+
// CALIBRATE PROBE TIP DIAMETER
4+
5+
// #1 is the expected X length of the artifact
6+
// #2 is the expected Y length of the artifact
7+
// #3 is the Z drop height
8+
9+
10+
G90 G94 G17 G49 G40 G80
11+
G20 // inch
12+
13+
// load probe config
14+
M812
15+
16+
M19 // ORIENT SPINDLE
17+
18+
// important local variables
19+
#100 = @100 // TOOL NUMBER PROVIDED BY PROBECONFIG MACRO
20+
21+
// Make sure diameter is zero when calibrating
22+
W_TOOL_DATA[0,#100,3,0] // store tool diameter
23+
24+
25+
// calling web probe macros macros to measure the rectangle
26+
M822 A0 B#1 C#3 Q0
27+
M816 A0 B#2 C#3 Q0
28+
29+
#131 = @998 // stored value of the measured X distance
30+
#132 = @999 // stored valued of the measured Y distance
31+
32+
#133 = #1-#131 // error in x
33+
#134 = #2-#132 // error in y
34+
#135 = ABS[#133 + #134]/2 // average error
35+
W_TOOL_DATA[0,#100,3,#135] // store tool diameter
36+
37+
MENU_ADD["Ruby Diameter Set To: #135",""];
38+
MENU["CALIBRATION REPORT","RESULTS","",1];
39+
40+
M20 // UNLOCK SPINDLE ORIENTATION FOR SAFETY
41+
G90
42+
M99

maker_macros/maker_macro_m802

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2024 Toolpath Labs Inc., Justin Gray, and Josh Smith
2+
3+
// CALIBRATEDIAMETER
4+
// Description: Calibrate the Diameter of the probe using a ring guage
5+
// Initial coding 1/14/2024: Joshua Smith
6+
// Your probe must be concentric and you must use a ring guage!!!!!!!!!!
7+
// #1 is the expected DIAMETER of the artifact
8+
9+
// load probe config
10+
M812
11+
12+
M19 // ORIENT SPINDLE
13+
14+
// important local variables
15+
#100 = @100 // TOOL NUMBER PROVIDED BY PROBECONFIG MACRO
16+
17+
// Make sure diameter is zero when calibrating
18+
W_TOOL_DATA[0,#100,3,0] // store tool diameter
19+
20+
// calling our slot macros the first time centers probe
21+
M817 A0 B#1 Q0
22+
M823 A0 B#1 Q0
23+
24+
25+
// calling our slot macros a second time gives an accurate inspection
26+
M817 A0 B#1 Q0
27+
M823 A0 B#1 Q0
28+
29+
// average Diameter calculation
30+
// @999 and @998 are set in the slot macros
31+
// this could be improved by keeping track of both X and Y diameters and controling probe orientation
32+
#131 = @998 // measured ring guage diameter in x
33+
#132 = @999 // measured ring guage diameter in y
34+
#133 = #1-#131 // error in x
35+
#134 = #1-#132 // error in y
36+
#135 = ABS[#133 + #134]/2 // average error
37+
W_TOOL_DATA[0,#100,3,#135] // store tool diameter
38+
39+
MENU_ADD["Ruby Diameter Set To: #135",""];
40+
MENU["CALIBRATION REPORT","RESULTS","",1];
41+
42+
M20 // UNLOCK SPINDLE ORIENTATION FOR SAFETY
43+
G90
44+
M99

maker_macros/maker_macro_m803

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2024 Toolpath Labs Inc., Justin Gray and Josh Smith
2+
3+
// CALIBRATEZ
4+
// THIS MACRO ASSUMES THAT YOU HAVE PUT YOUR GAUGE TOOL IN THE SPINDLE
5+
// AND MANUALLY JOGGED UP TILL YOUR REFERENCE ARTIFACT CAN JUST BARELY SLIDE UNDER THE TOOL.
6+
// THE MACRO WILL SAVE THE XY LOCATION FOR FUTURE USE AND STORE THE REFERENCE HEIGHT OFFSET
7+
8+
// Argument A -> turns on/off full calibration: default is quick calibration
9+
10+
// load probe config
11+
M812
12+
13+
M19 // ORIENT SPINDLE
14+
15+
// important local variables
16+
#100 = @100 // TOOL NUMBER PROVIDED BY PROBECONFIG MACRO
17+
18+
#108 = @108 // PROBE BACKOFF DISTANCE PROVIDED BY PROBECONFIG MACRO
19+
20+
#104 = @104 // FAST PROBE SPEED PROVIDED BY PROBECONFIG MACRO
21+
#105 = @105 // SLOW PROBE SPEED PROVIDED BY PROBECONFIG MACRO
22+
#106 = @106 // PROBE CLEARANCE DISTANCE
23+
#108 = @108 // PROBE BACKOFF DISTANCE
24+
#109 = @109 // MASTER TOOL GAUGE LENGTH
25+
// NOTE: @5109 will be used to save reference block height
26+
#111 = @111 // PROBE CALIBRATION EXTENDED WORKOFFSET NUMBER
27+
28+
IF [#1!=#0]
29+
MSG_OK["CALIBRATE PROBE", "ZERO MASTER GAUGE TOOL ON CALIBRATION ARTIFACT AND LEAVE IT THERE",""]
30+
31+
@5109 = R_MACH_COOR[0,3] // GET MACHINE Z COORDINATE WHICH SHOULD BE THE TOP OF A 123 BLOCK
32+
#120 = @5109
33+
34+
// STORE THE CURRENT POSITION TO G54P99 FOR FUTURE FAST CALIBRATION
35+
W_G54EXP_COOR[0,#111,1,R_MACH_COOR[0,1]]
36+
W_G54EXP_COOR[0,#111,2,R_MACH_COOR[0,2]]
37+
ELSE // FAST CALIBRATION
38+
MSG_OK["CALIBRATE PROBE", "INSTALL CALIBRATION ARTIFACT IN REFERENCE LOCATION",""]
39+
END_IF
40+
41+
#120 = @5109 // PREVIOUSLY STORED REFERENCE HEIGHT
42+
43+
44+
// COMMAND A TOOL CHANGE
45+
T#100 M6 // BRING THE MACHINE UP TO TOOL CHANGE HEIGHT
46+
G28 G91 Z0.
47+
#121 = R_MACH_COOR[0,3] // GET MACHINE Z COORDINATE AFTER TOOL CHANGE
48+
49+
IF [#1!=#0]
50+
// TELL THE PERSON TO PUT THE PROBE INTO THE SPINDLE
51+
MSG_OK["INSTALL PROBE", "SWITCH TO MPG MODE AND INSTALL THE PROBE THEN SWITCH BACK AND HIT CYCLE START; T#100",""]
52+
END_IF
53+
54+
G54P#111 // LOCATION OF PROBE CALIBARTION IS X0 Y0 ON G54P#111
55+
56+
G90 G0 X0. Y0. // MOVE TO TOOLSETTER
57+
58+
#123 = #120 - #109 // DELTA DISTANCE WE HAVE MOVED PLUS SOME INCASE PROBE IS SHORTER THAN GAUGE TOOL
59+
// Probe Z ALL THE WAY BACK TO 123 BLOCK
60+
G31 G91 P2 Z[#123] F#104
61+
62+
// Check that the probe has triggered
63+
IF[R_SKIP[0,1] == 1]
64+
65+
66+
67+
G91 G01 Z[#108] // BACK OFF
68+
FIX_CUT_OR_ON
69+
G31 G91 P2 Z-[1.5*108] F#105 // PROBE Z AT SLOW SPEED
70+
FIX_CUT_OR_OFF
71+
#125 = R_SKIP[0,203] // GET MACHINE Z COORDINATE
72+
G91 G01 Z[#108] // BACK OFF
73+
#126 = [#125-#120+#109] // PROBE LENGTH CALCULATION, ACCOUNTING FOR GAUGE TOOL LENGTH
74+
W_TOOL_DATA[0,#100,203,#126] // STORE PROBE LENGTH
75+
76+
ELSE
77+
ALARM["FAILED TO PROBE PART WITHIN SPECIFIED DISTANCE"]
78+
END_IF
79+
80+
G28 G91 Z0.
81+
82+
M20 // UNLOCK SPINDLE ORIENTATION FOR SAFETY
83+
G90
84+
M99

0 commit comments

Comments
 (0)