Good methods for building a Finite State Machine?
I was building an "acting system" for remote-controlled sackbots, and I had a bit of trouble with it - keeping state that I didn't want it to, not making the transitions I wanted it to, occasionally cycling rapidly between states or jumping momentarily to the wrong state before going to the correct one... I got it sorted out (it still does that momentary "jump to the wrong state before jumping to the correct one" thing, though) but it got me thinking about how to implement a finite state machine (FSM) in LBP2...
It seems like the way to go is to use a big selector for all the possible states in the machine, with logic combined (via AND) with individual outputs to trigger selector inputs - and then one-shot the various triggers to keep them from producing multiple state changes.
It's not an ideal solution: it produces a messier circuit than I'd like. Each input to the selector has to be connected to an OR gate with as many inputs as there are possible triggers for that state.
I tried another approach: still using the selector to control which state was active, but representing each state as a circuit board, and connecting a selector output to the "enable" line for that microchip. Then each microchip (representing a single "state") contains all the logic for its own outgoing transitions. I ran into a few issues there - some of my logic didn't like being turned off and then back on (still looking into that) - and that approach still requires the big OR gates on every selector input. I feel like I was having some other problem with this approach, but I can't remember what. Maybe it was just seeming too cumbersome for the specific problem I was trying to solve...
So, any better ways to make a state machine? It seems like it would be a good way to create behavior patterns in general...