Home Programming

Discussion

Left ArrowBack to discussions page
JstewartJstewart Posts: 54 Apprentice
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:

  1. 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?
  2. 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

Comments

  • bcastetsbcastets Vacuum Beta tester Posts: 292 Handy
    I am not sure about what you want to do with this script.

    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:
    unnamed()


    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.




  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,180 Handy
    That variable is an execution step counter that is being added by either UR behind the scenes or possibly a URCap if you have one installed.  What version of polyscope are you running?  Since this is defined as a thread you have to use the run command to cause it to start, you can see that in the code below

    Thread definition
    thread Step_Counter_Thread_1f0542e5_48a9_4cd4_8e00_e9bb9f64c151():
      while (True):
        step_count_7679db51_583c_48aa_afeb_a37e29d0d27f = step_count_7679db51_583c_48aa_afeb_a37e29d0d27f + 1
        sync()
      end
    end
    Thread Execution
    run Step_Counter_Thread_1f0542e5_48a9_4cd4_8e00_e9bb9f64c151()
    When you run a thread you can also assign it to a variable such as this allowing you to kill the thread by using the id that is returned from the run command
    local stepId = run Step_Counter_Thread_1f0542e5_48a9_4cd4_8e00_e9bb9f64c151()
    at some time later or on some condition being met
    kill threadId
    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


  • JstewartJstewart Posts: 54 Apprentice
    Thanks for the reply’s!

    @bcastets I don’t want to do anything with that particular script. I am trying to learn script programming and when I created a program on the TP that’s the script file that was generated. So would the sync() be used at the end of thread like shown in script?

    @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()”
  • matthewd92matthewd92 Founding Pro, Tactile Sensor Beta Testers Posts: 1,180 Handy
    edited January 12
    If it a thread you use run command. Otherwise just call the function direct. 

    Threads are background functions. They do not block your code that’s controlling your robot. A good built-in example is the timer function. When you start a timer it starts a thread and when you stop it the thread is killed which stops the timer running. 
  • bcastetsbcastets Vacuum Beta tester Posts: 292 Handy
    As Matthew said this thread is automatically generated by URCAP or UR system. I did not know about it. It is not so important. The most important is the portion which concern your program.


    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.
  • JstewartJstewart Posts: 54 Apprentice
    Thanks for all the help guys, definitely helped me out! 
Sign In or Register to comment.
Left ArrowBack to discussions page