Exemple #1
0
def demo_path_planner():
    global pp
    global initial_state
    global start_state
    global animation_delay_sec
    start_time = time.time()

    # Initialize to global variable
    demo_initial_state = initial_state

    # If global variable was not set, use a default value
    if not is_valid_file(demo_initial_state):
        demo_initial_state = "examples/initialState/Gorbett-start1.txt"

    # Create initial state
    start_state = pp.initializeStartState(demo_initial_state)
    # NOTE: State is an object that contains a dictionary, state.blocks, in the form {blockid: blockObject}
    # The blockObject should contain all the information necessary to visualize it

    # Create a planner for individual moves
    path_planner = PathPlanner()
    # Display the initial state
    # vis.show_state(start_state)

    # Get moves to put block5 on the table in the given state
    print("------------------------------")
    print("planMove - block5 above table")
    print("------------------------------")
    new_state, moves, visited_states = path_planner.planMove(("block5", "above", "table"), start_state)
    elapsed = str(timedelta(seconds=time.time() - start_time))

    for move in moves:
        print(move[0])
        vis.show_state(move[1], move[0])
        time.sleep(animation_delay_sec)

        # Print final state w/o command.  This is needed to 'remove' command formatting
        vis.show_state(move[1])

    print("Completed move planning in {0} moves after visiting {1} unique states in {2}".format(
        str(len(moves)), str(visited_states), elapsed))

    # Get moves to put slide block4 next to block6
    print("--------------------------------------")
    print("planMove - slide block4 next to block6")
    print("--------------------------------------")
    start_time = time.time()
    new_state, moves, visited_states = path_planner.planMove(("block4", "next-to", "block6"), new_state)
    elapsed = str(timedelta(seconds=time.time() - start_time))

    for move in moves:
        print(move[0])
        vis.show_state(move[1], move[0])
        time.sleep(animation_delay_sec)

        # Print final state w/o command.  This is needed to 'remove' command formatting
        vis.show_state(move[1])

    print("Completed move planning in {0} moves after visiting {1} unique states in {2}".format(
        str(len(moves)), str(visited_states), elapsed))