mlpy.agents.fsm.StateMachine¶
-
class
mlpy.agents.fsm.StateMachine(states=None, initial=None, transitions=None, onupdate=None)[source]¶ Bases:
mlpy.modules.ModuleThe finite state machine.
The finite state machine handles state transitions, by triggering events. Events can also be fired from outside the state machine to force a transition.
Parameters: states : FSMState | list[FSMState], optional
A list of states.
initial : str, optional
The initial state.
transitions : list[dict] | list[list], optional
Transition information.
onupdate : list[dict] | list[list], optional
Callback information to be executed on update.
Attributes
current_stateThe current event. midThe module’s unique identifier. Methods
add_onupdate(source[, onupdate, conditions])Add a callback to be called on update. add_states(states)Add new state(s) to the managed states. add_transition(event, source, dest[, ...])Add a transition from a source state to a destination state. clear_events([state_name])Clear all events. enter(t)Enter the current state. exit()Exit the finite state machine. get_state(state)Return the FSMState instance with the given name. load(filename)Load the state of the module from file. load_from_file(owner, filename, **kwargs)Load the FSM from file. post_event(e, *args, **kwargs)An event is added to the events list. reset(t, **kwargs)Reset the finite state machine and all registered states. save(filename)Save the current state of the module to file. set_state(state)Set the current state. update(dt)Update state and handle event transitions.