RobotStudio event

Retain values of a PERS num variable

I have defined a global persistant numeric 6x6 array.

MODULE MainModule

    ! Shared Global Persistant variables with tasks
    PERS num bZ{6,6};

When a specific procedure is executed, values are written into the bZ array. These values are later used by other procedures. However, when the PP is set to main, the values become zero. How to retain the values of the bZ variable?  
Tagged:

Comments

  • Did you create the variable in RobotStudio?
    If you use the real or virtual FlexPendant to create the variable it will also create "0" filled assignments which takes the effort of doing this yourself.
    PERS num bZ{6,6}:=[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]];

  • This is not the problem. The variable bZ is being overwritten to 0 when PP is moved to main. I want the bZ to retain the values. I agree that bZ will be initialized to 0 when created. After a specific procedure is run (say PROC1), new values are written into bZ array. When I want to run another procedure PROC2, PROC3, .. etc, I am observing that bZ is being overwritten to 0 instead if retaining values after PROC1. 

    I have to use PP to main since the structure of main is as follows:

    PROC main()
            PROC1;
            !PROC2;
    ENDPROC

    After PROC1 is run and bZ is updated, I comment PROC1 and uncomment PROC2 to run PROC2.
  • How are you checking the values in the array after running PROC1, and then after PP to main?
    Is there an initialisation any where that may be writing 0 back into the values?
  • rakshithb174
    edited August 2020
    I am checking the values on the real teach pendant under program data. There is no initialization between procedure calls. Does PP to main cause any initialization? 
  • From the RAPID kernel manual:
    A persistent (data object) can be described as a "persistent" variable. While a variable value is lost (re-initialized) at the beginning of each new session - at module load (module variable) or routine call (routine variable) - a persistent keeps its value between sessions. This is accomplished by letting an update of the value of a persistent automatically lead to an update of the initialization value of the persistent declaration. When a module (or task) is saved, the initialization value of any persistent declaration reflects the current value of the persistent.
    So it could be the value has not been updated yet in the program data but the changed value should be retained.
    Try displaying the current value with a TPWrite instruction.
  • I am checking the values on the real teach pendant under program data
  • From the RAPID kernel manual:
    A persistent (data object) can be described as a "persistent" variable. While a variable value is lost (re-initialized) at the beginning of each new session - at module load (module variable) or routine call (routine variable) - a persistent keeps its value between sessions. This is accomplished by letting an update of the value of a persistent automatically lead to an update of the initialization value of the persistent declaration. When a module (or task) is saved, the initialization value of any persistent declaration reflects the current value of the persistent.
    So it could be the value has not been updated yet in the program data but the changed value should be retained.
    Try displaying the current value with a TPWrite instruction.
    When I use TPWrite to display the data in the array, I get 0 for all elements. It looks like value of the all of the elements is getting overwritten to 0. I want the values written to bZ after executing PROC1 to be retained. 

    If a variable is defined as type PERS but not assigned any value in declaration, does the value of the variable revert to 0 after a PP to main? 
  • Ok, I solved this. I found an old post which helped me: https://forums.robotstudio.com/discussion/3178/var-pers-and-const

    If a PERS variable is declared WITHOUT any initial value E.g. PERS num bZ{6,6}, the variable gets overwritten to 0 after PP to main and controller restart!! In this case any PERS variable will be treated as VAR and no information will be retained.

    The solution would be to provide an initial value during variable declaration: PERS num bZ{6,6}:=[[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]];

    This is trivial but easily overlooked. 
  • Great to hear.
    That is what I was asking in my first reply....
  • Great to hear.
    That is what I was asking in my first reply....
    Ah! I misunderstood this. Thanks for the help