Page 1 of 2 12 LastLast
Results 1 to 12 of 19

Thread: Macro WHILE DO END Loop (Lathe)

  1. #1
    Registered
    Join Date
    Mar 2006
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0

    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
    Registered
    Join Date
    May 2006
    Location
    Sweden
    Posts
    265
    Downloads
    0
    Uploads
    0
    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
    gar
    gar is offline
    Registered
    Join Date
    Mar 2005
    Location
    USA
    Posts
    1,498
    Downloads
    0
    Uploads
    0
    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
    Registered
    Join Date
    Mar 2006
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0
    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
    gar
    gar is offline
    Registered
    Join Date
    Mar 2005
    Location
    USA
    Posts
    1,498
    Downloads
    0
    Uploads
    0
    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
    Registered
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    11,964
    Downloads
    0
    Uploads
    0
    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
    Moderator Switcher's Avatar
    Join Date
    Apr 2005
    Location
    mydxf.blogspot.com
    Posts
    3,665
    Downloads
    0
    Uploads
    0
    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
    Registered
    Join Date
    Mar 2006
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0
    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
    Registered
    Join Date
    Jul 2005
    Location
    Canada
    Posts
    11,964
    Downloads
    0
    Uploads
    0
    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
    Registered CNCRim's Avatar
    Join Date
    Feb 2006
    Location
    usa
    Posts
    949
    Downloads
    0
    Uploads
    0
    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
    Registered
    Join Date
    Mar 2006
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0
    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.
    Last edited by Jorge-D-Fuentes; 07-23-2007 at 03:55 PM.


  • #12
    gar
    gar is offline
    Registered
    Join Date
    Mar 2005
    Location
    USA
    Posts
    1,498
    Downloads
    0
    Uploads
    0
    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.

    .


  • Page 1 of 2 12 LastLast

    Similar Threads

    1. Closed loop vs. open loop
      By pelesl in forum Benchtop Machines
      Replies: 10
      Last Post: 04-06-2007, 05:56 PM
    2. Lathe conversion - open loop vs closed loop
      By bhowden in forum General Metal Working Machines
      Replies: 7
      Last Post: 03-21-2006, 04:56 PM
    3. Closed loop....open loop?
      By DAB_Design in forum General Electronics Discussion
      Replies: 10
      Last Post: 06-26-2004, 05:02 PM
    4. Closed Loop Driver vs. Closed Loop Computer
      By ojibberish in forum Gecko Drives
      Replies: 3
      Last Post: 06-08-2004, 12:30 PM
    5. closed loop
      By georgebarr in forum DIY CNC Router Table Machines
      Replies: 9
      Last Post: 06-01-2003, 10:39 AM

    Posting Permissions


     


    About CNCzone.com

      We are the largest and most active discussion forum from DIY CNC Machines to the Cad/Cam software to run them. The site is 100% free to join and use, so join today!

    Follow us on

    Facebook Dribbble RSS Feed


    Search Engine Friendly URLs by vBSEO ©2011, Crawlability, Inc.