|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
||||
|
||||
|
Re: RPM calculator
To calculate the delta time in Java do you use System.currentTimeMillis() before or after getting latest count or is there a better timestamp that is associated with the time the encoder count value was actually taken?
|
|
#17
|
||||
|
||||
|
Re: RPM calculator
Quote:
I suppose you could put the code to grab the encoder count and the system timer in a critical section to prevent getting swapped out between the two operations. |
|
#18
|
||||
|
||||
|
Re: RPM calculator
I meant to ask if System.currentTimeMillis() is the best time source -or- is there some other timeStamp to use?
|
|
#19
|
||||
|
||||
|
Re: RPM calculator
Quote:
Code:
/**
* @brief Gives real-time clock system time with nanosecond resolution
* @return The time, just in case you want the robot to start autonomous at 8pm on Saturday.
*/
double GetTime()
{
struct timespec tp;
clock_gettime(CLOCK_REALTIME,&tp);
double realTime = (double)tp.tv_sec + (double)((double)tp.tv_nsec*1e-9);
return (realTime);
}
|
|
#20
|
||||
|
||||
|
Re: RPM calculator
Excellent! In the WPILib I just found:
Timer.java /** * Return the system clock time in seconds. Return the time from the * FPGA hardware clock in seconds since the FPGA started. * * @return Robot running time in seconds. */ public static double getFPGATimestamp() { return Utility.getFPGATime() / 1000000.0; } Utility.java /** * Read the microsecond timer from the FPGA. * * @return The current time in microseconds according to the FPGA. */ public static long getFPGATime() { return tGlobal.readLocalTime(); } Thanks! |
|
#21
|
|||
|
|||
|
Re: RPM calculator
I generally use System.nanoTime() for anything in Java. It's overkill, but I've never found a reason NOT to use it.
You could measure the dT that it takes to get the latest count and see how negligible it is. (or isn't) Last edited by nickpeq : 05-03-2012 at 01:22. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|