Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
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.
Transition provides six methods that users can override:
- Initialization method. Be sure to include a call to super().__init__() as part of your __init__ method.
- 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.
- 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.
- 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).
- 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.
- 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.
Calls to these methods are generated automatically by genfsm.
- Sets the name of the transition.
- Adds source nodes to the transition. Note: all sources and destinations must have the same parent node.
- Adds destination nodes to the transition. Note: all sources and destinations must have the same parent node.