Asked
— Edited
Hi Everyone,
I've searched for several hours now for a solution to my problem, all to no avail.
I need to start an internal timer during the normal running of a script. The timer will be started with a variable going TRUE or a servo position reached. It will be stopped in the same manner. It cannot be a typical COUNT function but must be actual elapsed time and out to 3 decimal places.
The elapse time noted at the bottom of the DEBUG screen is similar to what I am attempting to trigger internally between two distinct lines of code in my main script.
I love to learn and would appreciate if someone could point me in the right direction. Thanks Jack
I’ll need more information of what you’re attempting to achieve. A timer with 3 decimal place resolution doesn’t mean anything to me. Is that 3 decimal resolution of seconds? Milliseconds? Microseconds? Hours? Weeks?
Remember that working with a non-real-time operating system such as windows, you won’t get too high of a resolution. Also, remember that the communication over WiFi is limited to millisecond resolution.
To know what your communication delay is to the ezb, use the windows command prompt PING command. Ping the IP address of a connected ezb to get the communication delay.
That will be as fast as you can trigger on and off ports per packet.
So first, start by describing what you’re goal is and we’ll be able to work from there.
Hi DJ, Thank you for your interest. I am measuring only the time a light sensor has been triggered ON and goes True to when that same sensor is triggered Off and goes False. The expected time interval for the triggered state of ON til Off would be between 2-10 seconds. The timer must have resolution to a hundredth of a second, ideally to a millisecond . I expect to trigger the timer again after a one second delay between ON / OFF states.
I have considered ControlCommand() to start a Timer Script, whilst the Main Script continues to run and looks for a variable changed to True by the Timer Script.
For the Timer Script, I am unsure what commands to use to actually measure time elapsed as opposed to simply counting cycles once it is called for with Control Command.
What is critical is the measured time of the On / Off state of the light sensor. All other timing inefficiencies caused by data transmission, etc are secondary.
BTW, EZ-Robot has opened up a new world to me by making programming a micro controller so doable. I have struggled for years using other platforms that were not very user friendly. I simply cannot speak more highly of your organization. My Roli was money well spent.
Thanks Jack
That’s great to hear
Is the application requiring some form of communication? Is that why precise timing is necessary?
Also, will a light sensor not detect any change of light? Or is the light a specific wave length that’s been filtered?
While you could measure the time between two digital or adc values with ezscript, my concern is regarding the accuracy. The accuracy is limited to the resolution of the network stack and operating system as mentioned above.
The solution may be to use an arduino connected to the ezb. The arduino can measure the time in real-time and send the response to the ezb.
Hi DJ I am using a Sharp IR sensor to trigger a variable to TRUE / FALSE. The timer will accurately need to time the duration the variable is TRUE. Timing accuracy is critical as this time total will be manipulated through several mathematical equations and compared to another trigger sequence. Too much error will invalidate the result.
I anticipate the time to remain TRUE will be anywhere from 2-10 seconds.
No external communication other than EZ-Bv4 and my laptop.
I could use an ancillary controller, but I suspect EZ-B is capable of this application.
Specifically, what commands could be used to initiate actual time duration, other than simply counting cycles thru a script?
Thanks Jack