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? 0
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]];
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.0 -
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?0 -
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?0
-
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.0 -
I am checking the values on the real teach pendant under program data
0 -
graemepaulin said: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.
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?0 -
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.0 -
Great to hear.
That is what I was asking in my first reply....1 -
graemepaulin said:Great to hear.
That is what I was asking in my first reply....0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 798 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings