501,541 active members
5,127 visitors online
Register for free
Login
Page 1 of 2 12
Results 1 to 12 of 19
  1. #1
    Registered
    Join Date
    Jun 2014
    Posts
    75

    Question Passing arguments through layered macros

    Exploring the NCT Faunc based controller we have now and im trying to get my head around macros. I understand how they work and how to pass an argument though. However while it is probably not something I will use (ever if not often), im interested to know.

    When calling a macro from the main program, we use G65 <insert subprogram> and pass arguments through with a letter to correspond to a local variable. You can then call a macro from within the first macro using the same procedure - and so on and so on, layering macro within macro (does anyone do this).
    My question is how do you pass an argument from the main program to each layer of macro? Or can it only be done from the layer above calling the macro?

    Quick example.
    MAIN PROG
    G0 X0 Y0 Z0
    G1 X100 Y100 Z0
    G65 <MACRO1> A20 <----A20 MAKES LOCAL VARIABLE #1=20
    G0 X0 Y0
    M2

    MACRO1 PROG
    G1 Z#1
    G1 Z0
    G65 <MACRO2> B? <---- HOW CAN I CALL B FROM MAIN PROGRAM
    M99

    MACRO2 PROG
    G1 Z#2
    G1 Z0
    G65 <MACRO3> C? <---- HOW CAN I CALL C FROM MAIN PROGRAM
    M99

    MACRO3 PROG
    G1 Z#3
    G1 Z0
    M99


    One idea i had, though its not really calling the variable and rather passing the argument which sorta defeats the purpose is:

    MAIN PROG
    #100=40
    #101=60
    G0 X0 Y0 Z0
    G1 X100 Y100 Z0
    G65 <MACRO1> A20 <----A20 MAKES LOCAL VARIABLE #1=20
    G0 X0 Y0
    M2

    MACRO1 PROG
    G1 Z#1
    G1 Z0
    G65 <MACRO2> B#100
    M99

    MACRO2 PROG
    G1 Z#2
    G1 Z0
    G65 <MACRO3> C#101
    M99

    MACRO3 PROG
    G1 Z#3
    G1 Z0
    M99


    in which case you may aswell not pass the argument and rather just use global variables.

    Any thoughts or ideas? or can it simply not be done?

    Thankyou

  2. #2
    Member
    Join Date
    Jun 2015
    Posts
    2710

    Re: Passing arguments through layered macros

    hello zelodia i don't know exactly how things are for your machine, i don't have great experience with fanuc, but i can share a few things, hoping to help you

    fastest performing codes are those with linear arhitecture, thus no conditions, no formulas, only coordinates + GM codes; a linear arhitecture requires less processing time from the controller

    codes with non-linear arhitecture perform a bit slower, and require more processing time from the controller; depending on controller, there may be some functions available to speed up the processing time, so to have a non-linear code that perform almost as fast as a linear code

    a code with soubroutines is a non-linear code, and each soubroutine represents a nesting level; in other words, each individual soubroutine is a linear code only at a specific nesting level

    passing arguments to a soubroutine can be done using common and/or local variables; there may be also system variables, system local variables, reserved locals, extended adress chars, custom arrays, bytes arrays, file read/write, but this is less common ...

    generally speaking, common variables have global behaviour, while local variables have only local behaviour :
    .., a global variable can be used regardless of nesting level
    ... a local variable may be used :
    ...... only inside current nesting level
    ...... only inside current nesting level + deeper nesting levels, thus it may act as a "global" variable, starting from the nesting level where it was created; for example, if you use a program that calls soubroutine 1, and inside soubroutine 1 you create a local variable and also call another soubroutine, then that local variable may be available also inside the 2nd soubroutine, because it was created at a superior nesting level

    such behaviours are very control specific, so you have to be sure about how your controller handles such situations

    some controllers use more then a single set of local variables :
    ... set 1 ( eq #100-#200 ) may be volatile, thus it's content is no longer available after cnc reset and/or cnc power cycle ( on / off )
    ... set 2 ( eq #500-#600 ) may not be volatile, thus it's content is recorded, so not to lose it in case of reset and/or power cycle
    ... set 3 may be a limited set, designed for passing parameters to a soubroutine ( A #1 , B # 2, etc )

    machines with dual spindles, may have each set specific to each spindle, for example, there may be set 1 for spindle 1, and another set 1 for spindle 2, thus, you may use #100 inside code for spindle 1, and another #100 inside code for spindle 2

    some controllers use a 'nil / empty' state, so to show that a variable had not been initialized yet

    it may be possible to check if a local variable had been initialized or not, allowing one to create soubroutines with overload content; this is a high-specific technique


    it may seem a bit confusing, i don't know, i tried to explain it as simple as possible, but, once you master them, you may be able to create stable&versatile parametric soubroutines, that will help you deliver better codes / kindly
    Ladyhawke - My Delirium, https://www.youtube.com/watch?v=X_bFO1SNRZg

  3. #3
    Registered
    Join Date
    Aug 2004
    Posts
    696

    Re: Passing arguments through layered macros

    I think the best and easiest way is by writing the vars to a file.
    Adding some datestamp and sanity checking, and one has a very robust system.

    Endless details abound like checking for the name/existence of the file, ability to create it, etc.

  4. #4
    Member
    Join Date
    Jun 2015
    Posts
    2710

    Re: Passing arguments through layered macros

    I think the best and easiest way is by writing the vars to a file.
    hello hanermo, the cnc operates at the flash memory level; when you use a print/read function, you target a device <> flash, and downtime will appear / kindly
    Ladyhawke - My Delirium, https://www.youtube.com/watch?v=X_bFO1SNRZg

  5. #5
    Registered
    Join Date
    Aug 2004
    Posts
    696

    Re: Passing arguments through layered macros

    Maybe some cnc do.
    Haas does not.
    I think almost all cnc do not.

    Any programmer can code the vars to load on macro startup, and to update as needed to file.
    It is silly to use direct variables from a file vs a trivial programming effort.


    Quote Originally Posted by deadlykitten View Post
    hello hanermo, the cnc operates at the flash memory level; when you use a print/read function, you target a device <> flash, and downtime will appear / kindly

  6. #6
    Member
    Join Date
    Jun 2015
    Posts
    2710

    Re: Passing arguments through layered macros

    hi hanermo, some downtimes are small, hard to percept ... this makes it hard to guess that something happens; if the frequency is increased, then the downtime may start to be perceptable

    to quantify this behaviour, then is needed to record the duration of the process, and this requires an implemented stop watch inside the controller; the higher the resolution, the better

    and to update as needed to file
    if initializations are done inside the program, then is no more needed to write the values to a file; of course, there are values ( log data ) that can not be initializated inside the program, and in this case it may be ok to store them inside a file / kindly
    Ladyhawke - My Delirium, https://www.youtube.com/watch?v=X_bFO1SNRZg

  7. #7
    Member
    Join Date
    Jun 2015
    Posts
    2710

    Re: Passing arguments through layered macros

    hello again zedodia, i have been thinking : in your post, you have a code with 3 ( or 4 ) nesting levels ( 0 main 1 macro1 2 macro2 3 macro3 ), and you wish to send, from the main nesting level, a variable to every other nesting levels

    if i may, what do you wish to achieve ?

    passing variables through nesting levels is commonly used in next situations; target soubroutine is :
    ... designed for cutting, and operations is :
    ...... simple, so is more convinient to initialize the variables inside the main program
    ...... complex, thus there are many parameters involved, but some of them may be initialized inside the main program
    ... not designed for cuting, thus it is a general resource


    i asked about your purpose. because you may need a pre-setting program; such programs store all those variables that are needed, but with different values, so to help toogling between iterations pretty fast, only by 2-3 keystrokes ( program select + run ), and not by direct program editing / kindly
    Ladyhawke - My Delirium, https://www.youtube.com/watch?v=X_bFO1SNRZg

  8. #8
    Registered
    Join Date
    Jun 2014
    Posts
    75

    Re: Passing arguments through layered macros

    Thanks Deadlykitten for the long winded answer. I am very aware how to code and how linear progs are more processing power efficient than parametric etc, and how variables are used .. I am merely asking if anyone know how to pass arguments thought multiple layers or if anyone does it. As stated it is not something i would ever use (i think), and just interested to know how it can be done.
    The prog supplied was purely for an example cause im not going to post a massive code that will take ages to read.
    Essentially if a have a program that cuts a square, and a macro to cut a smaller square within, at first layer of macro called i know i can pass arguments to define (what ever i want) the size of the sqaure and the position for example. however if i was to call a macro from within the macro to make another smaller sqaure, how do i pass the argument to the second layer to define its size and location (using the same example). What im getting at is the idea of using macros is so you dont have to alter the macro program from itself and rather give it arguments to define its 'what ever'. However once you get to a second level, i see no way to define the arguments unless it comes directly from the 1st layer macro. The machine i have says it can go upto 16 levels of macro/subroutines. While this is good its has capability, is it really of any use?

    Hanermo - I think the best and easiest way is by writing the vars to a file.
    Adding some datestamp and sanity checking, and one has a very robust system.

    Endless details abound like checking for the name/existence of the file, ability to create it, etc.

    can you elaborate on this at all? do you mean a file with all the variables (#1-#999 or what ever you use) defined, which loads the memory with this info, then run the programs?
    how do you add date stamps and 'sanity checking'?
    not really sure what your getting at here.

    thankyou both

  9. #9
    Member
    Join Date
    Jun 2015
    Posts
    2710

    Re: Passing arguments through layered macros

    hello zedodia

    linear progs are more processing power efficient than parametric
    depending on controller, there may exist the possibility to remove or reduce drastically this gap, thus allowing to keep the versatility of a parametric program, without infusing downtime

    The prog supplied was purely for an example
    somehow i was not sure about your intention, and i can't give a good advice without knowing the purpose ... i mean if i think of too many ways, i can't decide which one is better hoping that there is a 'better' way

    Essentially if a have a program that cuts a square, and a macro to cut a smaller square within
    for such a part, you don't need to go over nesting level 1; program would be like this :

    Code:
        [ main program ]
        preparatory codes ( tool-change offset fixture rpm etc )
        call square_soubroutine var_1 = a1 var_2 = a2 ... var_n = an
        call square_soubroutine var_1 = b1 var_2 = b2 ... var_n = bn
        call square_soubroutine var_1 = c1 var_2 = c2 ... var_n = cn
        end
    
        [ square_soubroutine ]
        content optimized for cutting a square, using var_1, var_2 ... var_n
        end
    i can try to suggest ideas, but i can't share a real solution, unless i see a real reason to pass through multi nesting levels

    ok ... now, i will share an example about a code that i use, where variables are passed through levels :

    Code:
        [ main program ]
        preparatory codes ( home position, fixture )
        call operation_1 var = 04
        call operation_2 var = 53
        call operation_3 var = 17
        end
    
        [ operation_1 ]
        call verify_offset
        call prepare_tool
        content for operation 1
        end
    
        [ operation_2 ]
        call verify_offset
        call prepare_tool
        content for operation 2
        end
    
        [ operation_3 ]
        call verify_offset
        call prepare_tool
        content for operation 3
        end
    
        [ verify_offset ]
        checking if offset for tool [ var ] is within some safe limits, otherwise stop the cnc
        end
    
        [ prepare_tool ]
        go to safe position, and index to tool [ var ]
        end
    i hope that this example helps; there are also other cases when i go 'through nesting levels'

    However once you get to a second level, i see no way to define the arguments unless it comes directly from the 1st layer macro
    yes, this is true, but, more precise, the argument must "allready exist at 1st layer" ; this means :
    ... argument was created inside 1st layer ( pls check sample 1 )
    ... argument was created before 1st layer ( pls check sample 2 )
    * another option, is that the argument is created when the 2nd soubroutine is called ( pls check sample 3 )

    Code:
    
    ( sample 1 )
    
        [ main program ]
        call soubroutine_1
        end
    
        [ soubroutine_1 ]
        variable = 500
        call soubroutine_2
        end
    
        [ soubroutine_2 ]
        do something with 'variable'
        end
    
    ( sample 2 )
    
        [ main program ]
        variable = 500
        call soubroutine_1
        end
    
        [ soubroutine_1 ]
        call soubroutine_2
        end
    
        [ soubroutine_2 ]
        do something with 'variable'
        end
    
    ( sample 3 )
    
        [ main program ]
        call soubroutine_1
        end
    
        [ soubroutine_1 ]
        call soubroutine_2 variable = 500
        end
    
        [ soubroutine_2 ]
        do something with 'variable'
        end
    The machine i have says it can go upto 16 levels of macro/subroutines. While this is good its has capability, is it really of any use?
    this depends how you see things, and how far you wish to go, and how much time you have to experiment

    not everybody is using soubroutines, but those ones that do it right, have more skills and more control over the machine, and their programs perform better

    so far i have reached nesting level 6 or 7, but most operations are executed inside nesting level 2 or 3 i use deeper nesting levels for general soubroutines, that target optimizations that are not related to cutting; for example : checking axis positions, computing home positions, checking machine states, checking offsets, etc .... well, i have a few / kindly
    Ladyhawke - My Delirium, https://www.youtube.com/watch?v=X_bFO1SNRZg

  10. #10
    Registered
    Join Date
    Jun 2014
    Posts
    75

    Re: Passing arguments through layered macros

    Thanks Deadlykitten. Im not really doing anything with them 'yet'. im just exploring the possibilities of them atm to see whether they will be useful for my job. Essentially I have to rewrite all of my programs for work (3-4years worth) because we have moved from an old 98' model masterwood 327 to a retrofitted 98' model masterwood 327 (lol). The controller is an NCT 204 (which i cannot find any info on cnczone. Seems to not be a popular thing. Already i am finding so many things i need to incorporate moving from the old MW327 language to Fanuc - which is a headache at best atm. code structure is different and not as 'easy' to use. Something as simple as having to add G39 after every linear move to make the cutter run smoothly around the workpiece is a pain. We work with timber so having a micro pause usually mean a burn mark.
    Tool offsets are different (code structure and sequence) and i cannot simply run a while/end sequence altering the offset diameter as easily - I used to be able to use a 'Q' value after G41/42 to offset the diameter, now i have to use G10 and alter the table then alter it back after a loop in finished. All in all my codes are almost doubled in length to do the same task. Calling subroutines or macros will be very useful to me once i get my head around the best way to approach them (I always attempt to make all my programs parametric rather than static). Thats why I am asking this question.

    Is that an exact code you run? or just an example. the 'call' function and 'var' looks more like a computer language rather than Gcode to me.

  11. #11
    Member
    Join Date
    Jun 2015
    Posts
    2710

    Re: Passing arguments through layered macros

    hello, about your question on passing values, simply declare all variables at the begining of the program, and after that use them how you wish, inside the main program or inside a soubroutine; something like this :

    Code:
        [ main program ]
        #101 = 1 ( comment 1 )
        #102 = 2 ( comment 2 )
        #103 = 3 ( comment 3 )
        main program content, maybe some operations with #101 and #102
        call soubroutine_a
        end
    
        [ soubroutine_a ]
        soubroutine content, maybe some operations with #102 and #103
        end
    your code sample has many variables, but is also simple, so i would recomand you to keep the variables at the begining of the program

    if somehow you wish to use same soubrtouine twice inside same program, then try this :

    Code:
        [ main program ]
        call initialization_1
        call soubroutine
        call initialization_2
        call soubroutine
        end
    
        [ initialization_1 ]
        #101 = 1 ( comment 1 )
        #102 = 2 ( comment 2 )
        #103 = 3 ( comment 3 )
        end
    
        [ initialization_2 ]
        #101 = 11 ( comment 1 )
        #102 = 22 ( comment 2 )
        #103 = 33 ( comment 3 )
        end
    
        [ soubroutine ]
        do something here with #101 #102 #103
        end
    we have moved from an old 98' model masterwood 327 to a retrofitted 98' model masterwood 327 (lol)
    is this an antivirus ?

    We work with timber
    i have no clue what timber is ...

    codes are almost doubled in length to do the same task
    this means more programing time, if codes are long-handed ... is there also a benefit with that retrofit ? does the machine moves faster now, or is there an advantage, so to justify the retrofit ?

    Calling subroutines or macros will be very useful
    well, build your soubroutines, or at least update those ones from before the retrofit ... if i may, what soubroutines do you wish do use ? i am asking this, because, in the near future, i may be able to help you deliver them faster

    Is that an exact code you run? or just an example. the 'call' function and 'var' looks more like a computer language rather than Gcode to me
    is only an example; some of my codes are filled with stuff but i use 'call' to execute a soubroutine, i may also use 'var', and i can use soubroutine names up to 16 chars / kindly
    Ladyhawke - My Delirium, https://www.youtube.com/watch?v=X_bFO1SNRZg

  12. #12
    Registered
    Join Date
    Jun 2014
    Posts
    75

    Re: Passing arguments through layered macros

    is this an antivirus ?
    I would say more so a virus lol

    i have no clue what timber is ...
    timber....? timber = wood (material)

    this means more programing time, if codes are long-handed ... is there also a benefit with that retrofit ? does the machine moves faster now, or is there an advantage, so to justify the retrofit ?
    Oh how i'd love someone else to address these questions with the employer lol. So far the only benefit is the machine actual moves. The old one died. You'd sorta have to work here to understand.

    well, build your soubroutines, or at least update those ones from before the retrofit ... if i may, what soubroutines do you wish do use ? i am asking this, because, in the near future, i may be able to help you deliver them faster
    Previous machine did no have macros or ability to use them. It was very simple - but effective.


    Thanks again. I will explore subroutines more soon and see what else i can learn.

Page 1 of 2 12

Similar Threads

  1. Passing parameter as arguments in G65
    By biqut2 in forum G-Code Programing
    Replies: 0
    Last Post: 07-31-2015, 04:31 PM
  2. Passing parameter as arguments in G65
    By biqut2 in forum General CNC (Mill / Lathe) Control Software (NC)
    Replies: 0
    Last Post: 07-31-2015, 04:18 PM
  3. Plasma- Multiple layered AL thin sheet cutting?
    By diyengineer in forum General Waterjet
    Replies: 2
    Last Post: 08-22-2011, 12:06 AM
  4. Foil layered foam
    By webdude12 in forum Composites, Exotic Metals etc
    Replies: 0
    Last Post: 10-23-2009, 08:15 PM
  5. passing arguments to a sub program
    By kiprip in forum Mazak, Mitsubishi, Mazatrol
    Replies: 1
    Last Post: 07-13-2006, 05:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •