def visualize_paths_from_pddl(task_plan, path_to_map): position = (5, 5 ) # change this to the starting position for your PDDL problem pp.load_image(path_to_map) log = open("../out/planning_execution.log", "w+") task_number = 0 for task in task_plan: # Iterate the whole task list task_number += 1 log.write(str(task) + '\n') if type( task ) is tuple: # Movement must be a tuple, so we are only interested in this case if task[0] == 'MOVEFAST' or task[ 0] == 'MOVESLOW': # This is the action we were looking for new_pos = task[1] # Get the destination for this action print(position, '->', new_pos) path = calculate_path( position, new_pos ) # Calculate the path using a path planning algorithm # Output the path to a file pp.output_image( path_to_map, path, # This last argument is the path where we want to save the file. # Note that there is a good deal of string processing in order to trim the file # name from the path to the map and use it as a basis to contruct the output file, # along with an indication of what task is being executed. '../out/' + path_to_map.split('/')[-1].split( '\\')[-1].split(".")[-2].split('/')[-1] + '_task_' + str(task_number) + '.png') position = new_pos # Update where the agent would be log.close()
def run_path_planning(scenario_file, navmesh_file, grid_size, algorithm, heuristic, start, finish): pp.load_image(scenario_file) if navmesh_file: with open(navmesh_file) as navmesh: path = pp.run_path_planning_mesh(navmesh['mesh'], algo=algorithm, heur=heuristic, start=( int(start.replace('(', '').\ replace(')', '').\ replace(' ', '').split(',')[0]), int(start.replace('(', '').\ replace(')', '').\ replace(' ', '').split(',')[1])), finish=( int(finish.replace('(', '').\ replace(')', '').\ replace(' ', '').split(',')[0]), int(finish.replace('(', '').\ replace(')', '').\ replace(' ', '').split(',')[1]))) else: if not grid_size: print("Please, define a grid size.") exit() path = pp.run_path_planning(int(grid_size), algo=algorithm, heur=heuristic, start=( int(start.replace('(', '').\ replace(')', '').\ replace(' ', '').split(',')[0]), int(start.replace('(', '').\ replace(')', '').\ replace(' ', '').split(',')[1])), finish=( int(finish.replace('(', '').\ replace(')', '').\ replace(' ', '').split(',')[0]), int(finish.replace('(', '').\ replace(')', '').\ replace(' ', '').split(',')[1]))) pp.output_image(scenario_file, path)