Macro Programming Fundamentals - Page 3
Close
Login to Your Account
Page 3 of 27 FirstFirst 1234513 ... LastLast
Results 41 to 60 of 539
  1. #41
    Join Date
    May 2008
    Location
    Great State Of Wisconsin
    Posts
    444
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    5

    Default

    Shearwater,

    I am going to assume that since it is on a monarch machine that it has a rotary table “C-axis”?? What kind of control is on the machine?

    This program below is set up for a rotary axis. If you need one that is not for a rotary axis let me know I will post that one as well. This program will do any amount of holes that you want equally spaced just by changing the “A” variable. You can also set it for drill, peck, high speed peck by changing the “K” variable and the “Q” for the pick. If you are not using a peck cycle then Q=0. Some machines you cannot pre call a tool so if his machine is not set up for that then just remove the “U” value from the G65 line.

    You can also stop after every hole just activate the optional stop button. It's about as simple as the programs get. Just load program O0001 and O8000.

    Definitions of the variables:
    A=12(number of holes to drill #1)
    C=0(starting degree of holes #3)
    K=73(G-code for drill cycle #6)(73,83,81etc)
    D=1(hole to start #7)
    R=20(bolt circle diameter #18)
    Q=.1(pick size for drill cycle #17)
    W=.05(starting depth #23)
    T=7(tool number #20)
    Z=1.3(depth of hole #26)
    U=1(next tool pre call #21)
    M=8(coolant code #13)(9,8,18 etc)

    O0001(MAIN PROGRAM)
    #500=3(CLEARANCE/R-PLANE)
    #100=55(WORK COORDINATES USED)
    G65P8000A12C0K73D1R20Q.1W.05T7Z1.3U1M8
    M30

    O8000(DRILL EQ. SPACED HOLES)
    M6T#20
    T#21
    G90G80
    IF[#1LE0]GOTO150
    IF[#7GT#1]GOTO150
    IF[#7LT1]GOTO100
    #14=360/#1
    #16=[[#7-1]*#14]+#3
    IF[#7LT2]TH#16=#3
    #10=#7-1
    G#100G0X0Y[#18/2]C#16Z#500M3
    N1M3
    G#6X0Y[#18/2]C#16Z-#26R#23Q#17M#13
    M1
    #10=#10+1
    #16=#16+#14
    IF[#10NE#1]GOTO1
    G80M9
    N150M5
    #3006=10(CHECK HOLE WITH GAUGE)
    M99
    N100
    #3000=10(HOLE TO START NOT SPECIFIED)


    Let me know if you have any questions.
    Stevo

  2. #42
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    16
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    1

    Default

    hey can you wright a macro for a octagon on a lathe with a c axes
    the lathe is a gang cnc with live tooling?

  3. #43
    Join Date
    Feb 2005
    Location
    Sydney Australia
    Posts
    24
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    0

    Default

    Quote Originally Posted by machinist_650r View Post
    hey can you wright a macro for a octagon on a lathe with a c axes
    the lathe is a gang cnc with live tooling?
    here are a couple of contour generators.

    Sorry. It didn't work. The upload facility is down.

    http://depositfiles.com/files/10psbecnb

  4. #44
    Join Date
    Jun 2007
    Location
    Maine
    Posts
    43
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    0

    Default

    Hi all....just wondering if anyone would be so kind as to
    show me an example in Macro A that would input the values
    required for work co-ordinates (G54-G59) at the start of a program.

    Our machine is a VMC with a Fanuc 0M control and we do
    have Macro A installed. Thanks in advance for any help........

  5. #45
    Join Date
    Jul 2005
    Location
    Croatia
    Posts
    45
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    0

    Default

    newg3,

    Clear work offset G54:
    G10 G90 L2 P1 X0 Y0 Z0

    Instead of X0 Y0 Z0 input your values

    Clear tool offset H1:
    G10 G90 L11 P1 R0

    G10 - Data input
    G90 - Absolute value
    L2 - Work offset
    L11 - Tool offset
    P# - offset number
    X - value of X axis
    Y - value of Y axis
    Z - value of Z axis
    R - value of tool length/radius

    This is copied from:
    http://www.*******.com/forums/showthread.php?t=35666

  6. #46
    Join Date
    Jun 2007
    Location
    Maine
    Posts
    43
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    0

    Default

    Zdravko....thanks for the reply.
    I will try this first thing Monday when I get
    back in the shop. I just hope G10 is not an option
    on our machine......

  7. #47
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    16
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    1

    Exclamation

    Quote Originally Posted by Tonytn36 View Post
    Macro programming is a useful tool for most any CNC machine shop, whether a one man garage or an international conglomerate. Macro programming provides a means of shortening code and doing repetitive tasks easily and quickly. All of your canned cycles in a control are nothing but a macro. Macro is also extremely useful for families of parts.
    All computer programming is on a fundamental level, very similar. The syntax of the commands, and purpose of the programming may change, but the fundamentals of how to approach it, how logic works, and program flow are pretty much the same.

    The first step to any programming is to define the _functionality_ required of the program. Functionality is defined as the end result(s) and abilities expected of the computer code. In other words, what is it supposed to do.

    When we write a macro, we have a desired result in mind. Write down the broad-based result you are looking for from the program. A broad-based result would be something like: Bolt circle drilling, rectangular pocketing, block facing, slotting, etc.
    For an example, lets use bolt circle drilling.
    After we have defined the broad-based functionality, we need to narrow down the specifics of what we desire from the program. We must set limits to the functionality we want to achieve. If no limits are set, then the program becomes too large, cumbersome and time consuming.
    In our example, one of the main limits we need to set is the maximum number of holes we will be allowed to drill in the macro. For the sake of brevity, lets limit ourselves to 10 holes (We have another question coming up that, in reality, allows unlimited holes using only 10 as a maximum here)
    So: Max Holes in pattern == 10.
    Next up on the functionality list regarding hole drilling: Do we have a drilling cycle in the machine control or not? Most of the time, this is going to be a yes, so we will go with that.
    So: Have drilling cycle in control == Yes
    Next up on the functionality list: Do we want the ability to start the hole pattern at some angle other than directly along one of the major machine axis (X,Y,Z), this is seen often in parts, so yes, we want this functionality.
    So: Ability to start holes at operator input angle == Yes
    Next: Do we want the macro to call the tool, or will you already have the tool in the spindle when you call the macro? Lets do macro does not call tool. This is really a programmers preference as to which way to go, but since the possibility exists that we could do multiple bolt patterns with the same tool, we wouldn't want to go to tool change position each time between patterns.
    So: Macro calls tool == No
    Next: Do we want to induce multiples of our max holes? This would allow you to drill more than our stated maximum number of holes. I think we can implement this in a short manner, so we will do this.
    So: Macro allows multiples == Yes
    What other functionality should we define?......hrm.....for now I can't think of anything, so onward we go with the functionality described above.

    Still not sure how to start i am look into writting macros for a cnc gang with live c axes making octagon with diffrent size is there somthing that might clearfly it for me ?

  8. #48
    Join Date
    Dec 2007
    Location
    Southeastern US
    Posts
    6,078
    Post Thanks / Like
    Likes (Given)
    652
    Likes (Received)
    2403

    Default

    Ok,
    You've already defined what you want it to do.
    The next step is to define the dimensions that will change from one size part to the next. These are your base "user defined variables".
    After you have determined what will change, what are the mathematical relationships of those variables?
    For example, with the octagon, you will have a diameter which is tangent to the "points" of the flats, which would be the diameter you turn to before milling the flats.
    So you need to define the math based off of how the part is dimensioned on the drawing.
    If you are given a flat width on the drawing, then you need to calculate the diameter in the macro. If you are given the diameter, then you need to calculate the flat with that results from having that diameter......
    Next would be to have the macro calculate your X axis position for the live toy work based on the chord created by the flat and it's distance from part center.
    See where this is going?
    Actually writing how to execute the code is just like you normally would do it, you just use the calculated variables instead of hard numbers.

  9. #49
    Join Date
    Dec 2007
    Location
    Southeastern US
    Posts
    6,078
    Post Thanks / Like
    Likes (Given)
    652
    Likes (Received)
    2403

    Wink Another macro tip

    So,
    While I'm sitting here writing this (up to) 12 op macro program with a seemingly gazillion variables and listening to a little concentration music (Floyd), I'm using a few methods that might be of interest to those who code macro.

    Lets say you are milling, and want to add in your tool radius to a position. How do you get the tool radius into a variable, one might ask....

    It's fairly simple, really.

    1. (Disclaimer) So, as always, check your manuals, because these system variable numbers can be different on different flavors of controls.

    Given the following assumptions:
    a) We are using tool groups (or we just want to be sure, because someone may have swapped tools on us in the main and we wouldn't know it in the macro and that could be really, really bad....).
    b) We need to add both wear comp and tool radius to the position we want to go.

    In my case, the tool in the spindle is sys var #3700
    The sys var for the tool radius is #130xx where xx == tool number.
    The sys var for the tool wear offset is #120xx again, where xx == tool number. Fanuc controls should be similar...but see 1 above....

    So, the first thing we have to do is get the number of the tool that's in the spindle. I use my #800's for this...

    Our first line is going to be:
    Nxx #800 = #3700 (GET TOOL IN SPINDLE)

    This is going to set #800 to something like 12 (if you are using tool 12 in the spindle and we will assume we are)

    Now, to get our tool radius value, we have to get it to #130xx format, so the next line is going to be:
    Nxx #801 = [#800+13000] (ADD 13000 TO GET TOOL OFFSET VARIABLE)

    This is going to set #801 to 13012 which is the radius variable for tool 12

    Now comes the part that I scratched my head over for a few hours before I hit my head against the wall and referred to myself as a ....

    We have to get the offset corresponding to what's in var #801.

    So we:
    Nxx #802 = #[#801] -- Note the # prior to the []'s..... we are saying get the variable of variable #801, and since #801 contains 13012 which is our sys var for tool 12 radius, that's what it returns...

    Now, we do the exact same thing for our wear offset, with one change...since we are adding radius and wear together...we do this in the last line and save ourself a line of code.

    Nxx #803 = [#800+12000]
    Nxx #804 = [#[#803] + #802]

    So now #804 == wear comp + tool radius for the tool in the spindle at the time you execute the code.

    Personally, I'll use this same code and variables repeatedly in the program, as it works on what's currently in the spindle. Now, you do have to be careful if folks are apt to restart a program mid-way through something and you don't put measures in place to prevent them from skipping this snippet of code as #804 would hold the last number calculated.

  10. #50
    Join Date
    Sep 2002
    Location
    Posts
    233
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    4

    Default

    To reduce the gazillions of variables used, say:
    #804=#[13000+#3700]+#[12000+#3700]

    A small sample to help others visualize the concept of variable of a variable
    #1=5
    #5=100

    solve for variable 3
    #3=#[#1]

    in steps...
    since #1=5
    then #3=#5
    so #3=100

  11. #51
    Join Date
    Dec 2007
    Location
    Southeastern US
    Posts
    6,078
    Post Thanks / Like
    Likes (Given)
    652
    Likes (Received)
    2403

    Default

    But...but......Bryan,

    I couldn't write a book explaining it if I used really short code...

    Nice way of cleaning up my chicken scratchin.....

    I'm beginning to get a case of brain burn on this macro I'm writing. It has turned into one of those nightmare projects.
    I've now got over 125 operator input variables required, 14 tools, for 16 operations, 3 of which can have multiple optional methods of operation, depending on what the print calls for. For instance, one op, depending on what flavor of it they put on the print, (all of these are features inside of an existing bore done earlier) can be 4 simple circle mills, or it can be 4 partial bores from inside toward out, or it can be 4 circle mills with the part at an odd compound angle, or it can be 4 partial bores with the part at an angle.
    The operator has to choose which type it is, simple for him/her, but I have to write calculations and subs for what amounts to 4 very different operations.

    Once done and debugged, it'll be nice, they can do the op file off-line while one job is running, load the op file change one number in the main and be up and running. But, it's a long road to get there.

  12. #52
    Join Date
    Jul 2005
    Location
    San Francisco, CA
    Posts
    799
    Post Thanks / Like
    Likes (Given)
    11
    Likes (Received)
    80

    Default

    Quote Originally Posted by Tonytn36 View Post
    125 operator input variables required.
    125 operator inputs??? that sounds excessive but leads me to the hardest part of macro writing, for me, and that is error checking.
    There has to be enough checks that there can never be a negative interaction between values that would cause the macro to produce an undesired result. For many this may not be an issue but most of my macros are run behind the scenes or use the inputs that are entered from a posted CAM program so every possible scenario has to be thought out and hopefully caught before the first tool is called.

    A "few hours" to right a macro inorder to read the current tools radius!!! ...for me its only one variable and I'm on to the real work!!

  13. #53
    Join Date
    Dec 2007
    Location
    Southeastern US
    Posts
    6,078
    Post Thanks / Like
    Likes (Given)
    652
    Likes (Received)
    2403

    Default

    Quote Originally Posted by Hansdie View Post
    125 operator inputs??? that sounds excessive..
    Not excessive, absolutely required for the operations the machine will be doing. Better than 85% of the dimensions on the print are required to do the operations.
    There are 16 Option bits to determine what operations are required, not all are on all prints, but you have to program for worst case. Operator just puts in 0 or 1 for each feature.
    There are 10 other option bits that determine what *type* of operation some are. There are variable flavors of several operations, each requiring a unique machining technique. (You could count these as separate, additional operations, but since they have a "common name" in our company language, just different types of that operation, I use the common name as the operation type.
    Then there are up to 100 or so dimensions that need to be entered, depending on how many operations are needed. Not all prints will require all 100+ dimensions, actually a minimal number of prints will, but they still have to be there for those that do. I would say 45-60 are going to be required on average.
    These parts could be considered a "family" of parts. They are all the same kind of part, but all of the dimensions are different for each print, and there are potentially hundreds of prints. The machine is robot loaded, so the operator isn't standing there slinging parts in the machine, he/she has time to input numbers in a parameter file on a computer while the machine runs, to be transferred by memory stick to the control. Once all the repeat parts have a file created, it's a simple matter of changing which sub the main program calls to change over to another part type. This same type of system is in use on another machine although it needs many less parameters entered (about 30). It works really well in our situation. This is a production operation, not a job shop.



    Quote Originally Posted by Hansdie View Post
    A "few hours" to right a macro inorder to read the current tools radius!!! ...for me its only one variable and I'm on to the real work!!
    Well....sometimes......you bang your head against the wall for a while over something simple that's slapping you right in the face.....but you just can't see it, and can't figure out what that sting is........

  14. #54
    Join Date
    Jul 2005
    Location
    San Francisco, CA
    Posts
    799
    Post Thanks / Like
    Likes (Given)
    11
    Likes (Received)
    80

    Default

    I realize that you’re a production shop, as am I, all the more reason I wouldn’t let the operator set ~125 variables, I would barely trust myself to do it right.

    If it were me I would probably write it so the operator only had to type in the print part number, or other identifying number and then let the sub set the variables and then call the macro or better yet use a bar code reader or other automatic device to call the right program in. That way once you know the variables match the particular print you never have to worry again, unless of course the operator type in the wrong number...

    But that’s just me!!!

    Quote Originally Posted by Tonytn36 View Post
    Well....sometimes......you bang your head against the wall for a while over something simple that's slapping you right in the face.....but you just can't see it, and can't figure out what that sting is........
    I only said this since I feel sorry that your control doesn’t have an easier way of getting the current tool radius. I realize too that you have to work with what you have…

  15. #55
    Join Date
    Dec 2007
    Location
    Southeastern US
    Posts
    6,078
    Post Thanks / Like
    Likes (Given)
    652
    Likes (Received)
    2403

    Default

    Quote Originally Posted by Hansdie View Post
    I realize that you’re a production shop, as am I, all the more reason I wouldn’t let the operator set ~125 variables, I would barely trust myself to do it right.

    If it were me I would probably write it so the operator only had to type in the print part number, or other identifying number and then let the sub set the variables and then call the macro or better yet use a bar code reader or other automatic device to call the right program in. That way once you know the variables match the particular print you never have to worry again, unless of course the operator type in the wrong number...

    But that’s just me!!!
    The operator in this case will a qualified Technician, having spent 4 years in an apprenticeship program, and then at least 15+ years on the floor setting up CNC equipment and automation. The personnel slated to run this cell are top-notch folks.
    Unless I do the variable entry, which I have no time to do with all of my other duties, there is nobody else to do it except for the operators.
    Almost all of our programming is this type of macro, with operator inputs, they do this type of data entry daily, it won't be a big deal for them.
    This cell is designed to run lot sizes in the 100-500 pc range, which means they may change part types up to 4 times a shift, with 2 shifts of operations to start. As volume picks up it will move to 3 shifts and if predicted volumes mature, up to 4 of these cells may be in operation. As it is also designed to be a pull system with very short lead time, we may only have a few hours notice of the type of parts needed. I'm looking at the very real possibility of having to turn around an order in 24 hours, from order receipt to getting the mold on the casting machine, casting parts, degating, heat treating, machining, surface treatment, inspection and out the door.
    Since you have fixed times in there that cannot be changed (mold heating time, heat treatement times, surface treatment curing times, for instance), the rest of the operations get compressed.


    Quote Originally Posted by Hansdie View Post
    I only said this since I feel sorry that your control doesn’t have an easier way of getting the current tool radius. I realize too that you have to work with what you have…
    It's easy enough, if my brain would just cooperate at times.

  16. #56
    Join Date
    May 2009
    Location
    California, USA
    Posts
    5
    Post Thanks / Like
    Likes (Given)
    1
    Likes (Received)
    0

    Default

    Tony,

    Interesting that Fadal has the ability to prompt operator for data input, great for running family of parts;

    http://tinyurl.com/nfljlz

    Look at bottom of page 65

    Also I had a Bridgeport 3020 with Fanuc 21i, machine came off dealer floor, had the Bridgeport fast op keys, seemed every option was turned on. One option was menu driven programming.

    With menu driven programming I could create custom menus for operator input and tie it to a macro, I did that. If I remember correctly you could have it prompt operator for data input but I hadn't tried it.

    Down side of Fanuc menu driven programming is it takes up a lot of the available machine memory.

    Tom

  17. #57
    Join Date
    May 2007
    Location
    Central Texas, West and North of Austin
    Posts
    1,619
    Post Thanks / Like
    Likes (Given)
    176
    Likes (Received)
    522

    Default

    A quick question, Anyone can tell a noobie(to writing macros that is) the best text or reference book or info source to get started teaching myself how to write macros? Even Tonytn36 info is above my head. I've been writing subs nested in subs nested in subs, but somehow I haven't grasped the basic roots of macros. Seems that material written to explain even the basics assumes I know some basic terms that I don't know. I've used controls that have "canned cycles" and know that they're just factory macros, so I can see the utility of them and can use something like that a lot. I just need to get started off right. Any ideas?

  18. #58
    Join Date
    May 2009
    Location
    California, USA
    Posts
    5
    Post Thanks / Like
    Likes (Given)
    1
    Likes (Received)
    0

  19. #59
    Join Date
    Dec 2007
    Location
    Southeastern US
    Posts
    6,078
    Post Thanks / Like
    Likes (Given)
    652
    Likes (Received)
    2403

    Default

    Quote Originally Posted by gorrilla View Post
    A quick question, Anyone can tell a noobie(to writing macros that is) the best text or reference book or info source to get started teaching myself how to write macros? Even Tonytn36 info is above my head. I've been writing subs nested in subs nested in subs, but somehow I haven't grasped the basic roots of macros. Seems that material written to explain even the basics assumes I know some basic terms that I don't know. I've used controls that have "canned cycles" and know that they're just factory macros, so I can see the utility of them and can use something like that a lot. I just need to get started off right. Any ideas?
    In addition to the great resources noted by Brewertr, I would suggest starting out and experimenting with simple stuff.

    I needed to profile an aluminum bracket. Since I wasn't holding it very well, I wanted to go in 1 mm depth increments. Rather than program the profile 12 times, or call a sub 12 times, I did a simple little increment counter and check. See below:
    (OUTSIDE)
    G0 G90 G40 G80 G17 G64 ( SET DEFAULTS )
    M08
    #750=-1.0 (INITIAL DEPTH)
    G100 G56 T12 G43 H12 D12 X-85. Y50.0 Z0. S10000 M03 A0.B0.
    N25 G0 Z#750
    G1 G41 X-66. Y31.5 F3200 (START PROFILE)
    G1 X34.25 Y31.5
    G2 X34.25 Y-31.5 I0. J-31.5
    G1 X-66.Y-31.5
    G1 X-66. Y-16.5
    G1 X-41. Y-16.5
    G1 X-41. Y16.5
    G1 X-66. Y16.5
    G1 X-66. Y40.
    G1 G40 X-85. Y50. (END PROFILE MOVE OFF PART)
    N500 IF [#750 EQ -12.0] GOTO 900 (CHECK FOR FINISH DEPTH)
    #750=#750-1.0 (DECREMENT DEPTH)
    GOTO 25 (LOOP PROFILE)
    N900 G0 Z60. (CLEAR Z)
    M09
    M30

    The other day I needed to cut some radial reliefs in a collet. This was mounted in it's housing on the A axis of the 4/5 indexer. Here is a short program that plunge mills these reliefs at a 0.2 mm radial step over per plunge, every 15 degrees around the collet to a radial depth of 2 mm.
    I have commented the program so you can follow what it's doing (hopefully).

    (COLLET RELIEF)
    G0 G90 G40 G80 G17 G64 ( SET DEFAULTS )
    #750 = 42.0 (SET INITIAL X POSITION)
    #751 = 0. (SET INITIAL A AXIS POSITION)
    G100 G56 T12 G43 H12 D12 X0. Y0. Z0.5 S1800 M03 A0.B0. (TOOL CALL+POSITIONING)
    N10 G0 X#750 A#751 (MOVE TO START POSITION)
    G1 Z-15. F400 (PLUNGE)
    G0 X41. Z0.5 (CLEAR)
    IF [#751 EQ 360] GOTO 500 (CHECK FOR 1 COMPLETE CIRCLE)
    #751 = #751+15.0 (INCREMENT ANGLE)
    GOTO 10 (LOOP BACK)
    500 IF [#750 EQ 44.0] GOTO 900 (CHECK FOR FINISH X POSITION)
    #750 = #750+0.2 (INCREMENT X POSITION)
    GOTO 10 (LOOP BACK)
    900 G0 Y100. Z100. (CLEAR POSITION)
    M30

    Using macro for everyday little jobs like this is where the basics get burned into your head. It also shows you how utterly useful macro is to everyday job shop work.

  20. #60
    Join Date
    Sep 2009
    Location
    elmira,ny usa
    Posts
    8
    Post Thanks / Like
    Likes (Given)
    0
    Likes (Received)
    0

    Default Macros made easy

    TonyTn, I notice you use a lot of the common variables, do you prefer these over local variables? I also note that you use a lot of "Write to's", have you ever had that one come back to bite you?
    Currently on Hardinge's version of fast ops, there are 8 user definable "one-touch" program/macro features available.
    Every MTB using the ISO/Fanuc platform has Manual Guide i available to them. MGi is the conversational side of the control, and as a guy that has been teaching/writing macros since headbands and bell bottoms I am glad to see it. Macros are a great tool, but we all know they are typically time consuming, as Tony said. Let's face it, CAM packages and conversational programming is the way the video game generation has found to be the most productive.
    To all who posted on this string; Great info and look forward to reading more of your posts in the future.

    Many Thanks,
    G


Tags for this Thread

Bookmarks

Posting Permissions

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