help with multiple routine

  • :help: hi i have the simple program like this


    ------------------------------------------------------------------------------------------------
    %%%
    VERSION:1
    LANGUAGE:ENGLISH
    %%%


    MODULE V1
    !
    CONST robtarget p1:=[[1000,1200,800],[0,0.92388,0.382683,0],[0,0,2,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
    CONST robtarget p2:=[[1000,1200,800],[0,0.92388,0.382683,0],[0,0,2,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
    CONST num P1:=180;
    CONST num P2:=180;


    PROC main()
    !
    IF p1=1 THEN
    routine_1;
    ENDIF
    !
    IF p1=2 THEN
    routine_2;
    ENDIF
    !
    IF p2=1 THEN
    routine_1;
    ENDIF
    !
    IF p2=2 THEN
    routine_2;
    ENDIF
    ENDPROC


    PROC routine_1()
    !program1
    ENDPROC



    PROC routine_2()
    !program2
    ENDPROC


    ------------------------------------------------------------------------------------------------


    the problem i have is i have 50 programs and robot has limited variable and file size!! so is there a way to load program only when using


    PROC main()
    !
    IF p1=1 THEN
    routine_ref_p1=routine_1.prg;
    ENDIF
    !
    IF p1=2 THEN
    routine_ref_p1=routine_2.prg;
    ENDIF
    !
    IF p2=1 THEN
    routine_ref_p2=routine_1.prg;
    ENDIF
    !
    IF p2=2 THEN
    routine_ref_p2=routine_2.prg;
    ENDIF
    !
    ENDPROC


    PROC routine_ref_p1()
    !program_reference_p1
    ENDPROC


    PROC routine_ref_p2()
    !program_reference_p2
    ENDPROC


  • p1 will never = 1, 2 or any number other than 180 because you have made it a constant. You should do something like p1:=giProgramNumber. Then CallByVar "routine", p1;


    Keep in mind that IF THEN's are very simple minded, the first condition that evaluates TRUE will be selected, even if you want some other condition to be TRUE and to do it first. With this in mind, you can use it to prioritize what should happen first when many conditions are true by placing the highest priorities first.

  • well thank for correct my basic program but my question is i have alot of routine inside 1 program file which cause the robot slow to load and limit variable. so my question is can i have a multiple program files instead of multiple routine?? thanks ( i dont know how slow that load instruction will be)
    also in my basic program I call different routine for different line (p1 and p2) (p1 can call both routine 1 and 2), (p2 can call both routine 1 and 2)
    i dont know if load instruction be the same. thanks

    Edited once, last by lunknowl ().

  • IF p1=1 THEN
    routine_ref_p1=:"program_1.mod";
    ENDIF


    Load stProgPath\File:=routine_ref_p1;
    %"rMyProgramMain"%;
    UnLoad stProgPath\File:=routine_ref_p1;




    This, while very simplified, explains the theory behind it. By making as late binding call to your modules "main" routine you won't get a reference error when the module isn't loaded.
    You'll keep the name of the main routine the same for all programs (i.e. modules) and only change the module name.



    The way I used it back in the day was a menu based system (see snippets below - it's not complete so it's pointless to try and load it to run it) which allowed the operator to enter a numeric number for which program they'd like to run and the robot(code) would handle loading/unloading of the programs. This number could be manually entered or fed by a PLC.


    Most of the strings are stored as constants so it's a bit tricky to follow the code, but hopefully it'll give you some pointers.


  • You can modify the install script to allocate more program memory, but if the programs are large(r) then I do still recommend loading/unloading the part specific module through rapid as the controller tend to get sluggish (from a user point of view) when you have a lot of stuff loaded.

  • DO YOU HAVE SIMPLE LOAD PROGRAM, I TRY THIS BUT DUPLICATE MAIN PROGRAM (S4C CONTROLLER)


    A0.PRG
    MAIN()
    LOAD\DYNAMIC:RAM1DISK"A1"
    UNLOAD


    A1.PRG
    MAIN()
    SETVALUEl:=1;


    I NEED MAIN PROGRAM SO I CAN SAVE THE FILE AND IT ACTUALLY LOAD INTO A1 BUT SHOW THAT DUPLICATE MAIN???? :help:

  • We use it like this:


    UnLoad diskhome \File:=currentfile;
    Load diskhome\File:="FSNA0126/Flash/rev_00_04/FSNA0126_Flash.MOD";
    currentfile:="FSNA0126/Flash/rev_00_04/FSNA0126_Flash.MOD";
    %"FSNA0126_Flash:Main"%;
    With the variable call enclosed within the percent signs, it allows for the late binding which masks the Main of your top level program.

Advertising from our partners