def on_new_plan_req(agents):
    hatpehda.reset_agents_tasks()
    hatpehda.set_state("robot", state1_r)
    hatpehda.set_state("human", state1_h)
    for ag, tasks in agents.items():
        hatpehda.add_tasks(ag, [(t[0], *t[1]) for t in tasks])

    hatpehda.print_state(hatpehda.agents["robot"].state)

    print(hatpehda.agents["robot"].tasks)
    hatpehda.print_methods("robot")
    hatpehda.print_methods("human")
    sol = []
    plans = hatpehda.seek_plan_robot(hatpehda.agents, "robot", sol)
    print(sol)
    rosnode.send_plan(sol)
Exemplo n.º 2
0
def on_new_plan_req(agents):
    for ag, tasks in agents.items():
        state = hatpehda.State(ag + "_init")
        state.types = {
            "Agent": ["isHolding"],
            "Cube": ["isIn", "isHeldBy"],
            "Box": [],
            "ReachableDtBox": [],
            "ReceiverReachableDtBox": [],
            "VisibleDtBox": [],
            "ReceiverVisibleDtBox": [],
            "DirectorVisibleDtBox": [],
            "DirectorReachableDtBox": [],
            "DtDirector": [],
            "DtReceiver": []
        }
        # state_r = retrieve_state_from_ontology("robot", state_r)

        state.individuals = {}
        state.isHolding = {}
        state.individuals["DtReceiver"] = ["human"]
        state.isHolding["human"] = []

        state_h = deepcopy(state)  # TODO: Retrieve it from the ontology
        generate_tidy_all_orders(
            ["cube_GBTG", "cube_BBTG", "cube_GBCG", "cube_GBTB"])
        hatpehda.set_state(ag, state)
        hatpehda.add_tasks(ag, [(t[0], *t[1]) for t in tasks])

    hatpehda.print_state(hatpehda.agents["robot"].state)
    print(hatpehda.agents["robot"].tasks)
    hatpehda.print_methods("robot")
    hatpehda.print_methods("human")
    sol = []
    plans = hatpehda.seek_plan_robot(hatpehda.agents, "robot", sol)
    print(len(hatpehda.ma_solutions))
state1_r = deepcopy(state1_h)

goal1_h = hatpehda.Goal("goal1_h")
goal1_h.isOnStack = {"cube4": True, "cube5": True, "cube6": True}
goal1_h.onStack = ["cube4", "cube5", "cube6"]
goal1_r = deepcopy(goal1_h)

hatpehda.set_state("human", state1_h)
hatpehda.add_tasks("human", [('stack', goal1_h)])
hatpehda.set_state("robot", state1_r)
hatpehda.add_tasks("robot", [('stack', goal1_r)])

hatpehda.print_state(hatpehda.agents["human"].state)

sol = []
plans = hatpehda.seek_plan_robot(hatpehda.agents, "robot", sol)
rosnode = None

generate_standard_domain("plop.xml", "simple_cube_pile")


def on_new_plan_req(agents):
    hatpehda.reset_agents_tasks()
    hatpehda.set_state("robot", state1_r)
    hatpehda.set_state("human", state1_h)
    for ag, tasks in agents.items():
        hatpehda.add_tasks(ag, [(t[0], *t[1]) for t in tasks])

    hatpehda.print_state(hatpehda.agents["robot"].state)

    print(hatpehda.agents["robot"].tasks)
Exemplo n.º 4
0
state1_h = deepcopy(state1_r)

goal1_r = hatpehda.Goal("goal1_r")
goal1_r.assembly = {"top1": ["leg1", "leg2", "leg3", "leg4"]}
#goal1_h = deepcopy(goal1_r)

hatpehda.set_state("human", state1_h)
#hatpehda.add_tasks("human", [('stack', goal1_h)])
hatpehda.set_state("robot", state1_r)
hatpehda.add_tasks("robot", [('assemble_tables', goal1_r)])

#hatpehda.print_state(hatpehda.agents["human"].state)

sol = []
fails = []
plans = hatpehda.seek_plan_robot(hatpehda.agents,
                                 "robot",
                                 sol,
                                 uncontrollable_agent_name="human",
                                 fails=fails)

gui.show_plan(sol + fails, "robot", "human")

print(fails)

print(len(sol), "solutions found")
for agents in sol:
    for name, a in agents.items():
        print(name, "plan:", a.plan)
    print("######")
