View Single Post
  #9   Spotlight this post!  
Unread 09-12-2008, 17:17
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,647
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Simple C++ State Machine

Possibly just a matter of preference, but wouldn't it make more sense to require the callbacks to return an AutoState and just use that to update the current state? That way, the callbacks can be blissfully ignorant of which instance of state machine is invoking them. I realize it's highly unlikely to have two state machine instances with the same state enumerations... but it still seems neater to me.

Also, who said you had to use this in in the IterativeRobot framework? It would work just fine in the SimpleRobot framework as well. You'd simply create a while loop around the CallCurrentState calls. Do whatever SimpleRobot stuff you want in the callbacks, with waits and everything else. Then when you've finished processing that state, it will loop around and process the next state. If your code has more than two or three cases to deal with, you'd be using switches, if-elses, and other things, and this helps clean those up regardless of what they're doing.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter