585,761 active members*
4,010 visitors online*
Register for free
Login
IndustryArena Forum > Machine Controllers Software and Solutions > Fanuc > Macro for finding hole center with 3 points
Results 1 to 15 of 15
  1. #1
    Join Date
    Aug 2011
    Posts
    92

    Macro for finding hole center with 3 points

    Hey guys,

    I recently bought a 3d taster that I have been using in my Fanuc 10M mori mv-40b.

    I would like to figure out a macro that allows me to input the position of 3 spots to calculate the center of a circle and load it to work offset.

    Does anyone have any ideas or suggestions?

    I found this code on another site

    %
    O9081(CIRCLE THROUGH 3 POINTS MACRO)
    #3006=1 (MAN TOUCH 1 - CYCLE START)
    #3006=0
    #1=#5021 (1ST X)
    #2=#5022 (1ST Y)
    #3006=1 (MAN TOUCH 2 - CYCLE START)
    #3006=0
    #3=#5021 (2ND X)
    #4=#5022 (2ND Y)
    #3006=1 (MAN TOUCH 3 - CYCLE START)
    #3006=0
    #5=#5021 (3RD X)
    #6=#5022 (3RD Y)

    (GET PERPENDICULAR BISECTOR OF #1, #2 and #3, #4)
    #7 = [#3 + #1] / 2
    #8 = [#4 + #2] / 2
    #9 = #3 - #1
    #10 = -[#4 - #2]

    (GET PERPENDICULAR BISECTOR OF #3, #4 and #5, #6)
    #11 = [#5 + #3] / 2
    #12 = [#6 + #4]/ 2
    #13 = #5 - #3
    #14 = -[#6 - #4]

    (SEE WHERE THE LINE INTERSECT)
    (X-CENTRE)
    #15 = [#8 * #10 * #14 + #11 * #10 * #13 - #7 * #9 * #14 - #12 * #10 * #14] / [#10 * #13 - #9 * #14]

    (Y-CENTRE)
    #16 = [#15 - #7] * #9 / #10 + #8

    (RADIUS)
    #17= SQRT[ [ [#1-#15]* [#1-#15] ]+[ [#2-#16]*[#2-#16] ]]
    I tried to load it but I can't seem to be able to view any of my 9000 series programs and I couldn't make any head with getting it to work.

  2. #2
    Join Date
    Feb 2011
    Posts
    640
    theres a parameter that can hide 8000 and 9000 programs...change the program number to 7999 or under, load and view it- or find the parameter and turn it off

  3. #3
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by blkaplan View Post
    Hey guys,

    I recently bought a 3d taster that I have been using in my Fanuc 10M mori mv-40b.

    I would like to figure out a macro that allows me to input the position of 3 spots to calculate the center of a circle and load it to work offset.

    Does anyone have any ideas or suggestions?

    I found this code on another site



    I tried to load it but I can't seem to be able to view any of my 9000 series programs and I couldn't make any head with getting it to work.
    You need to set parameter bit 2201.0 to "0" to enable editing of O9000 to O9999 programs.

    The program you have listed looks like one I wrote and posted, but that isn't it in its entirety; there should be more code following to load the result of X-Centre and Y-Centre into a specified Work Shift Offset. What you have here may have been the math involved that I posted to give someone a leg up.

    The message System Variable #3006 may be why its not working for you with a 10 Series control. Replace the occurrences of #3006=1 with the following, and delete all occurrences of #3006=0.

    M00 (MANUAL TOUCH 1 - THEN CYCLE START)


    M00 (MANUAL TOUCH 2 - THEN CYCLE START)


    M00 (MANUAL TOUCH 3 - THEN CYCLE START)

    The above is just a prompt to the operator to manually move a Touch Stylus, or some type of Edge Finder, so as to make contact with the feature. Then without moving the axes, select Auto Mode and press Cycle Start to record the current Machine Positions for use in calculations further on in the Macro. If the control doesn't have a Message Screen feature, then the #3006 may be giving you grief.


    Ask any question you may have about the code and I'll try and answer it for you.

    Regards,

    Bill

  4. #4
    Join Date
    Aug 2011
    Posts
    92
    Bill,

    I believe i did see you post that! Thanks for the replying.

    I am fairly new to my VMC and I am complete rookie to running and programming macros

    Because i was having the problems viewing the 8,000 and 9,000 programs I loaded it as a 3000 program just to try it out.

    It was a while since i tried it so i don't quite remember what was working and not working but part of the way i was getting confused was the actual process...

    for example if i were to load it to program 05000

    i would go to the memory option,

    and enter G65 P5000 S2 (that tells the controller i want to run a macro with program number 05000 and configure it to work offset 2..

    Then i would go jog and move to the correct location,

    Then select auto mode, cycle start.

    Then select jog go to the next location

    Then select auto mode, cycle start.

    for the 3 points....

    once thats done it should overright what ever data is in g55 right?


    For the program.... this is what i will use... does it look ok?

    %
    O5000(CIRCLE THROUGH 3 POINTS MACRO)
    M00 (MANUAL TOUCH 1 - THEN CYCLE START)
    #1=#5021 (1ST X)
    #2=#5022 (1ST Y)
    M00 (MANUAL TOUCH 2 - THEN CYCLE START)
    #3=#5021 (2ND X)
    #4=#5022 (2ND Y)
    M00 (MANUAL TOUCH 3 - THEN CYCLE START)
    #5=#5021 (3RD X)
    #6=#5022 (3RD Y)

    (GET PERPENDICULAR BISECTOR OF #1, #2 and #3, #4)
    #7 = [#3 + #1] / 2
    #8 = [#4 + #2] / 2
    #9 = #3 - #1
    #10 = -[#4 - #2]

    (GET PERPENDICULAR BISECTOR OF #3, #4 and #5, #6)
    #11 = [#5 + #3] / 2
    #12 = [#6 + #4]/ 2
    #13 = #5 - #3
    #14 = -[#6 - #4]

    (SEE WHERE THE LINE INTERSECT)
    (X-CENTRE)
    #15 = [#8 * #10 * #14 + #11 * #10 * #13 - #7 * #9 * #14 - #12 * #10 * #14] / [#10 * #13 - #9 * #14]

    (Y-CENTRE)
    #16 = [#15 - #7] * #9 / #10 + #8

    (RADIUS)
    #17= SQRT[ [ [#1-#15]* [#1-#15] ]+[ [#2-#16]*[#2-#16] ]]

    #[5201+[20*[#19]]]=#15 (X WORK SHIFT)
    #[5202+[20*[#19]]]=#16 (Y WORK SHIFT)

    M99
    %

  5. #5
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by blkaplan View Post
    Bill,

    I believe i did see you post that! Thanks for the replying.

    I am fairly new to my VMC and I am complete rookie to running and programming macros

    Because i was having the problems viewing the 8,000 and 9,000 programs I loaded it as a 3000 program just to try it out.

    It was a while since i tried it so i don't quite remember what was working and not working but part of the way i was getting confused was the actual process...

    for example if i were to load it to program 05000

    i would go to the memory option,

    and enter G65 P5000 S2 (that tells the controller i want to run a macro with program number 05000 and configure it to work offset 2..

    Then i would go jog and move to the correct location,

    Then select auto mode, cycle start.

    Then select jog go to the next location

    Then select auto mode, cycle start.

    for the 3 points....

    once thats done it should overright what ever data is in g55 right?


    For the program.... this is what i will use... does it look ok?

    %
    O5000(CIRCLE THROUGH 3 POINTS MACRO)
    M00 (MANUAL TOUCH 1 - THEN CYCLE START)
    #1=#5021 (1ST X)
    #2=#5022 (1ST Y)
    M00 (MANUAL TOUCH 2 - THEN CYCLE START)
    #3=#5021 (2ND X)
    #4=#5022 (2ND Y)
    M00 (MANUAL TOUCH 3 - THEN CYCLE START)
    #5=#5021 (3RD X)
    #6=#5022 (3RD Y)

    (GET PERPENDICULAR BISECTOR OF #1, #2 and #3, #4)
    #7 = [#3 + #1] / 2
    #8 = [#4 + #2] / 2
    #9 = #3 - #1
    #10 = -[#4 - #2]

    (GET PERPENDICULAR BISECTOR OF #3, #4 and #5, #6)
    #11 = [#5 + #3] / 2
    #12 = [#6 + #4]/ 2
    #13 = #5 - #3
    #14 = -[#6 - #4]

    (SEE WHERE THE LINE INTERSECT)
    (X-CENTRE)
    #15 = [#8 * #10 * #14 + #11 * #10 * #13 - #7 * #9 * #14 - #12 * #10 * #14] / [#10 * #13 - #9 * #14]

    (Y-CENTRE)
    #16 = [#15 - #7] * #9 / #10 + #8

    (RADIUS)
    #17= SQRT[ [ [#1-#15]* [#1-#15] ]+[ [#2-#16]*[#2-#16] ]]

    #[5201+[20*[#19]]]=#15 (X WORK SHIFT)
    #[5202+[20*[#19]]]=#16 (Y WORK SHIFT)

    M99
    %
    What you have above looks OK.

    As stated in my last Post, you can set parameter bit 2201.0 to "0" to be able to access and register O9000 to O9999 programs. Then if you Create a Custom G Code, you can use that G code either via MDI or Auto mode to launch the Circle through 3 Points Macro.

    Regards,

    Bill

  6. #6
    Join Date
    Aug 2011
    Posts
    92
    Bill,

    Looks like I am getting it to work :banana:

    very exciting!!!

    I unlocked the 9000 programs and loaded it to program 9001.

    One question I have is the last part of the program it calculates the Radius.

    How is this used? Is it just a check? If it is just a check how do i find out what the measured radius is?

    -Ben

  7. #7
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by blkaplan View Post
    Bill,

    Looks like I am getting it to work :banana:

    very exciting!!!

    I unlocked the 9000 programs and loaded it to program 9001.

    One question I have is the last part of the program it calculates the Radius.

    How is this used? Is it just a check? If it is just a check how do i find out what the measured radius is?

    -Ben
    Hi Ben,

    I would be inclined to create a Custom "G" to use to launch the Macro Program. With a Series 10 control, there are 10 programs that can be called via a "G" Code and 9 programs that can be called via an "M" code. To register a "G" or "M" code to call a Macro or Sub Program, the following table shows the relationship of Parameter Numbers and their associated Program Numbers.

    Macro Call using "G" Code
    Parameter Number ----------------------------- Program Number
    7050 ------------------------------------------------- 9010
    7051 ------------------------------------------------- 9011
    7052 ------------------------------------------------- 9012
    7053 ------------------------------------------------- 9013
    7054 ------------------------------------------------- 9014
    7055 ------------------------------------------------- 9015
    7056 ------------------------------------------------- 9016
    7057 ------------------------------------------------- 9017
    7058 ------------------------------------------------- 9018
    7059 ------------------------------------------------- 9019


    Sub Program call with "M" Code
    Parameter Number ----------------------------- Program Number
    7071 ------------------------------------------------- 9001
    7072 ------------------------------------------------- 9002
    7073 ------------------------------------------------- 9003
    7074 ------------------------------------------------- 9004
    7075 ------------------------------------------------- 9005
    7076 ------------------------------------------------- 9006
    7077 ------------------------------------------------- 9007
    7078 ------------------------------------------------- 9008
    7079 ------------------------------------------------- 9009

    The reason for using a "G" code rather than an "M" Code, is that the "G" Code calls the program as a Macro Program and is therefore able to pass arguments to the Macro program, the same as when calling the program using G65. When using an "M" code to call the program, it's called as a Sub Program, the same as when using M98, and is unable to pass arguments.

    Determine a program number between O9010 and O9019 that is vacant and then register the number of the "G" code you wish to use (Between G01 and G255), in the associated parameter. The program code is then registered in the selected Program Number. Lets say that G100 is "G" Code you want to use to launch your program, and program O9010 is available. In this case, the number "100" would be registered in parameter 7050 and the program code in program O9010.

    Once you have all the above in place, the Workshift can be set by specifying the following block in either a conventional program, or via MDI

    G100 S2

    The above command block will launch your Macro program and pass the number "2" to Local Variable #19 in the Macro Program.


    Quote Originally Posted by blkaplan View Post
    One question I have is the last part of the program it calculates the Radius.
    How is this used? Is it just a check? If it is just a check how do i find out what the measured radius is?
    This program can be modified to use as a Measuring program to get the X,Y Centre and Radius of a Bore or Boss. It doesn't have to be a complete Bore or Boss. Accordingly, its useful when you need to measure a feature where its not possible to use a micrometer or other measuring device that requires a full diameter to take the measurement.

    Once the Macro program has executed the following block, look up variable #17 in the Macro Variable pages.

    #17= SQRT[ [ [#1-#15]* [#1-#15] ]+[ [#2-#16]*[#2-#16] ]]

    You could use DPRNT to output the Centre and Radius, or diameter by multiplying #17 by 2, data to an external file.


    Regards,

    Bill

  8. #8
    Join Date
    Aug 2011
    Posts
    92
    Bill,

    Thank you again for the very informative posts! This is all very good info for me and I am basically self teaching myself all this stuff and advise like this goes along way to getting me upto speed.

    One question I have is i changed my parameter 2201 to bit 0 so i could edit 8000 & 9000 series programs.

    I looked in my program directory and there was no other programs listed besides 09001 (the one i loaded) Is it possible that my machine won't have any other macros loaded or is their some other parameter that i need to set to be able to view things in the 8000 and 9000 series range?

    -Ben

  9. #9
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by blkaplan View Post
    Bill,

    Thank you again for the very informative posts! This is all very good info for me and I am basically self teaching myself all this stuff and advise like this goes along way to getting me upto speed.

    One question I have is i changed my parameter 2201 to bit 0 so i could edit 8000 & 9000 series programs.

    I looked in my program directory and there was no other programs listed besides 09001 (the one i loaded) Is it possible that my machine won't have any other macros loaded or is their some other parameter that i need to set to be able to view things in the 8000 and 9000 series range?

    -Ben
    Hi Ben,
    Only the 8000 and 9000 series programs that have been created will be displayed in the program directory. You have a program registered as O9001 and therefore, its displayed. As other programs in this number range are created, so will they be displayed.

    Regards,

    Bill

  10. #10
    Join Date
    Aug 2011
    Posts
    92
    awesome. now working with g100 sX callout. very quick and easy.

  11. #11
    Join Date
    Sep 2012
    Posts
    182
    can anyone explain how the start of this macro works? I don't have macro B and I'm trying to convert it to macro A.

    I'm guessing M00 is a stop so you call the macro and it stops. you jog it to the first touch and hit cycle/start, which enters the x and y values.
    then it hits M00 and stops again for you to repeat?

    this is what I converted it to. macro A sucks! very limited to one line ops so it seems variable intensive.

    ***edited the code to a working version note 0m-a needed #5041 and #5042 for the x and y position.
    ***macro a lacks precision. it truncates any decimal number to whole numbers. the center is only approximate!
    ***I tried to use the same macro numbers as the macro b code so you can work out what it does. ie #7 = #107, #8 = #108 etc.

    %
    O1000
    M00
    G65 H01 P#501 Q#5041
    G65 H01 P#502 Q#5042

    M00
    G65 H01 P#503 Q#5041
    G65 H01 P#504 Q#5042

    M00
    G65 H01 P#505 Q#5041
    G65 H01 P#506 Q#5042

    G65 H02 P#107 Q#503 R#501
    G65 H05 P#107 Q#107 R2
    G65 H02 P#108 Q#504 R#502
    G65 H05 P#108 Q#108 R2
    G65 H03 P#109 Q#503 R#501
    G65 H03 P#110 Q#504 R#502
    G65 H04 P#110 Q#110 R-1
    G65 H02 P#111 Q#505 R#503
    G65 H05 P#111 Q#111 R2
    G65 H02 P#112 Q#506 R#504
    G65 H05 P#112 Q#112 R2
    G65 H03 P#113 Q#505 R#503
    G65 H03 P#114 Q#506 R#504
    G65 H04 P#114 Q#114 R-1
    G65 H04 P#101 Q#110 R#114
    G65 H05 P#101 Q#101 R10000
    G65 H04 P#102 Q#101 R#108
    G65 H04 P#103 Q#110 R#113
    G65 H05 P#103 Q#103 R10000
    G65 H04 P#104 Q#103 R#111
    G65 H04 P#105 Q#109 R#114
    G65 H05 P#105 Q#105 R10000
    G65 H04 P#106 Q#105 R#107
    G65 H04 P#118 Q#112 R#101
    G65 H02 P#115 Q#102 R#104
    G65 H03 P#115 Q#115 R#106
    G65 H03 P#115 Q#115 R#118
    G65 H03 P#119 Q#103 R#105
    G65 H05 P#115 Q#115 R#119
    G65 H03 P#116 Q#115 R#107
    G65 H04 P#120 Q#109 R10000
    G65 H05 P#120 Q#120 R#110
    G65 H04 P#116 Q#116 R#120
    G65 H05 P#116 Q#116 R10000
    G65 H02 P#116 Q#116 R#108

    M99
    %

  12. #12
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by landslide1 View Post
    can anyone explain how the start of this macro works? I don't have macro B and I'm trying to convert it to macro A.

    I'm guessing M00 is a stop so you call the macro and it stops. you jog it to the first touch and hit cycle/start, which enters the x and y values.
    then it hits M00 and stops again for you to repeat?

    this is what I converted it to. macro A sucks! very limited to one line ops so it seems variable intensive.
    I had to drop the radius and work offset but I should be able to call the hole center using #507 and #508


    %
    Irrespective of whether Macro A or Macro B is used, the concept is the same. This Macro was meant for use with machines not equipped with a proper Touch Probe and the infrastructure that goes with it.

    You're correct in that the M00 command halts the Macro program, and is used to allow the operator to switch to Hand Wheel Mode to make a touch with some type of edge finder. Once the touch is made, the control is put back to Auto, or MDI Mode (depending on which mode was used to launch the Macro, and press Cycle Start to record the current X,Y coordinate. After pressing Cycle Start, the Macro will again be halted to allow another touch to be made. This process repeats until Three Touches have been made, where upon the Macro will continue through the calculation phase and ultimately store the result in the selected Work Shift Offset.

    In the Macro B version, a number corresponding to the Work Shift to be set is passed as an argument to the Macro program. This is not possible with with Macro A, therefore, the number, 1 to 6, should be set in a Common variable, either directly via the Macro Variable pages, or by setting the variable in the Call Program prior to the Macro being executed. For example, you may use a simple Call Program consisting of just a few blocks where the Work Shift number to set is edited each time the process is required.


    O0001
    #100=2 (SET 1 TO 6 FOR THE WORK SHIFT G54 - G59)
    M98 P5000
    M30
    %

    In the above code, the Common Variable #100 is set to the number that corresponds to the Work Shift to be set, after which the Circle through 3 Points Sub Program is called.

    There is no requirement to use Common Variables => #500. These Variables are Non-volatile and the last value allocated to them will be retained even after the control is powered down. When there is no need to use Non-volatile Variables, Local, or Common Volatile (#100 Series Variables) should be used. As Local Variables aren't available with Macro A, Common Volatile Variables should be used.

    Regards,

    Bill

  13. #13
    Join Date
    Feb 2011
    Posts
    640
    a comment on Macro-A, maybe macro B too:

    controls buffer 3 lines, if the line with the cursor on it has variables referenced in the next two lines, it wont work right- have to keep two extra EOBs after the first line to make certain variables are updated before the next step is applied. sometimes you can simply move your lines around if order isnt critical, otherwise macro programs often have blank lines inserted- dont delete them

    while macro b is a little easier, on a zero A~D if you dont have full key mdi, you can only edit offline... the g65 crap is kinda messy, but freely editable. any macros I write, I always put a ton of text in to make it readable, but again on zero A~D that takes a fullkey MDI also... either A/B type can get pretty hard to read...text on each line isnt necessary, but will sure be appreciated by someone who cant read macro fluently when they go to add a little something later on... like ladder without text, eventually its gonna take someone extra time to figure out what it was supposed to be doing

  14. #14
    Join Date
    Sep 2012
    Posts
    182
    Quote Originally Posted by angelw View Post

    There is no requirement to use Common Variables => #500. These Variables are Non-volatile and the last value allocated to them will be retained even after the control is powered down. When there is no need to use Non-volatile Variables, Local, or Common Volatile (#100 Series Variables) should be used. As Local Variables aren't available with Macro A, Common Volatile Variables should be used.

    Regards,

    Bill
    thanks for the explanation and advice. I see why you don't think Non-volatile variables should be used due to the risks that something has been carried over from a previous day/operation. in the case of macro A it is very hard not to use them. you only have 32 volatile variables to use, if you limit yourself to them. even fanuc's examples use the non-volatile variables, for example initializing a bolt hole PCD macro.

    maybe it is wise to zero them to initialize the macro this way the variables would be cleared every time the macro starts regardless of the prior values.

    maybe I'm too new to macro A to see where I can save on variables. the operators manual wasn't clear if you could perform operation on a variable and place the result back into the same variable. as you can see I had to break all the one line equations in your code down to one line for every operation. it ate up variables and I ran out. so I resorted to the non-volatile variables for the key inputs and outputs like fanuc's example initializing the PCD parameters.

    Quote Originally Posted by tc429 View Post
    a comment on Macro-A, maybe macro B too:

    controls buffer 3 lines, if the line with the cursor on it has variables referenced in the next two lines, it wont work right- have to keep two extra EOBs after the first line to make certain variables are updated before the next step is applied. sometimes you can simply move your lines around if order isnt critical, otherwise macro programs often have blank lines inserted- dont delete them
    ...
    ill keep that in mind. maybe I missed it but the operators manual didn't realy say what you could get away with in terms of comments so I was being brief.

  15. #15
    Join Date
    Sep 2012
    Posts
    182
    I tested my macro a conversion today but it has an error at the start.
    error 115: a value not defined as a variable number is designated

    this is the code it has problems with:

    G65 H01 P#501 Q#5021
    G65 H01 P#502 Q#5022

    if I change the variable #5021 to an integer, it loads the value into the variable #50x and goes on to the next line without an error.

    it would seem my machine doesn't have the positioning variables.

    I found #5041 and #5042 give me my x and y positions.

    now I'm getting another error with the calculations going to large for the control to store.

Similar Threads

  1. Finding Center of Mass (COM)
    By eficonnection in forum Uncategorised CAD Discussion
    Replies: 2
    Last Post: 11-08-2012, 04:11 AM
  2. Need help with finding center of pinions.
    By Coldwave in forum MetalWork Discussion
    Replies: 9
    Last Post: 12-16-2010, 10:18 PM
  3. Finding center of hole
    By georgebarr in forum Mach Mill
    Replies: 1
    Last Post: 10-08-2009, 12:27 PM
  4. finding center of a hole
    By BeerFizz in forum Mach Mill
    Replies: 1
    Last Post: 06-15-2007, 01:17 AM
  5. Finding the center
    By Tazzer in forum MetalWork Discussion
    Replies: 6
    Last Post: 08-05-2006, 06:18 PM

Posting Permissions

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