StateNode class - touretzkyds/cozmopedia GitHub Wiki
StateNode is the base class for all state machine nodes. The cozmo_fsm package provides a collection of built-in node types such as Say and Turn that are subclasses (directly or indirectly) of StateNode. You can also make your own node classes by subclassing StateNode.
StateNode provides six methods that users can override:
- Initialization method. Be sure to include a call to super().__init__() as part of your __init__ method.
- This defines the action that should be taken when the node is activated. Be sure to include a call to super().start(event) as part of your start method.
- The action that should be taken when a state node is deactivated. Not usually needed, but useful for cleanup actions. Be sure to include a call to super().stop() as part of your stop method.
- Method called repeatedly when polling has been requested.
- Method that will be called by the cozmo_fsm event router if the node has subscribed to cozmo_fsm events. This is not typically necessary, as event handling is usually done by transitions. But it is available if a node wants to listen for events.
- Method used to construct a child state machine for whom this node will be the parent. The setup method is normally generated automatically by genfsm when you write a state machine in the shorthand notation.
- Request that the node be polled every interval seconds by calling its poll() method.
- Sets the name of the node. Normally filled in by genfsm.
- Set's the node's parent to parent, which must be an instance of StateNode or one of its subclasses. Normally filled in by genfsm.