RobotStudio event

CONST variables in multiple tasks

Hello,

I have two tasks. Each uses a constant value initialized in task1:

    CONST num sizebuffer := 1000;

I need to use this constant value in task2. Problem is, I have to declare sizebuffer in task 2 in order to compile. But the compiler refuse just to initialize the variable  without value

    CONST num sizebuffer;
    Syntax error(135): Expected ':='

If I initialize the sizebuffer in task2

    CONST num sizebuffer := 1000;
The program compile. But the value can be different if it is initialized differently in the two tasks! How is it possible to fix that?

Thank you for youtr help,

Comments

  • Micky
    Micky ✭✭✭

    Hi,

    constant declarations can only be used in the task in which they are defined, other tasks have no access.

    If you want use the data which are defined in another task, you have to declare them as persistent instead of constant.

    In the task T_ROB1 you have to define:

         PERS num nSizeBuffer:=1000;

     

    And in your task2:

        PERS num nSizeBuffer;

    In this case only the value of the task T_ROB1 will be used to initialize the persistent.

     

    /BR

    Micky

     

     

  • Hello,

    Thank you for your answer. I forgot to mention, the variavle sizebuffer is used to specify the size of an array of jointtarget.

        CONST num sizebuffer := 1000; ! Size of the cyclic buffer
        PERS jointtarget cyclicbuffer{sizebuffer};

    RAPID programming does not allow to use non-constant variables to specify the size of an array; using PERS num nSizeBuffer:=1000 thus generate an error. How can I specify the size of an array so that the variable containing the size of the array is only initialized once for multiple tasks^

    Thank you
  • Micky
    Micky ✭✭✭

    Hello,

    maybe you can define this constant declaration in a separate module and load it shared via "automatic loading of modules" (sys.cfg) into your memory.

    If a module is loaded as shared, all data declarations are available in all tasks.

     

    Best regards

    Micky

     

  • I know this is an old Post but did you ever figure a way to do this? I am trying to do the same thing....