def create_preemption_state_machine():
    state1 = ExecutionState("FirstState",
                            path=testing_utils.TEST_SCRIPT_PATH,
                            filename="concurrence_preemption1.py")
    state1.add_outcome("FirstOutcome", 3)
    input_state1 = state1.add_input_data_port("input_data_port1", "float")

    state2 = ExecutionState("SecondState",
                            path=testing_utils.TEST_SCRIPT_PATH,
                            filename="concurrence_preemption2.py")
    state2.add_outcome("FirstOutcome", 3)
    input_state2 = state2.add_input_data_port("input_data_port1", "float")

    state3 = PreemptiveConcurrencyState("FirstConcurrencyState")
    state3.add_state(state1)
    state3.add_state(state2)
    state3.add_outcome("State1 preempted", 3)
    input_state3 = state3.add_input_data_port("input_data_port1", "float", 0.1)
    input2_state3 = state3.add_input_data_port("input_data_port2", "float",
                                               0.1)
    state3.add_data_flow(state3.state_id, input_state3, state1.state_id,
                         input_state1)
    state3.add_data_flow(state3.state_id, input2_state3, state2.state_id,
                         input_state2)
    state3.add_transition(state1.state_id, 3, state3.state_id, 3)

    return StateMachine(state3)
Beispiel #2
0
def test_preemption_concurrency_state_execution(number_child_states=10, number_childs_per_child=10,
                                                number_of_childs_fast_state=3):

    preemption_state = PreemptiveConcurrencyState("preemption_concurrency")

    for i in range(number_child_states):
        hierarchy_state = create_hierarchy_state(number_childs_per_child)
        preemption_state.add_state(hierarchy_state)
        # preemption_state.add_transition(hierarchy_state.state_id, 0, preemption_state.state_id, 0)

    # add fast state
    hierarchy_state = create_hierarchy_state(number_of_childs_fast_state)
    preemption_state.add_state(hierarchy_state)
    preemption_state.add_transition(hierarchy_state.state_id, 1, preemption_state.state_id, 0)

    execute_state(preemption_state)
Beispiel #3
0
def create_preemptive_wait_state_machine():
    state1 = ExecutionState("state_1",
                            path=testing_utils.TEST_SCRIPT_PATH,
                            filename="preemptive_wait_test.py")
    state1.add_outcome("FirstOutcome", 3)

    state2 = ExecutionState("state_2",
                            path=testing_utils.TEST_SCRIPT_PATH,
                            filename="preemptive_wait_test.py")
    state2.add_outcome("FirstOutcome", 3)

    ctr_state = PreemptiveConcurrencyState("FirstConcurrencyState")
    ctr_state.add_state(state1)
    ctr_state.add_state(state2)
    ctr_state.add_outcome("end", 3)
    ctr_state.add_transition(state1.state_id, 3, ctr_state.state_id, 3)
    ctr_state.add_transition(state2.state_id, 3, ctr_state.state_id, 3)

    return StateMachine(ctr_state)
