View Single Post
  #13   Spotlight this post!  
Unread 08-01-2014, 12:35
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: How to make timed sequences in java?

Quote:
Originally Posted by Ether View Post
Your "polling" code (a form of state machine as shown) runs once every 20ms yes? While you're waiting for the 2 seconds to elapse, you're doing one simple conditional jump every 20ms.

If CPU usage becomes a problem using this approach, there's probably something seriously wrong elsewhere in the code.


Agreed as stated. The Simple robot code is called once and your own loop runs as often as it can, the Iterative I believe is triggered by packet arrival at 20ms intervals (not in a position to verify at the moment).
I was addressing the more general case. I program microcontrollers where the loop is all yours. In FIRST need there are constraints. I try to teach the generic case (as a statemachine) and mention the FIRSTisms that impact it.
If programming a PIC or similar I would use a timer interupt and be more efficient than either by miles.
Didn't mean to start a debate, just to acknowledge that polling can sometimes be unnecessarily expensive, (and might be compared to a thread whose only instruction was sleep(2000), but I've never profiled either situation), but this was a case where simplicity was probably the best.

Last edited by omalleyj : 08-01-2014 at 12:37. Reason: can't spell