StateNode class

Dave Touretzky edited this page Dec 26, 2016 · 4 revisions

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.

Methods to Override

StateNode provides six methods that users can override:

def __init__(self):
Initialization method. Be sure to include a call to super().__init__() as part of your __init__ method.
def start(self, event=None):
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.
def stop(self):
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.
def poll(self):
Method called repeatedly when polling has been requested.
def handle_event(self, event):
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.
def setup(self):
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.

Setup Methods

set_polling_interval(interval)
Request that the node be polled every interval seconds by calling its poll() method.
set_name(name)
Sets the name of the node. Normally filled in by genfsm.
set_parent(parent)
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.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.