Beispiel #4
0
def create_turtle_statemachine(base_path, example_path):
    basic_turtle_demo_state = HierarchyState("BasicTurtleDemo")
    init_ros_node = LibraryState("ros_libraries", "init_ros_node", "0.1",
                                 "init ros node")

    basic_turtle_demo_state.add_state(init_ros_node)
    basic_turtle_demo_state.set_start_state(init_ros_node.state_id)

    ########################################################
    # Turtle Concurrency State
    ########################################################

    preemptive_concurrency_state = PreemptiveConcurrencyState(
        "Turtle Concurrency State")
    basic_turtle_demo_state.add_state(preemptive_concurrency_state)
    basic_turtle_demo_state.add_transition(
        init_ros_node.state_id, 0, preemptive_concurrency_state.state_id, None)
    basic_turtle_demo_state.add_transition(
        preemptive_concurrency_state.state_id, 0,
        basic_turtle_demo_state.state_id, 0)

    ########################################################
    # Subscribe to turtle position concurrency State
    ########################################################

    subscribe_to_turtle_position_hierarchy_state = HierarchyState(
        "Turtle Position Subscriber Hierarchy State")

    preemptive_concurrency_state.add_state(
        subscribe_to_turtle_position_hierarchy_state)

    spawn_turtle = LibraryState("turtle_libraries",
                                "turtle_position_subscriber", "0.1",
                                "subscribe to turtle position")
    subscribe_to_turtle_position_hierarchy_state.add_state(spawn_turtle)
    subscribe_to_turtle_position_hierarchy_state.set_start_state(
        spawn_turtle.state_id)
    subscribe_to_turtle_position_hierarchy_state.add_transition(
        spawn_turtle.state_id, 0, spawn_turtle.state_id, None)

    ########################################################
    # Move Turtle Hierarchy State
    ########################################################
    move_turtle_hierarchy_state = HierarchyState("Move Turtle Hierarchy State")
    preemptive_concurrency_state.add_state(move_turtle_hierarchy_state)
    preemptive_concurrency_state.add_transition(
        move_turtle_hierarchy_state.state_id, 0,
        preemptive_concurrency_state.state_id, 0)

    spawn_turtle = LibraryState("turtle_libraries", "spawn_turtle", "0.1",
                                "spawn turtle")
    move_turtle_hierarchy_state.add_state(spawn_turtle)
    move_turtle_hierarchy_state.set_start_state(spawn_turtle.state_id)

    wait1 = ExecutionState("Wait1", path=base_path, filename="wait.py")
    move_turtle_hierarchy_state.add_state(wait1)
    move_turtle_hierarchy_state.add_transition(spawn_turtle.state_id, 0,
                                               wait1.state_id, None)

    teleport_turtle = LibraryState("turtle_libraries", "teleport_turtle",
                                   "0.1", "teleport turtle")
    move_turtle_hierarchy_state.add_state(teleport_turtle)
    move_turtle_hierarchy_state.add_transition(wait1.state_id, 0,
                                               teleport_turtle.state_id, None)

    wait2 = ExecutionState("Wait2", path=base_path, filename="wait.py")
    move_turtle_hierarchy_state.add_state(wait2)
    move_turtle_hierarchy_state.add_transition(teleport_turtle.state_id, 0,
                                               wait2.state_id, None)

    clear_field = LibraryState("turtle_libraries", "clear_field", "0.1",
                               "clear field")
    move_turtle_hierarchy_state.add_state(clear_field)
    move_turtle_hierarchy_state.add_transition(wait2.state_id, 0,
                                               clear_field.state_id, None)

    wait3 = LibraryState(name="Wait3",
                         library_path="generic",
                         library_name="wait")
    move_turtle_hierarchy_state.add_state(wait3)
    move_turtle_hierarchy_state.add_transition(clear_field.state_id, 0,
                                               wait3.state_id, None)

    set_velocity1 = LibraryState("turtle_libraries", "set_velocity", "0.1",
                                 "set velocity1")
    move_turtle_hierarchy_state.add_state(set_velocity1)
    move_turtle_hierarchy_state.add_transition(wait3.state_id, 0,
                                               set_velocity1.state_id, None)

    wait4 = ExecutionState("Wait4", path=base_path, filename="wait.py")
    move_turtle_hierarchy_state.add_state(wait4)
    move_turtle_hierarchy_state.add_transition(set_velocity1.state_id, 0,
                                               wait4.state_id, None)

    move_to_position = LibraryState("turtle_libraries", "move_to_position",
                                    "0.1", "move to position")
    move_turtle_hierarchy_state.add_state(move_to_position)
    move_turtle_hierarchy_state.add_transition(wait4.state_id, 0,
                                               move_to_position.state_id, None)

    move_turtle_hierarchy_state.add_transition(move_to_position.state_id, 1,
                                               move_to_position.state_id, None)

    kill_turtle = LibraryState("turtle_libraries", "kill_turtle", "0.1",
                               "kill turtle")
    move_turtle_hierarchy_state.add_state(kill_turtle)
    move_turtle_hierarchy_state.add_transition(move_to_position.state_id, 0,
                                               kill_turtle.state_id, None)

    move_turtle_hierarchy_state.add_transition(
        kill_turtle.state_id, 0, move_turtle_hierarchy_state.state_id, 0)

    return basic_turtle_demo_state