Quote:
Originally Posted by Ether
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.