Home› Programming
Discussion
Back to discussions page
Lavertue
Wrist Camera URCap 1.3.0 Posts: 9 Apprentice
Create global boolean variables. |
1.1K views
|
Answered | |
/ Most recent by matthewd92
in Programming
|
15 comments |

in Programming
Hi,
I am aware that I can create a ''global'' variable by the creating an installation variable, but it seems that I can only create an integers variable. Is there a way to create a boolean global variable (or string for that matter)? My problem is that I use boolean variables defined in the main program in the subprograms and at the start I always get an error message telling me: variables XXX is already created, do you want to automatically rename it?
thanks
I am aware that I can create a ''global'' variable by the creating an installation variable, but it seems that I can only create an integers variable. Is there a way to create a boolean global variable (or string for that matter)? My problem is that I use boolean variables defined in the main program in the subprograms and at the start I always get an error message telling me: variables XXX is already created, do you want to automatically rename it?
thanks
Best Answers
-
matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,267 Handy
-
louis_bergeron Posts: 94 Handy
@Lavertue
You can declare global bool variable in script code like this: Program<span style="background-color: transparent; color: inherit; font-size: inherit; font-family: Hind, sans-serif;"> <br> BeforeStart </span><div> global myvar= True <span style="background-color: transparent; color: inherit; font-size: inherit;"><font face="Hind, sans-serif"> Robot Program</font> </span><span style="background-color: transparent; color: inherit; font-size: inherit; font-family: Hind, sans-serif;"> myvar= True </span><span style="background-color: transparent; color: inherit; font-size: inherit;"><font face="Hind, sans-serif"> </font></span></div><div> Call SubProgram_1 </div><div> myvar= False </div><div> Call SubProgram_1 </div><div> SubProgram_1 </div><div> If myvar≟ True </div><div> Popup </div><div> Else </div><div> Popup<br></div>
You will have to use script code to assign the value True or False.
that is what I understood at first, thank you for confirming. I'll make sure to use integers next time I have to use variables in multiple sub programs!
Integration Coach
robotiq.com
[email protected]
TRUE:=1
FALSE:0
then I have assignements doing:
myvar:=TRUE
myvar2:=FALSE
This way I could use integers, but see a "boolean logic" in my programming?
Within the installation variables screen. Take care of uppercase and lowercase when you type 'True'.
Integration Coach
robotiq.com
[email protected]
I don't know since when it's available. I just tried it on one robot and it works. I was also surprised.
Integration Coach
robotiq.com
[email protected]
I have tried this method and I get good results when I am creating a new program or when using the UR simulator, but when I try to add it to an existing program I still get the same mistake (see picture below). This happen when I load the program, it does not stop it from working, but I have to hit cancel about 20 times in this particular program. On the end-user side it is not the most optimal thing.
My understanding of the UR was that it writes its variables when he sees them, so a script defining global variables should not cause ths error... Any idea what could cause this?
Note: the UR simulator on my computer never produce this message.
My original expectation for using the same name in the sub-program is so the value for the variable in the main program and sub-program is passed back and forth. So, for example, the main program has a variable "gadget_detected" that is solved for in one of eight sub-programs that run based on which gadget type is selected. (The sub-programs have the Camera Locate nodes in them which have to be different for each gadget type)
For example, I had "var_1" used throughout the program and sub-program, so I made and installation variable "var_1". I allowed PolyScope to convert the program variable to an installation variable. I then decided to get rid of some of the programming from a sub-program and merged it into the main program in a folder to keep it organized. When trying to run the program the incomplete message popped up. All of the parts of the program that referenced "var_1" had yellow nodes, even though Polyscope showed "var_1", appearing to be normal. To fix it, I had to delete, then re-enter "var_1" in all those places.
You would need to close the program program before deleting it then it should work when you open the program back up. You removed the instantiation of the variable from the program when you deleted the installation variable.