Universal Robots Forum

Get current time from system

How do I know the time of the system to calculate the duration of a movement? getting the time before the movement and the time at the end of the movement would make the difference of these two variables and know the duration. CB3 to polyscope/program/expression/var (urp / txt) or script.

Thank you in advance.

this has already been asked and has good answers. Can be found by using the search term “time”: Get current time

1 Like

I saw it and I was expecting a more simple function but I try it and it works well anyway, Thank you for your quick answer I win some precious time.

Time as such known from e.g. Java is not implemented in URScript.
So the sync() timer option in a thread, may be the prefereable option in URScript.
If done in Python, Java or similar, there are many native options to extract timestamps.

Dear jbm, do you have an exemple of using sync() in UR Script?

sync() uses the remaining time in an 8 ms frame.
If called sequentially, each call will have a duration of 8 ms.
E.g.:

count = 0
while (count < 125):
   sync()
   count = count + 1
end
seconds = seconds + 1
1 Like

Thanks you, it’s what I needed it

Finally i did it like this. Sometimes I have an error of 8ms but it’s insignificant for what I am doing.

contador_de_tiempo_pantallazo