Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By angelw

Thread: GOTO / RETURN question

  1. #1
    keencoyote is offline Plastic
    Join Date
    Mar 2009
    Location
    Kenmore, Washington
    Posts
    1

    Default GOTO / RETURN question

    I would like to branch to a pattern of calls in my code and return at the end of the pattern. I would prefer to do this without calling a sub program. Is there such a call as "RETURN" so that my "pattern" code does not have to be aware of where it is called from?

    --------
    (Sudo code - running on an Okuma - some G codes are different!)
    (Spot drill)
    N100 G0 G17 G20 G40 G53 G80 G90
    N110 G15 H0
    N120 M6 T2 T3
    N130 S8000 F40. M3
    N140 GOTO N1000 (run the pattern)
    N150 M5
    N160 M6 T3 T4
    N170 S4000 F20. M3
    N180 GOTO N1000 (repeat the pattern)
    N190 M5
    N200 M30

    (Pattern)
    N1000 G0 X0 Y0
    N1010 G56 H2 Z2.
    N1020 G1 Z1
    N1030 G81 X0 Y0 Z-.1 R.2 F25 M54
    N1050 X1.
    N1060 X0 Y1.
    N1070 X1.
    N1080 (other calls)
    N1090 !!!!! RETURN !!!!!! <- Is there such a call?????
    ------------------

  2. #2
    angelw is offline Hot Rolled
    Join Date
    Sep 2010
    Location
    Victoria Australia
    Posts
    819

    Default

    Quote Originally Posted by keencoyote View Post
    I would like to branch to a pattern of calls in my code and return at the end of the pattern. I would prefer to do this without calling a sub program. Is there such a call as "RETURN" so that my "pattern" code does not have to be aware of where it is called from?

    --------
    (Sudo code - running on an Okuma - some G codes are different!)
    (Spot drill)
    N100 G0 G17 G20 G40 G53 G80 G90
    N110 G15 H0
    N120 M6 T2 T3
    N130 S8000 F40. M3
    N140 GOTO N1000 (run the pattern)
    N150 M5
    N160 M6 T3 T4
    N170 S4000 F20. M3
    N180 GOTO N1000 (repeat the pattern)
    N190 M5
    N200 M30

    (Pattern)
    N1000 G0 X0 Y0
    N1010 G56 H2 Z2.
    N1020 G1 Z1
    N1030 G81 X0 Y0 Z-.1 R.2 F25 M54
    N1050 X1.
    N1060 X0 Y1.
    N1070 X1.
    N1080 (other calls)
    N1090 !!!!! RETURN !!!!!! <- Is there such a call?????
    ------------------
    What control make and model are you working with?

    Regards,

    Bill

  3. #3
    EDM JOE is offline Aluminum
    Join Date
    Oct 2009
    Location
    Tempe, Arizona
    Posts
    109

    Default

    How about establishing a counter in your program steps your GOTO line number value (1000) for the "subprogram" that is to be included in the code of your main program? Thus line number N1000 initially would be called N#600 (for example). You would also need to step the value of your subsequent "subprogram" GOTO commands. This could be achieved by adding 1 to variable #600. Then once you reach the end of calling patterns, use GOTO to jump around the "subprogram" section, and get it to the M30. Each time you reiterate the program, #600 is reinitialized.

    #600=1000 (Subprogram included in this program)

    N100 G0 G17 G20 G40 G53 G80 G90
    N110 G15 H0
    N120 M6 T2 T3
    N130 S8000 F40. M3
    N140 GOTO N#600 (run the pattern)
    N150 M5
    N160 M6 T3 T4
    N170 S4000 F20. M3
    N180 GOTO N#600 (repeat the pattern)
    N190 M5
    N191 GOTO N9999
    N200 M30

    (Pattern)
    N#600 G0 X0 Y0
    N1010 G56 H2 Z2.
    N1020 G1 Z1
    N1030 G81 X0 Y0 Z-.1 R.2 F25 M54
    N1050 X1.
    N1060 X0 Y1.
    N1070 X1.
    N1080 (other calls)
    #600=#600+1
    N9999
    M30

    I think this scenario will work with Custom Macro B, though I am not sure if line numbers can be defined with variables, and I am unfortunately without any reference books at the moment. Does anyone know if line numbers can be defined this way?
    Last edited by EDM JOE; 07-01-2012 at 04:50 PM. Reason: forgot how to use space bar

  4. #4
    EDM JOE is offline Aluminum
    Join Date
    Oct 2009
    Location
    Tempe, Arizona
    Posts
    109

    Default

    Wait, this can't work without a second variable controlling the return line number in the "main" program. It would also need to be stepped.

  5. #5
    angelw is offline Hot Rolled
    Join Date
    Sep 2010
    Location
    Victoria Australia
    Posts
    819

    Default

    Quote Originally Posted by EDM JOE View Post
    How about establishing a counter in your program steps your GOTO line number value (1000) for the "subprogram" that is to be included in the code of your main program? Thus line number N1000 initially would be called N#600 (for example). You would also need to step the value of your subsequent "subprogram" GOTO commands. This could be achieved by adding 1 to variable #600. Then once you reach the end of calling patterns, use GOTO to jump around the "subprogram" section, and get it to the M30. Each time you reiterate the program, #600 is reinitialized.

    #600=1000 (Subprogram included in this program)

    N100 G0 G17 G20 G40 G53 G80 G90
    N110 G15 H0
    N120 M6 T2 T3
    N130 S8000 F40. M3
    N140 GOTO N#600 (run the pattern)
    N150 M5
    N160 M6 T3 T4
    N170 S4000 F20. M3
    N180 GOTO N#600 (repeat the pattern)
    N190 M5
    N191 GOTO N9999
    N200 M30

    (Pattern)
    N#600 G0 X0 Y0
    N1010 G56 H2 Z2.
    N1020 G1 Z1
    N1030 G81 X0 Y0 Z-.1 R.2 F25 M54
    N1050 X1.
    N1060 X0 Y1.
    N1070 X1.
    N1080 (other calls)
    #600=#600+1
    N9999
    M30

    I think this scenario will work with Custom Macro B, though I am not sure if line numbers can be defined with variables, and I am unfortunately without any reference books at the moment. Does anyone know if line numbers can be defined this way?
    Hi Joe,
    If you're referring to Fanuc Custom Macro B, N#600 is not allowed. Variables can't be used with the N address.

    The following will work if its a Fanuc Control

    N1 G0 G17 G20 G40 G53 G80 G90
    G15 H0
    M6 T2 T3
    S8000 F40. M3
    #1=100
    GOTO900 (run the pattern)
    N100 M5
    M6 T3 T4
    S4000 F20. M3
    #1=110
    GOTO900 (repeat the pattern)
    N110 M5
    M30

    (Pattern)
    N900 G0 X0 Y0
    G56 H2 Z2.
    G1 Z1
    G81 X0 Y0 Z-.1 R.2 F25 M54
    X1.
    X0 Y1.
    X1.
    (other calls)
    GOTO#1

    The reason why the request for the Make and Model of the control, is that some Fanuc Series are able to call a Sub Program contained in the existing Main Program by using a Q address with M98 and return to the block following the call block with M99.

    Regards,

    Bill
    EDM JOE likes this.

  6. #6
    zero_divide's Avatar
    zero_divide is online now Hot Rolled
    Join Date
    Feb 2012
    Location
    Toronto
    Posts
    518

    Default

    He said OKUMA.
    And there is no RETURN statement in there. (or anywhere else i know of)

    If there is a need to branch out some operations or repeat a program you need to use either sub programs or if then goto statemnts

    like here i do this to repeat progs on my okuma lathe(for barfeeding)

    O1
    CN=7 (NUMBER OF CYCLES TO REPEAT)
    CC=0 (CURRENT CYCLE)
    N0
    ......
    (part program)
    ......
    CC=CC+1
    IF [ CC LT CN ] N0
    M2

  7. #7
    angelw is offline Hot Rolled
    Join Date
    Sep 2010
    Location
    Victoria Australia
    Posts
    819

    Default

    Quote Originally Posted by zero_divide View Post
    He said OKUMA.
    And there is no RETURN statement in there. (or anywhere else i know of)

    If there is a need to branch out some operations or repeat a program you need to use either sub programs or if then goto statemnts

    like here i do this to repeat progs on my okuma lathe(for barfeeding)
    Hi Zero,
    It pays to read the Posts carefully. I didn't even notice the comment in brackets. However, you can use the same logic as shown in my Post #5, only using Okuma format for the variable designation, if the pattern repeat was to be called from various points in the program and return to the block following the call block.

    Regards,

    Bill

  8. #8
    zero_divide's Avatar
    zero_divide is online now Hot Rolled
    Join Date
    Feb 2012
    Location
    Toronto
    Posts
    518

    Default

    I am not sure you can use variable as a line number for GOTO statement on Okuma though.
    Would be great if we could though.
    Come Tuesday i will check it on our captain.

  9. #9
    annoying's Avatar
    annoying is offline Cast Iron
    Join Date
    Apr 2010
    Location
    IN, USA
    Posts
    450

    Default

    Quote Originally Posted by keencoyote View Post
    I would like to branch to a pattern of calls in my code and return at the end of the pattern. I would prefer to do this without calling a sub program. Is there such a call as "RETURN" so that my "pattern" code does not have to be aware of where it is called from?

    --------
    (Sudo code - running on an Okuma - some G codes are different!)
    (Spot drill)
    N100 G0 G17 G20 G40 G53 G80 G90
    N110 G15 H0
    N120 M6 T2 T3
    N130 S8000 F40. M3
    N140 GOTO N1000 (run the pattern)
    N150 M5
    N160 M6 T3 T4
    N170 S4000 F20. M3
    N180 GOTO N1000 (repeat the pattern)
    N190 M5
    N200 M30

    (Pattern)
    N1000 G0 X0 Y0
    N1010 G56 H2 Z2.
    N1020 G1 Z1
    N1030 G81 X0 Y0 Z-.1 R.2 F25 M54
    N1050 X1.
    N1060 X0 Y1.
    N1070 X1.
    N1080 (other calls)
    N1090 !!!!! RETURN !!!!!! <- Is there such a call?????
    ------------------
    But sometimes the easiest solution is to call a sub.

    You do know..... 1) subs do not need to be registered in the library, only need be in the same file,, 2)you can use subs to call subs....., correct?

    A file, as you pull it up in the control, that is the file and file name, not the program. The program is in that file, and there can be many programs in that file and subs also, which subs will need to be in that file to be called without being registered in the library.

    Example: PART.MIN is your file name.... open to edit......

    OMAIN (program)
    ----
    M2
    OSUB1 (sub program)
    ----
    RTS
    OSUB2 (sub program)
    ----
    RTS
    OSUB3 (sub program)
    ----
    RTS
    OSUB4 (sub program)
    ----
    RTS

    And there are different ways to call.

    CALL OSUB1 (simple call)
    CALL OSUB1 Q5 (call and repeat 5 total)
    MODIN OSUB1 (call after axis movement)
    …..
    ……..
    MODOUT

    And you can use a mix of the 3 to get the job done. The only thing you can not do, which I really wish one could, is use a variable for a block jump destination., Such as: GOTO N=VC1

    Also, there is a way to call a fixed cycle without running the cycle.... Just use NCYL in the block. I always put it in front and space after
    Example….: N1030 NCYL G81R.2Z-.1F25

    This will set the cycle without running it until the next positioning line. I find myself wondering if this may be useful to you.

    Otherwise, you might need to provide more detail if you need more specific answers

  10. #10
    annoying's Avatar
    annoying is offline Cast Iron
    Join Date
    Apr 2010
    Location
    IN, USA
    Posts
    450

    Default

    Quote Originally Posted by zero_divide View Post
    I am not sure you can use variable as a line number for GOTO statement on Okuma though.
    Would be great if we could though.
    Come Tuesday i will check it on our captain.
    Can NOT on my old 700M, and DAMN I wish I could

  11. #11
    zero_divide's Avatar
    zero_divide is online now Hot Rolled
    Join Date
    Feb 2012
    Location
    Toronto
    Posts
    518

    Default

    Quote Originally Posted by annoying View Post
    Can NOT on my old 700M, and DAMN I wish I could
    TY just saved me half an hour.

    Regarding subs: they are great. But on our machine it is an option company didnt pay for. So i have to F*k around with goto if have to.

    btw you can still do this

    CC=9005 (where we return)
    GOTO N9999 (our sub call thing)
    N9005 (this should be the same as CC value so we go back to NEXT line)

    .....
    .....
    .....
    N9999(sub)
    .....
    .....
    (and this is how we return)
    IF [CC EQ 9000] N9000
    IF [CC EQ 9001] N9001
    IF [CC EQ 9002] N9002
    IF [CC EQ 9003] N9003
    IF [CC EQ 9004] N9004
    IF [CC EQ 9005] N9005

    and so on
    i honestly would try to never use that for the shear fear of screwing up with numbers somewhere and jumping to the wrong line. But you never know. people in need may be quite crafty and desperate

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
  •