State Machines and Remote Events

From Tekkotsu Wiki

Revision as of 05:47, 8 September 2010 by Touretzky (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The state machine shorthand assumes that all events occur on the local robot. Transitions such as the button event transition =B(...)=> listen for button events by calling addListener, not addRemoteListener. Therefore, transitions have no way to monitor events on remote robots. Adding this capability directly to transitions is not attractive because the overhead involved in setting up a new remote listener every time a transition becomes active would be prohibitive.

The recommended solution is to define a single state node that sets up a remote listener for all events the application needs to monitor, and rebroadcasts them as local events that will be visible to the remaining nodes and links of the state machine. An example of this can be found in the RemoteButtonEvent Demo, where the SetupListener node subscribes to remote button events, and then uses its doEvent method to rebroadcast these as userEGID events. Another active node, listen, has an outgoing EventTrans that looks for these userEGID events and transitions to the node that plays the ping sound, which in turn transitions back to listen. The complete state machine looks like this:

     startnode: StateNode =N=> {instructions, listen}

     instructions: DisplayInstructions =TM=> SetupListener =F=> instructions

     listen: StateNode =E(userEGID)=> SoundNode($,"ping.wav") =N=> listen