Go to Post I should have gone to IRI years ago. - Richard Wallace [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #16   Spotlight this post!  
Unread 02-03-2012, 12:43
Brian Selle's Avatar
Brian Selle Brian Selle is offline
Mentor
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Texas
Posts: 170
Brian Selle has a spectacular aura aboutBrian Selle has a spectacular aura aboutBrian Selle has a spectacular aura about
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?
Reply With Quote
  #17   Spotlight this post!  
Unread 02-03-2012, 13:06
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: RPM calculator

Quote:
Originally Posted by btslaser View Post
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?
If you are using a 360 count per rev encoder on a wheel spinning at, say, 4000 rpm, and you are sampling at roughly 20ms, then the delta count per sample would be 480. One count out of 480 is 0.2% so you probably don't need to worry about that.

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.


Reply With Quote
  #18   Spotlight this post!  
Unread 02-03-2012, 13:35
Brian Selle's Avatar
Brian Selle Brian Selle is offline
Mentor
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Texas
Posts: 170
Brian Selle has a spectacular aura aboutBrian Selle has a spectacular aura aboutBrian Selle has a spectacular aura about
Re: RPM calculator

I meant to ask if System.currentTimeMillis() is the best time source -or- is there some other timeStamp to use?
Reply With Quote
  #19   Spotlight this post!  
Unread 02-03-2012, 14:10
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: RPM calculator

Quote:
Originally Posted by btslaser View Post
I meant to ask if System.currentTimeMillis() is the best time source -or- is there some other timeStamp to use?
Don't know about Java, but in C++ there appears to be a nanosecond timer in WPILib:

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);
}
Reply With Quote
  #20   Spotlight this post!  
Unread 02-03-2012, 14:43
Brian Selle's Avatar
Brian Selle Brian Selle is offline
Mentor
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Texas
Posts: 170
Brian Selle has a spectacular aura aboutBrian Selle has a spectacular aura aboutBrian Selle has a spectacular aura about
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!
Reply With Quote
  #21   Spotlight this post!  
Unread 05-03-2012, 01:19
nickpeq nickpeq is offline
Turing-complete
FRC #1255 (Blarglefish)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Baytown, TX
Posts: 60
nickpeq is an unknown quantity at this point
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:46.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi