Transition class

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

Transition is the base class for all state machine transitions. The cozmo_fsm package provides a collection of built-in transition types such as CompletionTrans and TimerTrans that are subclasses (directly or indirectly) of Transition. You can also make your own node classes by subclassing Transition.

Methods to Override

Transition 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):
The action that will be taken when the transition is activated. Most commonly it adds itself as a listener for some type of event. For example, CompletionTrans listens for a CompletionEvent for each of its source nodes. If you create your own transition classes, be sure to include a call to super().start() as part of your start method.
def stop(self):
The action that will be taken when a transition is deactivated. Normally this removes the transition as an event listener. If you create your own transition classes, be sure to include a call to super().stop() as part of your stop method.
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. If the method determines that the transition should fire, it triggers this by calling self.fire(event).
def poll():
Method that will be called if the transition has requested polling. This is how TimerTrans is implemented: the polling interval is set to the timer value. There are no events involved.
def fire(self, event=None):
Method that determines what it means to 'fire' this type of transition. The normal behavior, which can be obtained by calling super().fire(event), is to first stop all the source nodes and then start all the destination nodes, passing along the event argument to the start methods. It is only necessary to override this method if a different behavior is desired, e.g., picking one destination at random.

Setup Methods

Calls to these methods are generated automatically by genfsm.

set_name(name)
Sets the name of the transition.
add_sources(nodes...)
Adds source nodes to the transition. Note: all sources and destinations must have the same parent node.
add_destinations(destinations...)
Adds destination nodes to the transition. Note: all sources and destinations must have the same parent node.
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.