def create_state_machine(): from rafcon.core.state_machine import StateMachine from rafcon.core.states.hierarchy_state import HierarchyState from rafcon.core.states.execution_state import ExecutionState root = HierarchyState(name='root') ex1 = ExecutionState(name='1') root.add_state(ex1) ex2 = ExecutionState(name='2') root.add_state(ex2) ex3 = ExecutionState(name='3') root.add_state(ex3) # hierarchy state at the beginning h4 = HierarchyState('H4') ex41 = ExecutionState(name='41') h4.add_state(ex41) ex42 = ExecutionState(name='42') h4.add_state(ex42) ex43 = ExecutionState(name='43') h4.add_state(ex43) h4.start_state_id = ex41.state_id h4.add_transition(ex41.state_id, 0, ex42.state_id, None) h4.add_transition(ex42.state_id, 0, ex43.state_id, None) h4.add_transition(ex43.state_id, 0, h4.state_id, 0) root.add_state(h4) root.start_state_id = ex1.state_id root.add_transition(h4.state_id, 0, ex1.state_id, None) root.add_transition(ex1.state_id, 0, ex2.state_id, None) root.add_transition(ex2.state_id, 0, ex3.state_id, None) t_id = root.add_transition(ex3.state_id, 0, root.state_id, 0) return StateMachine(root_state=root), t_id, h4.state_id
def create_models(*args, **kargs): import rafcon.core.singleton from rafcon.core.states.hierarchy_state import HierarchyState from rafcon.core.states.execution_state import ExecutionState from rafcon.core.state_machine import StateMachine state1 = HierarchyState('State1', state_id="State1") state2 = ExecutionState('State2', state_id="State2") ctr_state = HierarchyState(name="Root", state_id="Root") ctr_state.add_state(state1) ctr_state.add_state(state2) ctr_state.start_state_id = state1.state_id ctr_state.add_transition(state1.state_id, from_outcome=0, to_state_id=state2.state_id, to_outcome=None) ctr_state.add_transition(state2.state_id, from_outcome=0, to_state_id=ctr_state.state_id, to_outcome=0) ctr_state.name = "Container" sm = StateMachine(ctr_state) # add new state machine rafcon.core.singleton.state_machine_manager.add_state_machine(sm) rafcon.core.singleton.state_machine_manager.active_state_machine_id = sm.state_machine_id
def create_state_machine(): state1 = ExecutionState("DummyState1", path=testing_utils.TEST_SCRIPT_PATH, filename="transition_test_state.py") state1.add_outcome('dummy_outcome_1', 3) state1.add_outcome('dummy_outcome_2', 4) state2 = ExecutionState("DummyState2", path=testing_utils.TEST_SCRIPT_PATH, filename="transition_test_state.py") state2.add_outcome('dummy_outcome_1', 3) state2.add_outcome('dummy_outcome_2', 4) state3 = ExecutionState("DummyState3", path=testing_utils.TEST_SCRIPT_PATH, filename="transition_test_state.py") state3.add_outcome('dummy_outcome_1', 3) state3.add_outcome('dummy_outcome_2', 4) state4 = HierarchyState("DummyHierarchyState") state4.add_state(state1) state4.set_start_state(state1.state_id) state4.add_state(state2) state4.add_state(state3) state4.add_outcome("final_outcome", 5) state4.add_transition(state1.state_id, 3, state2.state_id, None) state4.add_transition(state1.state_id, 4, state3.state_id, None) state4.add_transition(state2.state_id, 3, state4.state_id, 5) state4.add_transition(state3.state_id, 3, state4.state_id, 5) state4.add_transition(state3.state_id, 4, state4.state_id, 5) t = state4.add_transition(state2.state_id, 4, state1.state_id, None) state4.remove_transition(t) state4.add_transition(state2.state_id, 4, state1.state_id, None) # no target at all with raises(ValueError): state4.add_transition(state3.state_id, 4, None, None) # no to_state with raises(ValueError): state4.add_transition(state3.state_id, 4, None, 5) # start transition already existing with raises(ValueError): state4.add_transition(None, None, state3.state_id, None) state4.start_state_id = None state4.add_transition(None, None, state1.state_id, None) return StateMachine(state4)