Exemplo n.º 5
0
    #robot_goal = hatpehda.Goal("robot_goal")
    #robot_goal.isInContainer = {"cube_BGTG": ["throw_box_green"], "cube_GBTG": ["throw_box_green"]}

    hatpehda.set_state("robot", state_filled)
    hatpehda.add_tasks("robot", [("robot_get_right_mug", "human"),
                                 ("robot_go_to_coffee_machine", )])

    human_state = deepcopy(state_filled)
    human_state.__name__ = "human_init"
    hatpehda.set_state("human", human_state)

    sols = []
    fails = []
    start_explore = time.time()
    hatpehda.seek_plan_robot(hatpehda.agents, "robot", sols, "human", fails)
    end_explore = time.time()

    print(len(sols))

    #gui.show_plan(sols, "robot", "human")
    #rosnode = ros.RosNode.start_ros_node("planner", lambda x: print("plop"))
    #time.sleep(5)
    #rosnode.send_plan(sols, "robot", "human")
    cost, root_action = hatpehda.select_conditional_plan(
        sols, "robot", "human", cost_dict)
    gui.show_plan(hatpehda.get_last_actions(root_action), "robot", "human")
    print("policy cost", cost)

    #print("n mug: {}\texplore duration: {}sec\tselect duration: {}sec\tnumber of valid branches: {}".format(n_mug, end_explore - start_explore, end_select - start_select, len(sols)))
Exemplo n.º 6
0
def on_new_plan_req(ctrl_agents, unctrl_agent):
    hatpehda.reset_planner()

    def update_agents(agents, operators, methods):
        for ag, tasks in agents.items():
            state = hatpehda.State(ag + "_init")
            state.types = {
                "Agent": ["isHolding"],
                "DtCube": ["isInContainer", "isHeldBy", "isReachableBy"],
                "DtBox": [],
                "ReachableDtBox": [],
                "ReceiverReachableDtBox": [],
                "VisibleDtBox": [],
                "ReceiverVisibleDtBox": [],
                "DirectorVisibleDtBox": [],
                "DirectorReachableDtBox": [],
                "DtDirector": [],
                "DtReceiver": [],
                "DtThrowBox": []
            }
            state_filled = retrieve_state_from_ontology(ag, state)

            #state_filled = state
            #state_filled.individuals = {'DtCube': ["cube_BGTG", "cube_GBTG", "cube_GGTB"], 'DtBox': ["box_C1", "box_C2", 'box_C3']}
            #state_filled.isInContainer = {'cube_BGTG': ["box_C1"], 'cube_GBTG': ['box_C2'], 'cube_GGTB': ['box_C3']}
            #state_filled.isHeldBy = {'cube_BGTG': [], 'cube_GBTG': [], 'cube_GGTB': []}

            # TODO: remove
            state_filled.individuals["DtReceiver"] = ["human_0"]
            state_filled.isHolding = {next(iter(unctrl_agent)): []}
            state_filled.isReachableBy = {
                c: [next(iter(unctrl_agent))]
                for c in state_filled.individuals["DtCube"]
            }

            hatpehda.declare_operators(ag, *operators)
            for me in methods:
                hatpehda.declare_methods(ag, *me)

            hatpehda.set_state(ag, state_filled)
            hatpehda.add_tasks(ag, [(t[0], *t[1]) for t in tasks])

    update_agents(ctrl_agents, ctrl_operators, ctrl_methods)
    update_agents(unctrl_agent, unctrl_operators, unctrl_methods)
    # hatpehda.print_state(hatpehda.agents["robot"].state)
    # print(hatpehda.agents["robot"].tasks)
    # hatpehda.print_methods("robot")
    # hatpehda.print_methods("human")
    sol = []

    # For now it only works with one controllable and one uncontrollable agents...
    plans = hatpehda.seek_plan_robot(hatpehda.agents,
                                     next(iter(ctrl_agents)),
                                     sol,
                                     uncontrollable_agent_name=next(
                                         iter(unctrl_agent)))
    print(len(sol))
    #regHandler.export_log("human_planning")
    gui.show_plan(sol, next(iter(ctrl_agents)), next(iter(unctrl_agent)))
    print(sol)
    rosnode.send_plan(sol, next(iter(ctrl_agents)), next(iter(unctrl_agent)))