Calling subroutines/functions by string variable

  • I believe this has been asked before, but I don't recall ever seeing a positive reply. I'm wondering if KSS 8.x may have added such a feature.


    Basically, I have a need to be able to call a Globally-Defined subroutine or function without hard-coding it's name into the calling routine. For reasons that don't bear going into, I need to have a top-level module that calls various other modules, depending on whether those optional modules are installed. The painful part is, this top-level routine needs to be identical across multiple robots, but these robots will have different options installed (or not). So right now, I don't see how to avoid creating Linking errors unless I put empty "placeholder" modules into every robot to cover every optional installation, or have all the optional modules installed on every robot. The latter is rather wasteful of memory and could create a real pain over multiple generations of this software architecture.


    I'm not talking about using $CMD from the SPS to fired "SELECT" commands to the Level 1 interpreter -- I'm talking about something effectively like this:

    Code
    DECL CHAR _SubName[24]
    _SubName[] = "Subroutine1 (55,77.7)"
    Execute (_SubName[])


    Oh, yeah, did I mention I need to be able to pass arguments, too? :uglyhammer2:


    I suspect I'm going to be stuck using one of the less-palatable options, but I figured I'd give the Hive Mind a shot before I waved the white flag. :grinning-smiley:

  • ABB has this functions in it's code. They have a function called "CallByVar" or you can do it directly like this %procname% arguments;
    I did discuss this with Kuka a while back when they came out with KR.C4 and the reply I got was that KRL does not support late linking.


    This is a feature we'd like to have as well so a proper way of doing it would have been great as it opens up for a lot more dynamic code.


    To get around it we created a switch wich compares a string to a list of known features then we call the appropriate method for that feature. Parameters is also passed along as a string, which is then decoded inside the method for the feature. All data coming in (method name and arguments) are sent via the network into the robot.

  • mmm, I would like to call a subrutine like this.


    in REIS language, you can assign a string to a variable then use command " call" to call the variable. about kuka I have no idea about this.


    I am not sure whether it is a good method to programming , but it's too flexible.

    KUKA Conntroller : _________<br />KSS Software : ____________ <br />Robot Model: _____________

  • create bunch of subprograms


    then create expert module called CALL_SUB:


    DEFDAT Call_Sub PUBLIC

    GLOBAL ENUM SUBS_T Open_gripper, close_gripper, go_home

    ENDDAT


    DEF Call_Sub(_sub:in)

    DECL SUBS_T Subprogram

    SWITCH _sub

    Case #go_home

    Go_Home()


    Case #open_gripper

    Open_Gripper()


    Case #Close_gripper

    Close_gripper()


    Default

    MsgQuit("Subprogram not handled")

    ENDSWITCH

    END




    Then in your programs do something like



    Call_Sub(#go_home)

    Call_Sub(#open_gripper)

    WAIT SEC 3

    Call_Sub(#close_gripper)

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

Advertising from our partners