Home› Programming
Discussion
Back to discussions page
Jstewart
Posts: 62 Apprentice
Questions about URScript |
240 views
|
Answered | |
/ Most recent by matthewd92
in Programming
|
15 comments |

in Programming
Hello,
Attached is a URscript that was generated from the sim software. Im new to script programming and im trying to understand more on how to use this to get more out of my UR.
the questions i have are:
Off topic but has anyone used an automatic tool changer with a UR and can give me some in-site on how they did it as far as the programming goes?
Thanks in advanced
Attached is a URscript that was generated from the sim software. Im new to script programming and im trying to understand more on how to use this to get more out of my UR.
the questions i have are:
- The program created a variable called "step_count_7679db51_583c_48aa_afeb_a37e29d0d27f" and it is being used in the thread "Step_Counter_Thread_1f0542e5_48a9_4cd4_8e00_e9bb9f64c151". is this created to tell the thread to run only once?
- If i wanted to run this code on my UR, would i just call the "Step_Counter_Thread_1f0542e5_48a9_4cd4_8e00_e9bb9f64c151()"?
Off topic but has anyone used an automatic tool changer with a UR and can give me some in-site on how they did it as far as the programming goes?
Thanks in advanced
Best Answer
-
matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,266 Handy
The question I would ask is why a thread in the function? Do you need this to be processed in the background? If not, this is a quick function call and so could easily be inline. If you need to know always what tool is loaded, like if someone paused the robot and swapped tools then you need the thread to loop so that it is always running. The way it's written it's a single execution background function.
The function would simply be as below, notice I am using a return statement and not assigning the global variable directly.def toolStatus(): if (get_standard_digital_in(0)): return 1 elif (get_standard_digital_in(1)): return 2 end return 0 end
Use it like this:ToolAct=toolStatus()
Couple of things to point out, since this function is not dependent on global state its easily tested and secondly, get_digital_in was deprecated quite a while ago and replaced with more specific calls which you see represented in the code above. Since the function has been officially deprecated they will most likely remove it from the language in the future which would cause your code to break when the update comes out.
Since the status of the `get_standard_digital_in(n)` call is a boolean return value I do not need to compare it to True or False as it is True or False, I can simply state in my logic that it either is that value by stating it directly or I can negate it by saying something like thisif (!get_standard_digital_in(0)): #Read as "if not true" or in more common vernacular "if false"
From what I understand the thread inside the script is counting the number of time the thread have been executed.
The robot execute program command with a pace of 0.008s for eSerie and 0.1s for CB. As there is nothing else than a step counter in the thread is behave like a time counter.
If you use eSerie, Step_Counter_Thread_1f0542e5_48a9_4cd4_8e00_e9bb9f64c151*0.008 will give you program execution time.
The variable is not used outside of the thread. It looks like it is not used.
Side remark: it is good practice to add a sync() command at the end of a each thread to avoid having interference with program execution pace.
If you want to run the complete code you can save your script file on the robot via FTP for example or with USB stick. Create a program, import the script and call it with the script command:
I don't see so much things in this program. It is probably better to redo it on the teach pendent of the robot without using script.
Thread definition
at some time later or on some condition being met
Looking at the generated script file is a really good way to learn URScript as it will show you how UR is converting the GUI Polyscope commands into the actual script that is being executed by the robot
@matthewd92 so if I created a script file it would be placed say in the before program sequence? And then whenever I need that code I would do a script line command with the “run scriptcodefilename()” or would it just be “scriptcodefilename()”
The first part of the script are some variables and functions used by the system to run the program. It is automatically added to the script by URCAP or polyscope. You don't need to dive into it.
The second portion is the main program.
So in my project i have an auto tool changing system that gets connected to the DIO of the robot. DI(0) is tool 1 and DI(1) is tool 2 when the are connected to the robot. In my URScript i want to be able to output to variable "Tool_act" a 1 or 2 for whichever tool is currently on the robot. my script starts as follows:
would this be the correct way of doing this? also the "global" variables could be ones i have created on the TP correct?
I think you need some modifications:
You can then execute your code with the following script command:
toolStatus()
when i run the code however it is saying the no tool is currently active even though tool 1 is connected to my robot.
Wow that helps me out a ton. While reading the script manual i did notice that some functions were being updated with newer ones, but must have over looked that one.