585,712 active members*
3,984 visitors online*
Register for free
Login

Thread: looping

Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2012
    Posts
    0

    looping

    hi peaple, i've not been programming long and was looking to shorten my progams when i am heilcal milling. i.e machining some soft jaws on the bed of my miller. using fanuc controls.
    N10 G17 G3 X5.0 I-5.0 Z-1.0
    N20 G3 I-5. Z-2.
    N30 G3 I-5. Z-3
    and so on.
    got a book that says if i progam
    N10 G17 G3 X5. I-5. Z-1
    N20 G91
    =N40/5
    N40 I-5. Z-1.
    N50 I-5.
    not looked into macro's yet trying to get the basics down first.
    i'd just like to know if i was on the right path.
    bry

  2. #2
    Join Date
    Mar 2007
    Posts
    22
    G90 is for absolute and G91 is for incremental.

    When given new point while using incremental(G91), its from current position, not from zero point (like when using G90)

    Havent done much basic milling for while, but if doing deep holes its hard to keep track of the current depth unless you loop it with (WHILE) macros.

    But like you said, you want to keep it simple, that works. But id also consider
    using subprogram and calling it with repeat.

    You'd have the closing on main program, and the helical circle command on subprogram, something like ->

    Main:

    G0 X5 Y0 Z20
    Z2
    M98 P100 L10
    (P = number of the subprogram)
    (L = number of repeats)
    G3 I-5
    G90
    G0 Z10

    Subprogram 100:

    G91 G3 I-5 Z-1

    Whenever using incremental, remember to turn it back to absolute, otherwise crash might happen.

    In any case, if i were you, look for M98 command in your manuals, since it might work differently in certain controls.

    Aand dont trust my code, like said, rusty.

    Whenever you start to mix with G90/G91, G40/G41/G42 you want to have a line on every programs start where it "defaults" these, this includes many other commands but just to advice to be careful with these.

  3. #3
    Join Date
    Jan 2012
    Posts
    0
    Thank you for your help, i know about G90/G91. I also use sub programs at times. Just wanted to have a play. Thanks again Bry.

  4. #4
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by dinglekiller View Post
    Thank you for your help, i know about G90/G91. I also use sub programs at times. Just wanted to have a play. Thanks again Bry.
    Bry,
    You don't state the controller, and I understand that you're not getting into User Macros yet. However, following is a method of looping any profile, and unlike running a Subprogram a number of times, the depth of cut from start point to full depth does not have to be evenly divisible by the depth of each cut. Following is an example using Fanuc User Macro syntax.

    #1 = 0 (Z CUT LEVEL)
    #2 = 3.0 (Z CUT IN AMOUNT)
    #3 = -20.0 (Z FULL DEPTH)
    G90 G00 X10.000 Y0.000
    G43 Z10.000 H01
    G01 Z1.000 F2000
    N10 #1 = #1-#2
    IF[#1 LT #3] TH #1 = #3
    G03 I-10.000 Z#1 F200
    IF[#1 GT #3] GOTO 10
    ............
    (PROGRAM CONTINUES HERE ONCE FULL DEPTH HAS BEEN REACHED)
    ............
    ............

    You will note from the above code example, that if the repeat of a Sub Program method was used, the tool would over cut the depth on the 7th iteration. This method ensures that the tool never goes beyond the programmed full depth.

    Regards,

    Bill

  5. #5
    Join Date
    May 2007
    Posts
    1003
    Neat Bill. Can't get any simpler or easier than that.

  6. #6
    Join Date
    Jan 2012
    Posts
    0
    Like I said never looked in to macros and that Bill is abit over my head, Working through a book by Peter Smid at the moment and the next installment is macros. So that should give me a better footing.
    Thanks Bry

  7. #7
    Join Date
    Sep 2010
    Posts
    1230
    Quote Originally Posted by dinglekiller View Post
    Like I said never looked in to macros and that Bill is abit over my head, Working through a book by Peter Smid at the moment and the next installment is macros. So that should give me a better footing.
    Thanks Bry
    As observed by g-codeguy, the code example in my previous post and following is a simple application of Macro statements, and may only seem daunting to you because, at this stage, you're not aware of the syntax of the User Macro language. However, you will quickly pick this up as you progress through various books on the subject. This is a good example to gain some understanding of Flow associated with the User Macro language; I'll explain how it works in this example.

    There are various Types of variables available. You will learn about these in early discussion in just about any manual or book relating to the Macro language. In my example, variables of Type "Local" have been used; these include variables in the range of #1 - #33.

    In the following section, the variables used are initialized.
    #1 = 0 (Z CUT LEVEL) This is set to the Z start surface. If the machining was to start at Z-5.0mm, then #1 would be initialized to -5.0. Its value is modified as the program Loops and carries out another calculation.

    #2 = 3.0 (Z CUT IN AMOUNT) This is the depth of each cut, and is subtracted from #1 to calculate the new absolute Z level. It could also be specified as a minus value, and added to #1 to gain the same result.

    #3 = -20.0 (Z FULL DEPTH) This is the full depth in Z of the feature.

    G90 G00 X10.000 Y0.000
    G43 Z10.000 H01
    G01 Z1.000 F2000

    N10 #1 = #1-#2 This is where the calculation for the depth of cut is carried out and is the marker of the return for the Loop. As #1 is initially set to Zero in this example, and #2 is 3.0, the resulting value of #1 for the first Loop is -3.0

    IF[#1 LT #3] TH #1 = #3 This block is a Conditional, Boolean statement that tests for True or False. LT is the Macro shorthand for LESS THAN, and TH for THEN. In this statement the test is to determine if #1 < #3. If #2 (-3.0) was repeatedly subtracted from #1, eventually #1 would have a value < #3 (-20). On the 7th iteration, #1 would have a value of -21.0, a value less than -20.0. In this case the Macro statement tests True and therefore, #1 will be set to the value of #3, so as not to over cut in Z.

    G03 I-10.000 Z#1 F200 This block cuts the helical path from the current Z level down to Z#1 (Z-3.0 for the first iteration)

    IF[#1 GT #3] GOTO 10 This block again tests the value of #1 compared to full depth #3. In this case, the test is to determine if #1 is GREATER THAN (GT) #3. On the 6th iteration, #1 would have a value of -18.0, a value that is > #3 (-20.0). In this case the Macro statement tests True, and therefore will execute the GOTO command and control returns to the block containing "N10". When #1 has a value of -20.0, its no longer Greater Than #3, and therefore tests False. In this case, control DOES NOT return to "N10", but continues to execute the remainder of the program.

    I hope this helps you understand the Loop functionality of this short program.

    Regards,

    Bill

  8. #8
    Join Date
    Aug 2011
    Posts
    2517

    retro solution

    if you're old school and programmed in BASIC on a C64, BBC Micro, Amiga or something similar in the 80's, macro is very simple to apply using the same programming principles.

    For example the above macro statements converted to BASIC would look like this and could effectively be run in something like QBASIC (came with DOS 6) to output the entire tool path to check to see if your logic is correct....

    10 A=0 : B=3.0 : C=-20.0
    20 PRINT "G90 G00 X10.000 Y0.000"
    30 PRINT "G43 Z10.000 H01"
    40 PRINT "G01 Z1.000 F2000"
    50 A = A - B
    60 IF A < C THEN A = C
    70 PRINT "G03 I-10.000 F200 Z"; A
    80 IF A > C GOTO 50

    BASIC is a bit more readable too and less daunting than macro. But essentially macro = BASIC
    Sometimes if I need to write a complex macro I'll write it in BASIC first and run it on a computer to prove the logic and ensure the calculated values are coming out right. I will then convert the proven program to macro.
    The logic in this very simple example is easy to follow even if you don't know BASIC.

    See pic attached with C64 generated G-code
    Attached Thumbnails Attached Thumbnails retro_macro.jpg  

  9. #9
    Join Date
    May 2007
    Posts
    1003
    Peter Smid's book is good. S.K. Sinha's book is better. Also more expensive, but I got mine for less than the Smid book....used for less than $17 (bit over $20 with shipping). However, it looked like the book had never had a page turned.

    Sinha writes it like a text book. Therefore you should not be skipping around. He gives more examples and plenty explanations of "why". I found it informative even though I've been using Macro B for awhile.

  10. #10
    Join Date
    Jun 2008
    Posts
    1511
    Quote Originally Posted by g-codeguy View Post
    Peter Smid's book is good. S.K. Sinha's book is better.
    x2

    That's not a blow at Smid's book I am just stating that Sinha's book explains it much better for newcomers to macros.

    Stevo

  11. #11
    Join Date
    Feb 2006
    Posts
    1792
    Quote Originally Posted by g-codeguy View Post
    ...Also more expensive...
    Not necessarily. I have seen its price dropping down to as low as $5. Just have patience for a couple of weeks and regularly visit amazon's page.
    Today's minimum price is $17.46 (new):
    [ame=http://www.amazon.com/Programming-using-Fanuc-Custom-Macro/dp/0071713328/ref=sr_1_3?s=books&ie=UTF8&qid=1278746639&sr=1-3#_]Amazon.com: CNC Programming using Fanuc Custom Macro B (9780071713320): S.K Sinha: Books[/ame]

Similar Threads

  1. M98 Looping
    By camtd in forum Parametric Programing
    Replies: 20
    Last Post: 08-15-2011, 02:43 PM
  2. Looping command?
    By rigo430 in forum Haas Lathes
    Replies: 1
    Last Post: 04-11-2010, 11:35 PM
  3. LOOPING? with Camsoft??
    By nelZ in forum CamSoft Products
    Replies: 15
    Last Post: 10-15-2008, 09:56 PM
  4. Program Looping
    By Bohemund in forum CamSoft Products
    Replies: 7
    Last Post: 05-26-2007, 05:08 PM
  5. Sub Looping
    By murphyspost in forum Daewoo/Doosan
    Replies: 8
    Last Post: 12-27-2006, 05:28 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
  •