585,667 active members*
4,201 visitors online*
Register for free
Login
Results 1 to 19 of 19
  1. #1
    Join Date
    Mar 2006
    Posts
    81

    Macro WHILE DO END Loop (Lathe)

    In this thread I finally managed to get a drill to do a radial hole on a lathe.

    Now I'm looking for a way to automatically do this a number of times, so I'm looking into subroutine/macro programming.

    Again, I look to the Haasmanual for answers and there's a section on the WHILE DO END Iteration/Looping.

    (for information purposes, I'm using a Haas OL-1 Lathe with the Live-Tooling and C axis option)

    There is less than one quarter of a page's worth of information on it, however. It basically has this:
    ////////
    "Macros allow flexibility with the WHILE-DO-END construct. For example:
    WHILE [<conditional expression>]DOn;
    <statements>;
    ENDn;

    This executes the statements between DOn and ENDn as long as the conditional expression evaluates to True. The brackets in the expression are necessary. If the expression evaluates to False, then the block after ENDn is executed next. WHILE can be abbreviated to WH. The DOn-ENDn portion of the statement is a matched pair. The value of n is 1-3. This means that there can be no more than three nested loops per subroutine. A nest is a loop within a loop.

    Although nesting of WHILE statements can only be up to three levels, there really is no limit since each subroutine can have up to three levels of nesting. If there is a need to nest to a level greater than 3, then the segment containing the three lowest levels of nesting can be made into a subroutine therefore overcoming the limitation.
    ////////

    As explained in the other thread, the goal here is to drill some holes into the outer diameter of a workpiece, but the book says that there is no canned cycle that does this, so I'm attempting to make one using Macros.

    The variables that I'm changing are only the Degrees the C-axis has to rotate to.

    This code, for example, would try to put a hole into 0, 90, 180, and 270 degrees in the OD and would look something like this:

    ;
    T101; (pick tool 1)
    M14; (clamp spindle brake)
    M154; (c axis engage)
    G98 (feed/minute)
    G00 X1.0 (rapid T101 to x1.0)
    #101=0; (variable for c axis degree)
    WH [#101LT360] DO1;
    G01 C#101 F500; (rotate spindle #101 degrees at 500RPM)
    G01 X0.75 F2.; (drill into OD down to 0.75")
    G00 X1.0; (retract)
    #101=#101+90
    END1; (end of loop)
    G01 C0. F500.; (return C axis to zero)
    M15; (unclamp spindle brake)
    M155; (c axis disengage)
    ;

    I cannot seem to enter the WH into the control when in MDI mode, however. As soon as I hit the enter/insert key after the WH (or) WHILE, or after the #101=0, I get a "Bad code" error.

    I have not tried putting the program in a file and loading it that way (in case it's just MDI that doesn't allow for parameter passing).

    I know I bug you guys with a lot of questions, but I'm willing to try stuff and learn and wouldn't wanna break anything... so I'm careful and check usually here or with software before running....

  2. #2
    Join Date
    May 2006
    Posts
    265
    This is how I should do this on my machine with fanuc macrob.

    I dont think you should have spindlebreak clamp when moving c-axis unless it is a
    anti vibration break. Ive got 2 breaks on the machine, both the antivibration and
    another one to use when I am machining in other axis then C...

    %
    :O1000(MAIN)
    G28U0
    G28W0
    G00T0101
    M35 - ENGAGE C-AXIS
    G28H0 - HOME C-AXIS
    G98
    G97S5000M34 LIVE TOOL SPINDEL ON
    G00X1Z-1 MOVE TO POSITION FOR FIRST HOLE
    G66P1001X0.75F2
    C90 - MOVES TO C90 AND REPEATS MACRO 1001
    C180
    C270
    G80
    G28U0
    G28W0
    M35 - LIVE TOOL SPINDLE OFF
    M5 - TURNING MODE ON
    M30
    %

    %
    :O1001(CYCLE/RADIAL DRILLING/NO PECKING)
    #1=#5001 - READ X AXIS POSITION AND SAVE FOR CLEARENS.
    M89- SPINDLE CLAMP HIGH ON
    G1X#24F#9
    G0X#1
    M90 - SPINDLECLAMP OFF
    M99
    %

  3. #3
    Join Date
    Mar 2005
    Posts
    1498
    070721-1530 EST USA

    Jorge:

    What are the semicolons for? I am not where I can test their effect. Your code looks ok on the surface. Try while instead of WH. Also load the program into an O-number program. If these don't work forget the while, and use line numbers, an if - then test, and a GOTO at the loop end.

    I seldom test anything in MDI vs single step in a program. It is easier to edit code on a computer and dowload to the machine for anything other than a couple lines.

    Why not post this under HAAS?

    .

  4. #4
    Join Date
    Mar 2006
    Posts
    81
    IRT All:

    I tried loading the program from a file, rather than entering it directly in MDI mode. The control reads the code all the way up until the first PoundSign (#), then does not read anything else and gives out an alarm.

    It cannot understand Pound, so I'm guessing there's a chance it just does not have Macros enabled... I'm guessing.

    @M-Man:

    I actually put the spindle brake code (M14) after the fact. It doesn't seem to make any difference whether I put it on or not, so I left it in. Again, I haven't actually cut a piece, so I don't know whether the spindle is locking when rotating.

    I have a bad habit of doing excessive tests before I cut anything (plus we don't have the drillbit for the livetooling spindle, nor do we have the air pressure connected yet. It's there, and a while back it was connected, but they disabled it because they saw 'no need at the time').

    I will examine your code and will showcase my results later.

    @Gar:

    The semicolons are just "End of Line" symbols. In MDI mode, it's equivalent to hitting the "Enter" key on a keyboard. When you write the program in a PC you don't need them, because usually the control adds them as it reads the code.

    In MDI mode, you put them in order to move down a line. Aside from that, they don't have any real purpose, so from a PC standpoint, you can ignore them.

    I didn't post this under Haas because I figured it was strictly a G-Code thing. I suppose with all the sub-forums that exist here, I probably should have.

    There's also the off-chance that the machine doesn't have the "Macros" option enabled, which would mean that anything with a # on it will not read.

  5. #5
    Join Date
    Mar 2005
    Posts
    1498
    070722-0811 EST USA

    Jorge-D-Fuentes:

    If the program fails at the
    #101 = 0
    then that is a good indicator of no MACRO capability.

    .

  6. #6
    Join Date
    Jul 2005
    Posts
    12177
    Quote Originally Posted by gar View Post
    070722-0811 EST USA

    Jorge-D-Fuentes:

    If the program fails at the
    #101 = 0
    then that is a good indicator of no MACRO capability.

    .
    With Haas you can turn Macro on for a trial period of 200 hours. Go to Parameter 57 and in the right hand column you will se ENABLE MACRO. It will show 0T if it is not turned on and 1 if it is. Just type 1 and WRITE and it will turn on. You have to turn off setting 7 and push Estop to do this.
    An open mind is a virtue...so long as all the common sense has not leaked out.

  7. #7
    Join Date
    Apr 2005
    Posts
    3634
    Jorge-D-Fuentes

    This code, for example, would try to put a hole into 0, 90, 180, and 270 degrees in the OD and would look something like this:

    ;
    T101; (pick tool 1)
    M14; (clamp spindle brake)
    M154; (c axis engage)
    G98 (feed/minute)
    G00 X1.0 (rapid T101 to x1.0)
    #101=0; (variable for c axis degree)
    WH [#101LT360] DO1;
    G01 C#101 F500; (rotate spindle #101 degrees at 500RPM)
    G01 X0.75 F2.; (drill into OD down to 0.75")
    G00 X1.0; (retract)
    #101=#101+90
    END1; (end of loop)
    G01 C0. F500.; (return C axis to zero)
    M15; (unclamp spindle brake)
    M155; (c axis disengage)



    Do you really need a (WHILE DO END Loop) macro, to rotate only 4 angles?






    .

  8. #8
    Join Date
    Mar 2006
    Posts
    81
    The example was for only four angles.

    In reality, the pieces might have as many as forty to sixty holes in a channel all the way around.

    So yes, a do-while loop would be more efficient to write than one hundred and sixty lines.

    @Geof & Gar.
    I'll check if the setting is enabled. Thanks for telling me the parameter/setting to check. I think some machines have it on, and some don't, and the one that happens to have livetooling doesn't have it. I'll check later.

    EDIT
    @Geof & Gar:
    Yeah it was off. It was set to 0T. I went to Parameter Lock and turned it off, then hit the Emergency Switch, and turned it on by pressing 1, then WRITE/ENTER. Then released the emergency and restarting the machine (I'm familiar with this procedure from when I had to change the Z Max Travel Limits). I turned it back on and now the Macro setting reads "1T". I'm guessing the "T" is for "Trial".

    I'll run the code again later.

  9. #9
    Join Date
    Jul 2005
    Posts
    12177
    Quote Originally Posted by Jorge-D-Fuentes View Post
    The example was for only four angles.

    In reality, the pieces might have as many as forty to sixty holes in a channel all the way around.

    So yes, a do-while loop would be more efficient to write than one hundred and sixty lines.
    If your hole spacing is constant, i.e. same angular spacing same linear spacing you could probably do it using incremental moves in nested subroutines with an L count.
    An open mind is a virtue...so long as all the common sense has not leaked out.

  10. #10
    Join Date
    Feb 2006
    Posts
    992
    Jorge;

    The reason you get an alarm on first # because it's useless number, as computer rule is any number equal to 0 is null..... all the variable in the machine right now is treat as 0.


    Quote Originally Posted by Jorge-D-Fuentes View Post
    ;
    T101; (pick tool 1)
    M14; (clamp spindle brake)
    M154; (c axis engage)
    G98 (feed/minute)
    G00 X1.0 (rapid T101 to x1.0)
    #101=0; (variable for c axis degree)
    WH [#101LT360] DO1;
    G01 C#101 F500; (rotate spindle #101 degrees at 500RPM)
    G01 X0.75 F2.; (drill into OD down to 0.75")
    G00 X1.0; (retract)
    #101=#101+90
    END1; (end of loop)
    G01 C0. F500.; (return C axis to zero)
    M15; (unclamp spindle brake)
    M155; (c axis disengage)
    ;
    I will change to some thing like this?

    #100=4(number of hole)
    #101=360/#100

    T101; (pick tool 1)
    M14; (clamp spindle brake)
    M154; (c axis engage)
    G98 (feed/minute)
    G00 X1.0 (rapid T101 to x1.0)
    C0(***)this can be vary, some require difference angle .....so revise math need.
    WH [#101LT360] DO1;
    G01 X0.75 F2.; (drill into OD down to 0.75")
    G00 X1.0; (retract)
    #101=#101+#101
    END1; (end of loop)
    G01 C0. F500.; (return C axis to zero)
    M15; (unclamp spindle brake)
    M155; (c axis disengage)
    The best way to learn is trial error.

  11. #11
    Join Date
    Mar 2006
    Posts
    81
    An L count, eh?
    "I'm interested in this".

    Is an L count a procedure that would not require us to purchase the Macro option?

    Also, I ran the code but forgot to put the periods next to the numbers representing the degrees, so the spindle did not turn, and my guys are doing a big production run so I can't test my code right now... but I will later.

    I gotta look into this L Count. Yes, our holes would be equidistant from one another (I believe), both on the Z and on the C. What might change would be whether it goes all the way around, but often it does.

    I might make new programmable code whether this is the case.

    EDIT:
    @NewTexas:

    I don't think this is the case. I managed to get the code working with no issues even if the first variable happened to equal Zero. The reason it is Zero is because I'm drilling the first hole at Zero degrees on the C Axis, so it's far from a useless number.

    @Everyone:

    I'd like to thank everyone who helped me with this problem.
    I'd also like to announce that the following code does what I want it to do to the letter.

    %
    O09899
    T101 (pick tool 1)
    M14 (clamp spindle brake)
    M154 (c axis engage)
    G98 (feed/minute)
    G00 X1. (rapid T101 to X1.0)
    #101= 0. (variable for c axis degree)
    #102= 45. (variable for degree change)
    #103= 360. (variable for total degrees)
    WH [ #101 LT #103 ] DO1 (WHILE DO END loop)
    G01 C#101 F500. (rotate spindle #101 degrees at 500 RPM)
    G04 P2.
    G01 X0.75 F2. (drill into OD down to 0.75")
    G00 X1. (retract)
    #101= #101 + #102 (add 90 degrees to variable #101)
    END1 (end of loop)
    G01 C0. F250. (return c axis to zero)
    M15 (unclamp spindle brake)
    M155 (c axis disengage)
    M30
    %

    One of the errors I was getting was that the spindle was not rotating. After examining the variables, I realized that all the variables for the C Axis require a period at the end (30 degrees is "30.", not "30").
    I also modified the code a bit so that I get the amount of holes I want given a certain portion of the ring.

    Say I wanted five holes on one quarter of the ring, I can assign "#103 = 90." instead of "#103=360."
    Also, I can say how many holes I want by just getting the degrees. It's a little crude because it requires a bit of math, but I can say I want five holes by assigning "#102=9.". So now I can put five holes on a quarter of a ring or forty holes on the entire circumference, etc.

    I have to see if the company will pay for the option to Macro this correctly.

  12. #12
    Join Date
    Mar 2005
    Posts
    1498
    070723-1826 EST USA

    newtexas2006:

    Your comment:
    The reason you get an alarm on first # because it's useless number, as computer rule is any number equal to 0 is null..... all the variable in the machine right now is treat as 0.
    is nonsense.

    The code line (block)
    #100 = numeric value
    on execution results in the variable #100 and only #100 being loaded with the value of "numeric value" whether that value is 25, 25., 0, 0., or null. In HAAS null and 0 are not identical. The HAAS null is #0 . However, the manual is confusing.

    From the current HAAS on-line manual.

    VARIABLE USAGE
    All variables are referenced with a pound sign (#) followed by a positive number. Examples are: #1, #101, and #501.
    Variables are decimal values that are represented as floating point numbers. If a variable has never been used, it can
    take on a special “undefined” value. This indicates that it has not been used. A variable can be set to undefined with
    the special variable #0. #0 has the value of undefined or 0.0 depending on the context it is used in. Indirect references
    to variables can be accomplished by enclosing the variable number in brackets.
    #[<Expression>]
    The expression is evaluated and the result becomes the variable accessed. For example:
    When you make a G65 subroutine call all local variables in the called subroutine are assigned the null value unless the variable corresponds to a parameter on the calling line.

    .

  13. #13
    Join Date
    Mar 2005
    Posts
    1498
    070723-1852 EST USA

    Jorge:

    You have MACRO capability since you can do
    #100 = something
    and WHILE works
    .

    For your line
    #101= 0. (variable for c axis degree)
    I would suggest a comment like
    (Angular position of first hole)

    Once you assign a fixed value to the variable it actually becomes a constant. Your #103 could be changed to the number of holes. Then add another variable that keeps track of the number of holes processed, and change the code to work with the number of holes.

    (edit) Note your first hole does not have to be at 0 as I am sure you know. (end edit)
    .

  14. #14
    Join Date
    May 2006
    Posts
    265
    Try this... What control do you use?

    %
    :O1000(MAIN)
    G00X1Z-1 MOVE TO POSITION FOR FIRST HOLE
    G65P1001X0.75F2A50 - X= Drill to dia, F= feed, A = no of holes to drill eq/360 degrees.
    G28U0
    G28W0
    M30
    %

    %
    :O1001(CYCLE/RADIAL DRILLING/NO PECKING)
    #103=360/#1
    #2=#5001 - Read X position for clearens
    N0001
    #3=#3+#103
    G1X#24F#9
    G0X#2
    G0C#3
    IF[#3LT360]GOTO1
    M99
    %

  15. #15
    Join Date
    Mar 2006
    Posts
    81

    Cool

    @M-Man:

    I'm on a Haas OL-1.
    Examining your code below, I've some comments/question:

    %
    :O1000(MAIN)
    G00 X1Z-1; (MOVE TO POSITION FOR FIRST HOLE)
    G65 P1001 X0.75 F2 A50; (X= Drill to dia, F= feed, A = no of holes to drill eq/360 degrees)(Jorge's note: I don't know if the HAAS control lets me use "A" in this case)
    G28U0;
    G28W0;
    M30;
    %

    %
    :O1001(CYCLE/RADIAL DRILLING/NO PECKING)
    #103=360/#1; (Jorge's note: It might not always be an all-around thing, so I might not use this bit of code where the 360 is always there. Also, #1 wasn't defined yet, though that should be OK)
    #2=#5001; (Read X position for clearance) (The Haas control does use #5001 for "Last Target Position" but #5001, specifically, deals with the X position, so I'm guessing this is read from the position in O01000; in the program line since that's its 'last position)
    N0001
    #3=#3+#103; (Jorge's note: This looks like it's the incremental for the degrees each turn/loop)
    G1X#24F#9; (Jorge's note: This appears to be the movement that drills inwards, but I didn't see variables #24 or #9 declared before at all, so this is a little confusing)
    G0X#2; (Jorge's note: retract? Variable #2 wasn't defined)
    G0C#3; (Jorge's note: rotate to 360/#1, which I'm guessing should've been 360/50)
    IF[#3LT360]GOTO1; (Jorge's note: Ah, the IF Statement instead of the WHILE statement. This still counts as a Macro though, right? Also, again, I might not always want the holes all the way around. But yes, I can see this)
    M99
    %

    @Gar:

    Yeah I know I don't have to start drilling on angle Zero, I just felt like starting there for my personal simplicity.

    I will add the comment line as suggested. My codes have comments on every line, upon perfecting the code. But right now that I was still trying to figure it out, I didn't add it.

    @All:
    You've all been tremendously helpful. I'm very grateful for your assistance.

  16. #16
    Join Date
    Nov 2005
    Posts
    1468
    I don't know specificaly what your lathe will accept, so excuse me if I'm way off base here, but shouldn't it be a WEND command (WhileEnd) not a straight END command?

    Apologies if this is not relevant, it's just that in BASIC it's WEND... just a thought?
    I love deadlines- I like the whooshing sound they make as they fly by.

  17. #17
    Join Date
    Mar 2005
    Posts
    1498
    070724-1008 EST USA

    Jorge:

    O1001 is a called subroutine with passed in parameters from the G65 line in the calling program.

    See the HAAS manual under MACROS for the mapping of letter addresses on the G65 calling line to the #-local variables in the called program. A50 maps the value 50 into #1, X0.75 maps 0.75 into #24, and F2 maps 2 into #9.

    I believe M-man assumed #3 to be 0. on entry to the subroutine. This may or may not be true. HAAS makes all local variables null on entry to a called G65 routine. Therefore, on the first pass thru the N1000 loop #3 = #3 + #103 is the same as #3 = #103 if null is treated as 0.

    #3 is the new angular position on each pass thru the loop. I would have put the #3 = line just before the C axis move for clarity of association. Or I might do the C axis move at the beginning of the loop with whatever initial value was desired having been loaded into #3 before the loop. In this case the incrementing of #3 would be after the move.

    There may or may not be decimal point problems.

    .

  18. #18
    Join Date
    May 2006
    Posts
    265
    the #5001 parameter is the X axis position the machine currently have, ofcoz it is probably not the same on your lathe as on my machine, but all machine has this kind of parameters that you can read... Just add a angle to fill varible and use current C-axis postition when entering macrocall as position of first hole, if you need to. ..

    #3 should be null, this would be true if macro just were used once during prg, (prg restart/reset should set this back to null for next part)..

  19. #19
    Join Date
    Mar 2005
    Posts
    1498
    070725-0842 EST USA

    M-man:

    On HAAS and in the program in question the O1001 is an external subroutine called from a G65 in a different O-number program. Every time O1001 is called all the local variables are nulled except the ones associated with passed in parameters. This I described previously.

    If O1001 were run as a main program, then it would not function properly because there are local variables that would not be loaded with correct values. Any time a main program is started the local variables are nulled. Power-up is not required to null these, just starting the program does the nulling.

    Also note that if O1001 had a G65 in it and called some other external subroutine, then a new set of local variables is created for that called subroutine, and the local variables associated with O1001 are unaltered.

    When you return from O1001 to the main program the local variable values in the O1001 subroutine are destroyed. Whatever local variables in the main program that may have been loaded before the call to O1001 are restored to their value before calling O1001.

    This type of operation all results from the local variables being stored on a memory stack.

    .

Similar Threads

  1. Closed loop vs. open loop
    By pelesl in forum Benchtop Machines
    Replies: 10
    Last Post: 04-06-2007, 10:56 PM
  2. Lathe conversion - open loop vs closed loop
    By bhowden in forum Uncategorised MetalWorking Machines
    Replies: 7
    Last Post: 03-21-2006, 10:56 PM
  3. Closed loop....open loop?
    By DAB_Design in forum CNC Machine Related Electronics
    Replies: 10
    Last Post: 06-26-2004, 10:02 PM
  4. Closed Loop Driver vs. Closed Loop Computer
    By ojibberish in forum Gecko Drives
    Replies: 3
    Last Post: 06-08-2004, 05:30 PM
  5. closed loop
    By georgebarr in forum DIY CNC Router Table Machines
    Replies: 9
    Last Post: 06-01-2003, 03:39 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
  •