Discussion

Left ArrowBack to discussions page
RamonSanchezRamonSanchez Posts: 14 Apprentice
Hello all,

I am trying to program a timer on a UR10. Since our cycle uses two robots, I would like to program the timer only in the second robot (close to the end of the cycle) to the same point one cycle later, as the program will be running in a continuous loop.
I have already set a cycle counter by using the following code:

In the BeforeStart, I have the following:
count=0
addcount:=False

In the robot program I've got:
addcount:=False
.

.

.
addcount:=True
Wait=0.01
addcount:=False
.
.

And then I created a thread with the following code:
If addcount:=True
  count:=count+1
Wait=0.01

For now it seems to be working correctly. Is there any way I could use something similar for a timer? Maybe instead of time:=time+1 it would be something like 0.01 or 0.008?

Thanks!

Best Answers

  • RamonSanchezRamonSanchez Posts: 14 Apprentice
    edited April 2018 Accepted Answer
    I was thinking something like this but I am not sure (I am unable to test it right now).

    BeforeStart
    timer:=0
    stoptimer==true

    RobotProgram
    .
    .
    timer:=0
    Wait=0.01
    stoptimer==false
    .
    .
    Thread2
    While stoptimer==false
      timer:=timer+.008
    sync()

Comments

  • RamonSanchezRamonSanchez Posts: 14 Apprentice
    Hello Matthew,
    Exactly. The idea is to only have a cycle timer on the second robot (current, previous, and average). It works perfectly now.
    Thank you for your help!
  • matthewd92matthewd92 Posts: 827Founding Pro, Tactile Sensor Beta Testers Handy
    You’re welcome
  • Brittaney541Brittaney541 Posts: 29 Apprentice
    edited May 23
    Hi there,
    I was needing some help with programming my timer. I have a sensor that tells the robot when to go to get the object and when the sensor is LOW then the robot waits. I want the timer to only record when the robot is moving basically timer running as long as the sensor is high. For the most part it is always high, but in case our coworkers take a break or fall behind I want to receive real time to base off of how productive the robot is and not based on the entire day.

    I was thinking about using an IF statement
    If Sensor=lo 
         Stop timer
    Else Sensor HI
         Start timer
    I obviously start the timer when I start the program. I just don't want the "start timer" in the else to restart the timer. 
  • matthewd92matthewd92 Posts: 827Founding Pro, Tactile Sensor Beta Testers Handy
    Why not just have a thread in the background like this:

    global time = 0
    thread collectUseTime():
      if (get_standard_digital_in(port)): #Where port is the DI port your sensor is connected to, if not DI then you can use the command for CI get_configurable_digital_in(port)
    time = time + get_steptime() (function returns the time of the controller 0.008 for CB3 and 0.002 for E-Series) end sync() (consumes either 0.002 or 0.008 seconds depending on robot model) end
    Write that as script code and place in your before start section, then add a line to the before start section that says

    run collectUsetime()
    Then as soon as the input goes high you would collect time when the input goes low time collection would stop.

    You could also add that same code to a thread in Polyscope, obviously you would just use the Input name in the if condition.
  • Brittaney541Brittaney541 Posts: 29 Apprentice
    Is there an easy way to figure out what port it is? or would it be like DI7== so it would be port 7? 
  • matthewd92matthewd92 Posts: 827Founding Pro, Tactile Sensor Beta Testers Handy
    That is correct, the number in the DI or CI is the port.
  • Brittaney541Brittaney541 Posts: 29 Apprentice
    Ok so what I have is

    global time=0
    thread collectUseTime():
     if(get_standard_digital_in(7))
      time = time + get_steptime() 
     end
     sync()
    end


    It is having an error code that pops up referring to line 4
    should it say global time? Also please forgive me and all the simple questions I am still a newby.
    I couldn't fully understand the part in parenthesis about the function part. And I am working with an E-series 
  • matthewd92matthewd92 Posts: 827Founding Pro, Tactile Sensor Beta Testers Handy
    edited May 23
    Need a colon at the end of the if statement

    global time=0
    
    thread collectUseTime():
     if(get_standard_digital_in(7)):   <- That colon is very important, at the end of def, thread, if, while, elif, else, etc.
    
      time = time + get_steptime() 
    
     end
    
     sync()
    
    end

Sign In or Register to comment.
Left ArrowBack to discussions page