![]() |
Time in Milliseconds
We are trying to program our robots kicker and we are having a problem with inacurate time delays because we can not get the time in milliseconds.
|
Re: Time in Milliseconds
What are you using currently to get the time?
GetTime() has nanosecond resolution, Timer::GetFPGATimestamp() has microsecond resolution, and the Timer class has microsecond resolution. |
Re: Time in Milliseconds
Hmm... Well, I'm sure that there's something buried in the WPILib that can do it for you like using the time() function. But, from a VxWorks perspective, you can issue a:
-> sysClkRateGet() This will tell you the interrupt rate of the system clock. And, sysClkRateSet(100) would set the interrupt rate to 100 Hz (10 ms clock resolution). With that, tickGet() will return the current clock tick count with subsequent calls allowing you to measure elapsed time to the resolution of the system clock. And, taskDelay(1) is a delay of 1 clock tick (10 ms at 100 Hz). You can also create watchdog timers that will attach your code to the system clock interrupt service routine and run it at a specified delay. Again, I'm sure that there's something buried in the WPILib that can provide what you're looking for, but I know VxWorks a lot better than I know the WPILib. HTH, Mike |
Re: Time in Milliseconds
Quote:
|
Re: Time in Milliseconds
By the way, changing the resolution of the clock using low level VxWorks routines may wreak havoc on the timing of the rest of the system. Obviously you can do so, but do it carefully and test well.
Greg McKaskle |
Re: Time in Milliseconds
use Wait(double seconds);
or a Timer |
Re: Time in Milliseconds
BTW, in case you haven't found an optimal solution, I just implemented a GetMsecTime() macro today. The timer object seems a bit heavy to me. This is simple yet functional.
Code:
#define GetMsecTime() (GetFPGATime()/1000) |
Re: Time in Milliseconds
If you want something simple and fast, use the standard C library's ctime (also known as time.h).
the function clock() returns the amount of ticks that have passed since your program started running as a clock_t value. The amount of ticks per second is defined in the macro CLOCKS_PER_SEC. Using this and some simple dimensional analysis, you can easily get how many miliseconds have passed between two clock() calls. |
| All times are GMT -5. The time now is 10:23 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi