Exemple #1
0
def main(arglist):
    start_time = time.time()
    input_file = arglist[0]
    spec = ProblemSpec(input_file)
    obstacles = __get_lenient_obstacles(spec)
    solution=[]

    solution += create_state_graph(spec, obstacles, 0)


    print("time:" + str(time.time()-start_time))
    write_robot_config_list_to_file("filename", solution)
Exemple #2
0
def main(arglist):
    if len(arglist) == 0 or len(arglist) > 2:
        print("Running this file launches a graphical program for visualising maps and solutions.")
        print("Usage: visualiser.py [input_file] [solution_file(optional)]")
        return
    spec = ProblemSpec(arglist[0])
    if len(arglist) == 2:
        soln = load_output(arglist[1])
    else:
        soln = []
    print(spec)
    vis = Visualiser(spec, soln)
Exemple #3
0
def main(arglist):
    start_time = time.time()
    input_file = arglist[0]
    spec = ProblemSpec(input_file)
    obstacles = __get_lenient_obstacles(spec)

    solution = []
    if spec.num_grapple_points == 1:
        solution += create_state_graph(spec, obstacles, 0)
    else:
        for stage in range(spec.num_grapple_points):
            if stage == 0:
                sub_goals = generate_sub_goals(spec, stage, obstacles)
                list1 = create_state_graph(spec,
                                           obstacles,
                                           stage,
                                           sub_goals=sub_goals)
                if list1 is None:
                    print("step1 no solution")
                else:
                    solution += list1
            elif 0 < stage < spec.num_grapple_points - 1:
                sub_goals = generate_sub_goals(spec, stage, obstacles)
                list2 = create_state_graph(spec,
                                           obstacles,
                                           stage,
                                           sub_init=solution[-1],
                                           sub_goals=sub_goals)
                if list2 is None:
                    print("step2 no solution")
                else:
                    solution += list2
            else:
                list3 = create_state_graph(spec,
                                           obstacles,
                                           stage,
                                           sub_init=solution[-1])
                if list3 is None:
                    print("step3 no solution")
                else:
                    solution += list3

    print("time:" + str(time.time() - start_time))
    write_robot_config_list_to_file("filename", solution)
Exemple #4
0
def main(arglist):
    input_file = arglist[0]
    soln_file = arglist[1]

    spec = ProblemSpec(input_file)
    robot_configs = load_output(soln_file)
    lenient_obstacles = __get_lenient_obstacles(spec)
    violations = 0

    # run validity tests for each config
    if not test_config_equality(robot_configs[0], spec.initial, spec):
        violations += 1
        if violations <= 10:
            print("!!! The first robot configuration does not match the initial position from the problem spec !!!")

    for i in range(len(robot_configs)):
        if not test_environment_bounds(robot_configs[i]):
            violations += 1
            if violations <= 10:
                print("!!! Robot goes outside the bounds of the environment at step number " +
                      str(i) + " !!!")

        if not test_angle_constraints(robot_configs[i], spec):
            violations += 1
            if violations <= 10:
                print("!!! One or more of the angles between robot segments is tighter than allowed at step number " +
                      str(i) + " !!!")

        if not test_length_constraints(robot_configs[i], spec):
            violations += 1
            if violations <= 10:
                print("!!! One or more of the robot segments is shorter or longer than allowed at step number " +
                      str(i) + " !!!")

        if not test_grapple_point_constraint(robot_configs[i], spec):
            violations += 1
            if violations <= 10:
                print("!!! Robot is not connected to at least 1 grapple point (or a grapple point is occupied by " +
                      "more than one end effector) at step number " + str(i) + " !!!")

        if not test_self_collision(robot_configs[i], spec):
            violations += 1
            if violations <= 10:
                print("!!! Robot is in collision with itself at step number " + str(i) + " !!!")

        if not test_obstacle_collision(robot_configs[i], spec, lenient_obstacles):
            violations += 1
            if violations <= 10:
                print("!!! Robot is in collision with an obstacle at step number " + str(i) + " !!!")

        if i + 1 < len(robot_configs) and not test_config_distance(robot_configs[i], robot_configs[i+1], spec):
            violations += 1
            if violations <= 10:
                print("!!! Step size is greater than primitive step limit between step number " + str(i) + " and " +
                      str(i + 1) + " !!!")

    if not test_config_equality(robot_configs[-1], spec.goal, spec):
        violations += 1
        if violations <= 10:
            print("!!! The last robot configuration does not match the goal position from the problem spec !!!")

    # print summary
    if violations > 10:
        print("!!! " + str(violations - 10) + " other rule violation(s) !!!")

    if violations == 0:
        print("Testcase solved successfully!")
        return 0
    else:
        print("Invalid solution file - " + str(violations) + " violations encountered.")
        return 1
Exemple #5
0
def main(arglist):
    input_file = arglist[0]
    spec = ProblemSpec(input_file)
    obstacles = __get_lenient_obstacles(spec)
    s = create_state_graph(spec, obstacles)
    write_robot_config_list_to_file("filename", s)
Exemple #6
0
def main(arguments):
    start_time = time.time()
    # Creating problemspec and (initial,goal nodes) from given file
    space = ProblemSpec(arguments[0])
    spec = space
    initial_config = space.initial
    goal_config = space.goal
    g_count=len(space.grapple_points)
    a_count=len(space.min_lengths)

    if len(spec.grapple_points) == 1:
        path_final = path_between_points(initial_config, goal_config, spec, 10,a_count)

    grapple_points=spec.grapple_points
    if len(spec.grapple_points)==2:
        random_configs=[]
        if a_count==3:
            while random_configs==[]:
                random_configs=config3Points(spec,grapple_points[0],grapple_points[1],  spec.min_lengths, spec.max_lengths)
        elif a_count==4:
            while random_configs == []:
                random_configs =config4Points(spec, grapple_points[0], grapple_points[1],spec.min_lengths, spec.max_lengths)
        else:
            print("Configured for 3 and 4 arms only")
        for config in random_configs:
            path_1 = path_between_points(initial_config, config, spec,10,a_count)
            config.ee2_grappled=True
            config.ee1_grappled = False
            path_2 = path_between_points( config,goal_config, spec,20,a_count)
            if path_1 != None and path_2!= None:
                path_final=path_1+path_2
                break

    if len(grapple_points) == 3:
        bridge_1=[]
        if a_count == 3:
            while bridge_1 == []:
                bridge_1 = config3Points(spec, grapple_points[0], grapple_points[1],spec.min_lengths, spec.max_lengths)
                if bridge_1!=[]:
                    bridge_1 = bridge_1[0]
        elif a_count == 4:
            while bridge_1 == []:
                bridge_1 = config4Points(spec, grapple_points[0], grapple_points[1],spec.min_lengths, spec.max_lengths)
        print(bridge_1)
        path_1 = path_between_points(initial_config, bridge_1, spec, 10,a_count)
        print("found path_1")
        write_robot_config_list_to_file("test_output.txt", path_1)
        copy_bridge_1 = copy.deepcopy(bridge_1)
        copy_bridge_1.ee1_grappled = False
        copy_bridge_1.ee2_grappled = True
        bridge_2 = []
        if a_count == 3:
            while bridge_2 == []:
                bridge_2 = config3Points(spec, grapple_points[2], grapple_points[1],spec.min_lengths, spec.max_lengths)
                if bridge_2 != []:
                    bridge_2=bridge_2[0]
        elif a_count == 4:
            while bridge_2 == []:
                bridge_2 = config4Points(spec, grapple_points[2], grapple_points[1],spec.min_lengths, spec.max_lengths)
        bridge_2.ee1_grappled = False
        bridge_2.ee2_grappled = True
        print("bridge 1", copy_bridge_1)
        print("bridge 2", bridge_2)
        path_2 = path_between_points(copy_bridge_1, bridge_2, spec, 10,a_count)
        print("found path_2")
        copy_bridge_2 = copy.deepcopy(bridge_2)
        copy_bridge_2.ee1_grappled = True
        copy_bridge_2.ee2_grappled = False
        path_3 = path_between_points(copy_bridge_2, goal_config, spec, 10,a_count)
        print("found path_3")
        path_final = path_1 + path_2 + path_3
    #dummy = randomsample([GraphNode(spec, dummy_config)], 100, spec, [])
    write_robot_config_list_to_file(arguments[1], path_final)
    end_time = time.time()
    time_rec = end_time - start_time
    print(time_rec)
Exemple #7
0
def main(args):
    spec = ProblemSpec(args[0])
    solve(spec, args[1])