586,905 active members*
2,740 visitors online*
Register for free
Login
Results 1 to 18 of 18
  1. #1
    Join Date
    Jul 2009
    Posts
    25

    Proofreading a Bit of Code

    I'm trying to write a simple macro to cut a series of through holes at variable depths based on the number of cycles, basically trying to use all the flutes on my endmill before changing it.

    I'm running it on a Haas TM-1P. The maximum depth is .650, the initial depth is .05, and the number of cycles before the step down is 20. #100 is my cycle counter and #101 is my depth variable. Here's the code:

    IF [#101 LT 0.05] THEN #101=0.05
    #100=#100+1
    IF #100=20 THEN #101=#101+0.05
    IF #100=20 THEN #100=0
    IF [#101 GE 0.650] THEN GOTO 10

    ...

    (This represents the cutting routines)
    G13 Z-#101 I0.14 D03 F12.

    ...

    N10
    (ALARM MACRO)
    #3000=115 (CHANGE TOOL)
    M30



    Does it look sound or does it need changes?

  2. #2
    Join Date
    Feb 2006
    Posts
    338
    The code and logic look good to me.

  3. #3
    Join Date
    May 2007
    Posts
    1003
    Wish we had a Haas just so I would know how the code works on that brand. That code wouldn't work on a Fanuc control. It would have to read

    IF [#101 LT 0.05] THEN #101=0.05
    #100=#100+1
    IF [#100EQ20] THEN #101=#101+0.05
    IF [#100EQ20] THEN #100=0
    IF [#101 GE 0.650] GOTO10

  4. #4
    Join Date
    Feb 2006
    Posts
    338
    wow, that slipped right by me. g-codeguy is right.
    [] around if conditions, and EQ instead of = inside them.

  5. #5
    Join Date
    Feb 2007
    Posts
    592

    Exclamation

    Also - if .65 is a usable depth you will never cut at .65 as is.

    Need to replace the "GE" with "GT".

  6. #6
    Join Date
    Jul 2009
    Posts
    25
    Good points.

    You're probably right about the syntax for Haas as well. I just cobbled this together out of examples they had in the manual. They do require you to bracket statements using Booolean operators, but in some samples they wrote it simply using "=" in others it was bracketed with "EQ" representing the operator. I suppose I'll find out if the processor doesn't like it when I run it the first time.

    And yeah, I shouldn't have used GE in the maximum depth statement. Good call.

    Thanks for the feedback fellas.

  7. #7
    Join Date
    Nov 2009
    Posts
    23
    I think HAAS uses mostly Fanuc code anyways -with a few alterations.

    Don't forget to reset the one common variable at the end, otherwise it could start as 0.65 on the next run -right? Or am I looking at it wrong?

    N20 #101=0; ~before the M30.

  8. #8
    Join Date
    May 2007
    Posts
    1003
    Quote Originally Posted by Medm View Post
    I think HAAS uses mostly Fanuc code anyways -with a few alterations.

    Don't forget to reset the one common variable at the end, otherwise it could start as 0.65 on the next run -right? Or am I looking at it wrong?

    N20 #101=0; ~before the M30.

    You are absolutely right. I am guilty of looking at the syntax and not the logic. Good catch.

  9. #9
    Join Date
    Feb 2006
    Posts
    338
    Quote Originally Posted by Medm View Post
    Don't forget to reset the one common variable at the end, otherwise it could start as 0.65 on the next run -right? Or am I looking at it wrong?

    N20 #101=0; ~before the M30.
    You don't generally want to use automatic resets. As it is it will track usage across parts. If he just changed it for the last hole of a part it would still keep the correct count on the next part rather than reset automatically.

  10. #10
    Join Date
    May 2007
    Posts
    1003
    Quote Originally Posted by dpuch View Post
    You don't generally want to use automatic resets. As it is it will track usage across parts. If he just changed it for the last hole of a part it would still keep the correct count on the next part rather than reset automatically.
    I'm not following you. Maybe because I am so tired I can't think straight. I'm not familiar with mills. On our lathes if it machined 20 holes to .650 depth, and then alarmed, another operation or 2 or whatever was run, and then came back to this operation on the next part, the #101 would still read .650 unless the machine had been powered off.

    What am I missing?

  11. #11
    Join Date
    Feb 2006
    Posts
    338
    Medm was suggesting to automatically reset #101 (effectively the life counter) at the end of the program. Thus you lose track of the tool usage at the end of each cycle. Even if my tool SHOULD always end it's life at the end of the program, I would not automatically reset it. That just means if they forget to change the tool it will NOT alarm, and produce bad parts and/or break.

  12. #12
    Join Date
    Nov 2009
    Posts
    23
    If you properly examine the code, the variable #101 is not the life counter. That is variable #100 -which is reset in the line;

    IF [#100EQ20] THEN #100=0


    The role of #101 is to change the 'Z' depth. If it is not reset, you will eventually run into a situation where the 'Z' is beyond the usable flute length and therefore a potential crash situation.

  13. #13
    Join Date
    Feb 2006
    Posts
    338
    Medm, Look again, there are two "counters".
    #100 is 0 to 19 and equals the number of holes before changing 0.05 in Z depth
    #101 is Z depth 0.05 to 0.650 and equals the tool life, after that the tool needs to be changed

    So 20 holes * 14 Z depths per tool, then it alarms out telling the operator to change the tool. Your wanting to reset #101 so it will not alarm out.

    IF [#101 GT 0.650] THEN GOTO 10
    ...
    N10
    (ALARM MACRO)
    #3000=115 (CHANGE TOOL)
    M30

  14. #14
    Join Date
    Nov 2009
    Posts
    23
    You are aware of the fact that #101 is a common variable?

    Being a common variable, it will hold its' value until told otherwise or at a machine power-off.

    My point, once again is to reset #101 after the alarm is issued.(nuts)

  15. #15
    Join Date
    Jul 2009
    Posts
    25
    Medm is right. I forgot to reset my depth variable in the alarm branch. It would just perpetually stay at .650 and alarm every cycle without that.

    Here's a little background for the operation to clear up the confusion:

    I'm milling four through holes on a piece part with .05 thickness. We found in our first trials that the tool wears enough to cut the hole under size at about 23 pieces which would be 92 holes. The macro is to indeed count twenty cycles--not twenty individual holes--then drop a step to the next fresh region of flutes. So theoretically I'll get 260 good pieces and 1040 individual holes from each tool.

    It's my first attempt at a macro, and I'm turning on the user macro trial during our next production run to pitch the option to our production manager. I think this is a good simple application to show him how he'd get the money back pretty quickly on paying the $3k for the code. We're on a tight schedule, though, and I needed to make sure this code wasn't going to be a huge time sink before we get parts at the machine.

  16. #16
    Join Date
    Feb 2006
    Posts
    338
    Quote Originally Posted by Medm View Post
    You are aware of the fact that #101 is a common variable?

    Being a common variable, it will hold its' value until told otherwise or at a machine power-off.

    My point, once again is to reset #101 after the alarm is issued.(nuts)
    Ahh, I understand your intent better, before I read you wanted to reset it at the end of the part program for some reason. If you put it after the alarm though it will never be reset either, the alarm will stop program execution. It would need to be right before it.

    I still do not favor this method of resetting it. Manually setting #101 to zero when to the tool is changed would be my first choice. Another might be to run a program that resets it. This could also be made into a G or M code to make resetting via MDI easier.

  17. #17
    Join Date
    Jul 2009
    Posts
    25
    Quote Originally Posted by dpuch View Post
    I still do not favor this method of resetting it. Manually setting #101 to zero when to the tool is changed would be my first choice. Another might be to run a program that resets it. This could also be made into a G or M code to make resetting via MDI easier.
    Well, in my case I'm the sole setup tech in my facility and the operators aren't trained to interface with the machine any further than doors, clamps, and the cycle start button, so I don't really need to create any further contingencies.

    I was originally looking into resetting the depth only when the tool length offset was changed--inferring that a tool change happened--but I don't think there's a macro variable that tracks that sort of input. It would be a nice finishing touch, though.

  18. #18
    Join Date
    Feb 2006
    Posts
    338
    [#[2000+#4120]+#[2200+#4120]] will give the tool length plus tool wear of the current T call (#4120). If your precalling the next tool to be used, you have to be careful where you use this one. At that point I usually switch to currently activated length offset toll number (#4111) instead.

    Now if your not tying it to the alarm, I think you can reset it automatically with a reasonably small chance of re-using a dull tool. I think ignoring tool length wear is desired for this check.
    So probably something like this:


    IF [#102EQ#[2000+#4111]] GOTO 3
    (Reset if current offset is different than #102)
    #100=0
    #101=0.05
    #102=#[2000+#4111] (set #102 to the tool length)
    N0003

    IF [#101 LT 0.05] THEN #101=0.05
    #100=#100+1
    IF [#100EQ20] THEN #101=#101+0.05
    IF [#100QE20] THEN #100=0
    IF [#101 GT 0.650] THEN GOTO 10

Similar Threads

  1. Replies: 4
    Last Post: 03-29-2011, 02:39 PM
  2. Replies: 8
    Last Post: 12-15-2010, 09:32 PM
  3. learning g code or cad-cam code output?
    By slow_rider in forum G-Code Programing
    Replies: 3
    Last Post: 02-28-2010, 03:48 AM
  4. G-Code viewing source code
    By Hussam in forum Visual Basic
    Replies: 3
    Last Post: 03-15-2009, 06:15 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
  •