586,131 active members*
2,601 visitors online*
Register for free
Login
IndustryArena Forum > Machine Controllers Software and Solutions > Fanuc > Tool Offset Macro needing an extra set of eyes
Results 1 to 14 of 14
  1. #1
    Join Date
    Feb 2009
    Posts
    64

    Tool Offset Macro needing an extra set of eyes

    I am working on a macro to quickly set Tool Length offsets .
    The program I have here uses 2 options for A. 1 - records tool lengths from a standard, 2 - sets offsets from part. B is the number of tools.

    %
    O99999
    (TOOL LENGTH OFFSET MACRO)
    (SET A EQ 1. TO READ ORIGIN)
    (SET A EQ 2. TO SET OFFSET)
    (SET B EQ TO NUMBER OF TOOLS)

    IF [[ROUND[#1] NE 1] AND [ROUND[#1] NE 2]] GOTO 9101;
    IF [#2 LE 2] GOTO 9102;
    IF [ROUND[#1] EQ 1] GOTO 1;
    IF [ROUND[#1] EQ 2] GOTO 2;




    N1 #32 = #2;
    #103 = [#2001];
    #101 = 1;
    WHILE [#32 GT 0] DO1;
    #[100 + #101] = [ #[2000 + #101]]; <----- gives illegal macro variable
    #101 = #101 +1;
    #32 = #32 -1;
    END1;
    GOTO 9999;

    N2 #32 = #2;
    #103 = #103 - [#2001];
    #101 =2;
    WHILE [#32 GT 0] DO1;
    #[2000 +#101] = [#[100 + #101] + #103];
    #101 = #101 + 1;
    #32 = #32 -1;
    END1;
    GOTO 9999;

    N9101 #3000 = 101 (EITHER 1 OR 2);
    N9102 #3000 = 102 (AT LEAST 2 TOOLS);

    N9999 M99;
    %

    I am getting an illegal macro variable reference at the indicated line starting when #101 = 2;
    Please help. When I use the same program but change it to the 2200 range for wear offset I get no error.

  2. #2
    Join Date
    Feb 2006
    Posts
    338
    Oops I see it now. Took a bit.
    #101 = 1
    #[100 + #101] = [ #[2000 + #101]];

    Resolves to:
    #[100 + 1] = [#[2000 + 1]];
    #101 = #2001

    Your counter is now = to the value of #2001
    Which this incraments
    #101 = #101 + 1

    You need to replace #101 in the counter loops with say #31 or something

    Dale

  3. #3
    Join Date
    Feb 2009
    Posts
    64
    The only thing I thought was that the #101 =1 line is outside of the DO/WHILE Loop. If I change the values to #[100 + 101] = [#[2100+#101]] I get no error. Same with [#[2200+#101]] but those are not the tool length offsets, they are wear offsets.


    Quote Originally Posted by dpuch View Post
    Oops I see it now. Took a bit.
    #101 = 1
    #[100 + #101] = [ #[2000 + #101]];

    Resolves to:
    #[100 + 1] = [#[2000 + 1]];
    #101 = #2001

    Your counter is now = to the value of #2001
    Which this incraments
    #101 = #101 + 1

    You need to replace #101 in the counter loops with say #31 or something

    Dale

  4. #4
    Join Date
    Feb 2009
    Posts
    64
    ... And I need the variable to remain after power - off.

    Quote Originally Posted by James L View Post
    The only thing I thought was that the #101 =1 line is outside of the DO/WHILE Loop. If I change the values to #[100 + 101] = [#[2100+#101]] I get no error. Same with [#[2200+#101]] but those are not the tool length offsets, they are wear offsets.

  5. #5
    Join Date
    Jun 2008
    Posts
    1511
    What model control are you using?

    I know it won't matter but try removing the brackets. #[100 + #101] = #[2000 + #101] you don't need them anyway.

    You are sure that you can set the geometry and wear by saying in MDI #2005=1, #2205=1 this changes the offset and wear of tool 5 to 1?

    You are on a machining center correct??

    Stevo

  6. #6
    Join Date
    Feb 2009
    Posts
    64

    Control

    I'm just running this on a HAAS simulator. I can enter the code #2001 = 5; and it sets it with no problem. I did try removing the brackets before. The only weird thing about it is I can use the program as written to do wear offsets. I think I have a calculation issue somewhere. Frustrating but I think I'll get it working sometime today.

  7. #7
    Join Date
    Jun 2008
    Posts
    1511
    James,
    Depuch was correct with the issue that you are having. You are trying to set a tool offset length to your counter of #101 and it is getting all mugged up. So let’s run it through just 1 round of calculations. We will say that tool 1 offset is 10.3968 and tool 2 offset is 15.645.

    #101=1
    WHILE
    #[100+#101]=[#[2000+#101]]----#101 is now equal to 10.3968
    #101=#101+1----#101 is now equal to 11.3968 then it jumps back to the previous line and trys to set #111.3968
    END1

    I would use as Depuch suggested #31 or something other than the #100’s. Or you can change your #100 to say #110 as long as you won’t set more than 10 tools.

    I am a bit confused on exactly what you are trying to accomplish. All I see this program doing is setting variables equal to tool offsets at the N1 and then resetting the tool offsets back equal to the variables in N2. What exactly does this accomplish? Can you not just set your tool length in the geometry and leave it until you change or break a tool?

    You say you are running this in the Haas simulator? Are you going to be running this in a Haas or a Fanuc control??

    Stevo

  8. #8
    Join Date
    Feb 2009
    Posts
    64
    Yeah, I saw that error also. The idea behind this macro -which was for practice more than anything else - was to record all the tool lengths initially. After they are set by running the macro with A = 1 their initial lengths are referenced. The next step would be to touch off tool # 1 on a workpiece and record the offset in the normal way. Then you run the macro with A=2 and it will reset the remaining tool lengths based on the difference between tool 1's second length minus tool 1's first length. If tool 1 were an indicator for example and all tools were set off a reference point then the macro could be used to accurately and quickly reset offsets when changing out multiple parts.

  9. #9
    Join Date
    Feb 2009
    Posts
    64
    %
    O99999
    (TOOL LENGTH OFFSET MACRO)
    (SET A EQ 1. TO READ ORIGIN)
    (SET A EQ 2. TO SET OFFSET)
    (SET B EQ TO NUMBER OF TOOLS)

    IF [[ROUND[#1] NE 1] AND [ROUND[#1] NE 2]] GOTO 9101;
    IF [ROUND[#2] LT 2] GOTO 9102;
    IF [ROUND[#1] EQ 1] GOTO 1;
    IF [ROUND[#1] EQ 2] GOTO 2;




    N1 #32 = #2;
    #199 = [#2001];
    #101 = 0;
    #33 =1;
    WHILE [#32 GT 0] DO1;
    #[100 + #33] = #[2000 + #33];
    #33 = #33 +1;
    #32 = #32 -1;
    END1;
    GOTO 9999;

    N2 #32 = #2;
    #199 = [#2001] - #199;
    #100 =0;
    #33 = 2;
    WHILE [#32 GT 0] DO1;
    #[2000 +#33] = [#[100 + #33] + #199];
    #33 = #33 + 1;
    #32 = #32 -1;
    END1;
    GOTO 9999;

    N9101 #3000 = 101 (EITHER 1 OR 2);
    N9102 #3000 = 102 (AT LEAST 2 TOOLS);

    N9999 M99;
    %



    There it goes

  10. #10
    Join Date
    Feb 2009
    Posts
    64
    and an oops again.. works only for 1 setting. working on an addition to fix that

  11. #11
    Join Date
    Feb 2009
    Posts
    64
    %
    O99999
    (TOOL LENGTH OFFSET MACRO)
    (SET A EQ 1. TO READ ORIGIN)
    (SET A EQ 2. TO SET OFFSET)
    (SET B EQ TO NUMBER OF TOOLS)

    IF [[ROUND[#1] NE 1] AND [ROUND[#1] NE 2]] GOTO 9101;
    IF [ROUND[#2] LT 2] GOTO 9102;
    IF [ROUND[#1] EQ 1] GOTO 1;
    IF [ROUND[#1] EQ 2] GOTO 2;




    N1 #32 = #2;
    #199 = [#2001];
    #101 = 0;
    #33 =1;
    WHILE [#32 GT 0] DO1;
    #[100 + #33] = #[2000 + #33];
    #33 = #33 +1;
    #32 = #32 -1;
    END1;
    GOTO 9999;

    N2 #32 = #2;
    #198 = #2001 - #199;
    #100 =0;
    #33 = 2;
    WHILE [#32 GT 0] DO1;
    #[2000 +#33] = #[100 + #33] + #198;
    #33 = #33 + 1;
    #32 = #32 -1;
    END1;
    GOTO 9999;

    N9101 #3000 = 101 (EITHER 1 OR 2);
    N9102 #3000 = 102 (AT LEAST 2 TOOLS);

    N9999 M99;
    %

    that does it...

  12. #12
    Join Date
    Jun 2008
    Posts
    1511
    James,
    I would be careful of doing it this way. You are always relying on the fact that a tool never needs to be offset again. A lot could potentially go wrong with constantly changing and resetting tool offsets. The easiest practice is to offset your tools to a known position like the table or vise face. Then when changing out parts just put the part height in the work coordinates G54-G59 or program the part height.

    However if you choose to do it this way I would combine the macro to do everything all at once. What you initially have to do is offset all of your tools then run a quick 1 time macro to store all of the tool offsets in variables #101-?. Now you just re offset tool 1 when setting up a new job into the geometry and run the program below. You could even set it up to use a custom M or G code to call the program. I would set all of the tool lengths not just the ones that you want to use. If you are going to use a macro why not change every tool to fit the part on the machine.

    O99999(TOOL LENGTH OFFSET MACRO)
    #30=1---counter for tool offset setting
    #31=2---counter for variable storage of tool offset
    #32=[#2001-#101]---difference between new offset of tool 1 and old offset of tool 1
    WHILE[#30LT50]DO1---will set 50 tools. change to suit the number of tools you have offsets for
    #[2000+#31]=#[100+#31]-[#32]---sets new tool geometry to tool 2(tool 1 is already set manually)
    #[100+#30]=#[2000+#30]---sets variable storage of tool 1 to new offset
    #30=#30+1
    #31=#31+1
    END1
    M99

    I did not test run it.

    Edit--missed your last post....see you got it to work. Good job!!

    Stevo

  13. #13
    Join Date
    Feb 2006
    Posts
    338
    Ok, I found these macros. They are for a Hitachi Seiki machine with a Fanuc 15MB control. Not a lot of comments, but this is what was provided by the machine tool builder.

    If someone wants to wrap (ok warp) their mind around all those variables and better document it...

    As I recall it is based around the O9010 set as G100 which then calls the rest as needed. It supports measuring at and angle and distance from the tool centerline for large tools. As well as a tolerance that triggers resetting the tool if it is too far off, and broken tool detection.

    This was setup to use a skip function with a touch sensor.

    ... and I see a call for O8074, but it isn't in there. I hope that was an option we didn't have.


    Code:
    O8050(TOOL CHECK CONST)
    #1 = #1
    N1 #15 = 1 (SKIP)
    N3 #27 = 1/#9 (TOLERANCE)
    N4 #12 = 2500/#9 (ROUGH TOUCH FEED)
    N5 #14 = 1/#9 (ROUGH TOUCH BACK)
    N6 #29 = #511 (SENSOR POS.X)
    N7 #30 = #512 (SENSOR POS.Y)
    N8 #32 = #509 (SENSOR POS.Z)
    N9 #11 = 60/#9 (MIN SENSIBLE LENGTH)
    M99
    
    O8053(TOOL BROKEN NG)
    #142 = #142-FIX[#142]
    N1 M86
    IF [#5 LE 1] GOTO 195
    M99
    N195
    #3000 = 195 (TOOL BROKEN NG)
    
    O9010(G100 V6.2 92- 2)
    #2 = 4
    SETVN509 (TLSENS.Z,PRINTON,TLSENS.X,TLSENS.Y)
    SETVN549 (MACROALM)
    IF [#4 EQ #0] GOTO 3
    #9 = 505-24*#4006
    M98 P8050
    #3 = 1
    IF [#20 EQ 1] GOTO 6
    IF [#15 LT 1] GOTO 2
    #3 = [#140 MOD #15]+1
    IF [#3 EQ 1] GOTO 6
    N2 IF [#142-FIX[#142] GE .08] GOTO 5
    M99
    N3IF [#18 LT 1] GOTO 4
    G65 P9013 R509. T#18 U#21 X#24 W#23 Z#26 J195. E#8
    N4 M99
    N5 #3 = 0
    N6 #12 = #18 GT 0
    N10 #5 = #[#2]
    IF [FIX[#5] NE #5] GOTO 181
    IF [#5 LT 1] GOTO 181
    #32 = #26
    IF [#26 NE #0] GOTO 11
    #32 = 10000
    N11 #27 = [1-FUP[#17]]*10000
    N24 IF [#12 LE 0] GOTO 25
    G65 P9013 R509. T#18 U#5 Z#26 J195. V4641. E#8
    #12 = #0
    N25 #6 = #[#2+3-FIX[#2/31]*34]
    IF [#6 GT 0] GOTO 30
    #6 = #21
    N30 IF [#6-FIX[#6] NE 0] GOTO 181
    G65 P9013 R#27 T#5 U#6 X#24 W#23 Z#32 J1. V4641. E#8
    N41 #2 = #2+3
    IF [#2 GT 33] GOTO 50
    IF [#[#2] NE #0] GOTO 10
    N50 M41
    M99
    N181 M41
    #3000 = 181 (G100 I NOT CORRECT)
    N195
    #3000 = 195 (REFERENCE TOOL NG)
    
    O9013(G103 V6.2 92- 2)
    G40 M9
    #9 = 505-24*#4006
    G80 G90 G0 M5
    #28 = #4311
    #1 = 0
    IF [#22 EQ 4641] GOTO 10
    IF [#18 EQ 509] GOTO 10
    #1 = 1
    N10 #145 = #0
    WHILE [FIX[#4012-66]*FIX[#4014-66] EQ 0] DO 1
    G67
    END1
    G53
    G49 X#5041 Y#5042 Z#5043
    G30 Z#5003 M19
    M98 P9180
    IF [#7 EQ #0] GOTO 11
    T#7
    N11 IF [#5 NE #0] GOTO 35
    M99
    N35 IF [FIX[#5] NE #5] GOTO 181
    IF [#20 NE #0] GOTO 38
    #6 = #28
    N38 IF [#6 GE 1] GOTO 39
    #6 = #4400
    N39 IF [#6 LT 1] GOTO 187
    #2 = 0
    N36 M98 P8050
    M74
    G53 G90 G0 X[#29+#24] Y[#30+#23]
    IF [#26 EQ #0] GOTO 37
    #27 = #26
    N37 #145 = #0
    #549 = 0
    G53
    #31 = #5043
    #15 = #5043-#5023+#32+#11
    IF [[#18-10000]*[#18-509] EQ 0] GOTO 40
    #15 = #5043-#5023+#32+#[2000+8000*[#6 GT 200]+#6]+#[[2200+8800*[#6 GT 200]+#6]*#514*[#6 GE 1]]-6/#9
    N40 #19 = #5023-#5043
    M40
    #3004 = 2
    G31 Z#15 F#12
    IF [ABS[#5063-#31] LT #14] GOTO 198
    G1Z[#5063+#14]F[1000/#9]
    IF [ABS[#5063-#15] LT .01/#9] GOTO 191
    #16 = #5063-1/#9
    #3 = 1
    WHILE [#3 LE 4] DO 1
    G53
    #17 = #5043
    G31 Z#16 F[200/#9]
    IF [ABS[#5063-#17] LT .05/#9] GOTO 199
    G1 Z[#5063+1./#9] F[400/#9]
    #141 = ABS[#31-#5063]
    IF [#141 LE #27*#1/10] GOTO 41
    IF [#141 LE .02005/#9] GOTO 41
    #31 = #5063
    #3 = #3+1
    END1
    #145 = #145 OR 1
    N41 G1 Z[[#31+#5063]/2+10/#9] F[2000/#9]
    #3004 = 0
    #10= FUP[#9/2.5]*1000
    #31 = [#31+#5063]/2
    #144 = #19+#31-#509
    #144 = ROUND[#144*#10]/#10
    IF [#141 LE #27*#1/5] GOTO 411
    IF [#141 GT .03/#9] GOTO 192
    N411 IF [ABS[#144-#[2000+8000*[#6 GT 200]+#6]-#[[2200+8800*[#6 GT 200]+#6]*#514*[#6 GE 1]]] LE #27+.000005] GOTO 43
    #145 = #145 OR 2
    N43 IF [#145 LE 0] GOTO 44
    #2 = #2+1
    IF [#2 LT 2] GOTO 36
    IF [#145 GE 2] GOTO 90
    N44 G90 G30 Z#5003
    IF [#18 NE 10000] GOTO 45
    #[2000+8000*[#6GT200]+#6] = #144
    IF [#514 LT 1] GOTO 46
    #[2200+8800*[#6GT200]+#6] = 0
    GOTO 46
    N45 IF [#18 NE 509] GOTO 46
    #509 = #19+#31-#[2000+8000*[#6 GT 200]+#6]-#[[2200+8800*[#6 GT 200]+#6]*#514*[#6 GE 1]]
    #509 = ROUND[#509*#10]/#10
    #144 = #[2000+8000*[#6 GT 200]+#6]
    N46#4=41
    IF [#22 EQ 4641] THEN #4 = #0
    G30 X#5001 Y#5002 M#4
    G49
    IF [#8 LE 0] GOTO 60
    M98 P8074
    N60 M99
    N191 #3004 = 0
    #144 = 0
    #145 = 191
    IF [[#18-10000]*[#18-509] EQ 0] GOTO 291
    N90 IF [#145 EQ 3] GOTO 192
    #549 = 195
    G90 G30 Z#5003
    G30 X#5001 Y#5002 M41
    IF [#8 LE 0] GOTO 91
    M98 P8074
    N91 M98 P8053
    M99 P#5
    N291 #549 = 191
    G30 Z#5003
    M41
    #3000 = 191 (TOUCH SIGNAL NOT RECEIVED)
    N192 #549 = 192
    G30 Z#5003
    M41
    #3000 = 192 (TOOL LENGTH SENSOR ERROR)
    N198 #3004 = 0
    #549 = 198
    G30 Z#5003
    M41
    #3000 = 198 (G100/G103 TOUCH SIGNAL ON)
    N199 #3004 = 0
    #549 = 199
    G30 Z#5003
    M41
    #3000 = 199 (G100/G103 SENSOR BROKEN)
    N181
    #3000 = 181 (G103 J NOT CORRECT)
    N187
    #3000 = 187 (H CODE NOT FOUND)
    
    O9015 (G105 WORK COUNT)
    #140 = #140+1
    M99
    
    O9180(TOOL CALL)
    #6 = #20
    #7 = #21
    IF [#20 EQ #0] GOTO 13
    IF [0+#20 EQ 0] GOTO 3
    N8 IF [#6 LT 1] GOTO 183
    GOTO 3
    N13 IF [#5 NE #0] GOTO 15
    N3 G30 X#5001 Y#5002
    IF [#6 EQ #0] GOTO 15
    T#6 M6
    #149 = #6
    N15 IF [#21 EQ #0] GOTO 19
    IF [#21 EQ 0] GOTO 19
    IF [#21 EQ #20] GOTO 20
    N18 IF [#7 LT 1] GOTO 183
    GOTO 19
    N20 #7 = #0
    N19 M99
    N183
    #3000 = 183 (TOOL NO. NOT FOUND)
    %

  14. #14
    Join Date
    Feb 2009
    Posts
    64
    That was what it was meant for. We're getting a part that is used to set length offsets with high precision and I wanted a way to maintain that precision when working with various parts. First set all the offsets to a reference and then run macro with A=1. Next you just touch off tool 1 and record it then run macro with A=2. As far as the number of tools I am a big fan of counters for some reason and I just liked the added control.





    Quote Originally Posted by stevo1 View Post
    James,
    I would be careful of doing it this way. You are always relying on the fact that a tool never needs to be offset again. A lot could potentially go wrong with constantly changing and resetting tool offsets. The easiest practice is to offset your tools to a known position like the table or vise face. Then when changing out parts just put the part height in the work coordinates G54-G59 or program the part height.

    However if you choose to do it this way I would combine the macro to do everything all at once. What you initially have to do is offset all of your tools then run a quick 1 time macro to store all of the tool offsets in variables #101-?. Now you just re offset tool 1 when setting up a new job into the geometry and run the program below. You could even set it up to use a custom M or G code to call the program. I would set all of the tool lengths not just the ones that you want to use. If you are going to use a macro why not change every tool to fit the part on the machine.

    O99999(TOOL LENGTH OFFSET MACRO)
    #30=1---counter for tool offset setting
    #31=2---counter for variable storage of tool offset
    #32=[#2001-#101]---difference between new offset of tool 1 and old offset of tool 1
    WHILE[#30LT50]DO1---will set 50 tools. change to suit the number of tools you have offsets for
    #[2000+#31]=#[100+#31]-[#32]---sets new tool geometry to tool 2(tool 1 is already set manually)
    #[100+#30]=#[2000+#30]---sets variable storage of tool 1 to new offset
    #30=#30+1
    #31=#31+1
    END1
    M99

    I did not test run it.

    Edit--missed your last post....see you got it to work. Good job!!

    Stevo

Similar Threads

  1. Changing tool diameter in the tool offset screen
    By Vern Smith in forum Haas Mills
    Replies: 22
    Last Post: 05-09-2022, 05:25 PM
  2. Sinumeric Offset Value macro
    By sanjeevlj in forum Mastercam
    Replies: 3
    Last Post: 05-06-2009, 11:05 AM
  3. tool offset macro
    By cnc-king in forum Fanuc
    Replies: 6
    Last Post: 09-22-2008, 04:43 AM
  4. macro program for work offset
    By cncwhiz in forum Fanuc
    Replies: 4
    Last Post: 12-14-2007, 01:28 PM
  5. Macro for positive offset
    By qmas99 in forum Uncategorised CAM Discussion
    Replies: 0
    Last Post: 02-12-2006, 04:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •