|
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
|