How do I get a time Instant in a non-threaded script

Typically: "How do I... ", "How can I... " questions
Post Reply
jvperoni
Posts: 1
Joined: 17 Oct 2019, 16:09

How do I get a time Instant in a non-threaded script

Post by jvperoni »

Hello. I am developing a conveyor simulation in which I have a start and end sensor. When the product passes the start sensor, I wanted to get the real time Instant, and then make the same thing in the end sensor and make end-start so I can get the time difference from start to end of the conveyor.

I tried this using sim.getSystemTime, using "a" as an auxiliary variable to make this work only 1 time, and then assign the value to another variable so I can work the math. Problem is the variable time keeps running even after the sensor = 0. Is there a function to get the time and "freeze" it so I can get the INSTANT, instead of the running time? Any help will be appreciated. Thanks.

tempo1= 0
a = 0
if (a ==0) then
if(sensorInicio == 1.0) then
tempo1 = sim.getSystemTime(0)
local tempoInicio = tempo1
a = 1
end
end

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: How do I get a time Instant in a non-threaded script

Post by coppelia »

Hello,

I do not understand your question. If your sensor A is triggering, simply assign the current time to a variable X. If your sensor B is triggering, then the duration between sensor A and B trigger is the current time minus the variable X.

Cheers

Post Reply