Welcome to Synthiam!

Program robots using technologies created from industry experts. EZ-Builder is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.
Get Started

Belgium
Asked
Edited

Comparing Times In Ezscipt

Im struggling with using time in ezscript.
I want to check how long it has been since a given face was recognized. But all the time functions seem to give strings and I cant really figure out how to convert those to number and compare. Using the script help I came up this this:

Quote:


$lastfacedetection= now()
....

if ( FmtTimeSpan(CDateTime(now()) - CDateTime($lastfacedetection) ), "mm") >5))
do something
endif



but that doesnt work, it tells me: Operator '-' invalid for strings.

Help?

AI Support Bot
AI Support Bot
Synthiam
Greetings! I'm the support robot! I've searched other questions, tutorials and controls related to your question. Take a look at these links. They're all sorted by what I believe is the most relevant:
Belgium
#23  
@DJ

Consider including PTPs plugin in ezb (if he allows it), I cant be the only one needing timers that are more accurate than counting out loud. And even if you dont need the sub second resolution, it is much more convenient to use to determine elapsed time compared to the existing date/time string conversions and custom functions- certainly if you dont need to compare it to the time of day or a date.

Secondly, I would still modify TotalSeconds. The problem is not datetime accuracy, its now() casting strings and the conversion to integer seconds. At the very least make TotalSeconds return an integer rather than float so people dont get confused as I did in to thinking it returns sub second results, when in reality it returns whole seconds plus a random decimal fraction.

Lastly, I mentioned the talk servo plugin. I stand by that, I would check its code, I really suspect there is a similar integer second time rounding issue lurking in there causing the lipsync to be delayed randomly by up to 1 second.
#24  

Quote:


Consider including PTPs plugin in ezb (if he allows it)

The code is open and the license is Beerware (https://en.wikipedia.org/wiki/Beerware)

No rocket science code:)

@DJ:
Plugin functions are only available for the desktop, adding them to the EZBuilder core will be useful to mobile applications.
#25  
I added 2 new functions: DateTimeTicks(), DateTimeTicksToMilliseconds()

The difference is more significant for short/frequent periods.

the difference was more significant a few years ago, although the differences are relative e.g. hardware, operating system, application code optimization.

Code:


$acc_delta_ticks=0
$acc_delta_dt_ticks=0

REPEAT ($ix, 1, 100, 1 )
$start_ticks=Ticks()
$start_dt_ticks=DateTimeTicks()

sleep(10)

$delta_ticks=Ticks()-$start_ticks
$delta_dt_ticks=DateTimeTicks()-$start_dt_ticks

$acc_delta_ticks = $acc_delta_ticks + $delta_ticks
$acc_delta_dt_ticks = $acc_delta_dt_ticks + $delta_dt_ticks
ENDREPEAT

$ticks_ms = TicksToMilliseconds($acc_delta_ticks)
$dt_ticks_ms = DateTimeTicksToMilliseconds($acc_delta_dt_ticks)
$diff = abs($ticks_ms - $dt_ticks_ms)

print("ticks_ms = " + $ticks_ms)
print("dt_ticks_ms = " + $dt_ticks_ms)
print("diff = " + $diff)


User-inserted image
Belgium
#26  
if I read your code correctly, it amplifies the difference a 100 fold, so the actual/average discrepancy is on the order of 0.5ms and much if not all of that could be caused by the execution of the code itself. If the code executed instantly (aside from a perfectly timed sleep), shouldnt you be seeing ~1000ms rather then the ~1380-1440ms you get?

FWIW, this is what I get:


User-inserted image
#27  
@vertigo:
The values are relative.

I can't get less than 50 ms difference, worst case 70 ms.

The script execution: 100 times x 10 ms + script interpretation, overhead etc etc takes between 1300 - 1800 ms.
Belgium
#28  
Well thats my point; looping through the code that is doing the measuring takes almost as long to execute as the time intervals you are trying to measure. So its difficult to conclude where the difference comes from.

Either way, I think we can agree its not an atomic clock, but I also find it difficult to come up with EZB scenarios where a sub millisecond errors per measurement is a big problem.