コード例 #1
0
def find_best_vehicle_linetask(line_tasks):
    # While there are free vehicles and undistributed tasks
    v_best = None  #vehicle
    l_best = None  #line
    d_best = None
    swap = None

    # Find the shortes distance between a free vehicle and an undistributed task
    for vehicle in free_vehicles:
        for line in line_task:
            d_s = Drone_Services.distance(vehicle.location.global_frame,
                                          line[0])
            d_e = Drone_Services.distance(vehicle.location.global_frame,
                                          line[1])
            d = min(d_e, d_s)
            if (d_best == None) or (d < d_best):
                d_best = d
                v_best = vehicle
                l_best = line
                swap = (d_e < d_s)
    if d_best == None:
        raise RuntimeError(
            "Unexpected Error in distribute tasks: if there are tasks then there should be an optimal one"
        )

    return ["line", v_best, l_best, d_best, swap]
コード例 #2
0
def main():
    Drone_Services.initialize(vehicles, UAV_BASE_PORT, server)
    server.set_fn_message_received(message_received)

    # Start web interface
    with server:
        while True:

            free_vehicles.clear()

            # For each vehicle
            for vehicle in vehicles:
                # If the vehicle does not have a next task, add it to free vehicles
                if not vehicle.nextlocations:
                    free_vehicles.append(vehicle)
                # Else if next task is reached remove it from the vehicles's task lis
                elif Drone_Services.distance(
                        vehicle.nextlocations[0],
                        vehicle.location.global_frame) < 0.001:
                    vehicle.nextlocations.pop(0)
                    # If the vehicle has more tasks, start the next

                    if vehicle.nextlocations:
                        vehicle.simple_goto(vehicle.nextlocations[0])

                    # Else add it to free vehicles
                    else:
                        free_vehicles.append(vehicle)

            # Distribute new tasks
            distribute_tasks(free_vehicles)
            time.sleep(1)
コード例 #3
0
def distribute_taskssss(free_vehicles, line_task):

    # While there are free vehicles and undistributed tasks
    while free_vehicles and line_task:
        v_best = None  #vehicle
        l_best = None  #line
        d_best = None
        swap = None

        # Find the shortes distance between a free vehicle and an undistributed task
        for vehicle in free_vehicles:
            for line in line_task:
                d_s = Drone_Services.distance(vehicle.location.global_frame,
                                              line[0])
                d_e = Drone_Services.distance(vehicle.location.global_frame,
                                              line[1])
                d = min(d_e, d_s)
                if (d_best == None) or (d < d_best):
                    d_best = d
                    v_best = vehicle
                    l_best = line
                    swap = (d_e < d_s)
        if d_best == None:
            raise RuntimeError(
                "Unexpected Error in distribute tasks: if there are tasks then there should be an optimal one"
            )

        # Remove the vehicle from free vehicles and remove the task from undistributed tasks
        free_vehicles.remove(v_best)
        line_task.remove(l_best)

        # Swap the line start and end position if the end position is closest
        if swap:
            l_best = reversed(l_best)

        # Add task to the vehicle's task list and start the task
        v_best.nextlocations.extend(l_best)
        v_best.simple_goto(v_best.nextlocations[0])
コード例 #4
0
def find_best_vehicle_polytask(poly_tasks):
    v_best = None  #vehicle
    l_best = None  #line
    p_best = None  #polygon
    d_best = None
    swap = None
    for vehicle in free_vehicles:
        for polygon in poly_tasks:
            for line in polygon:
                d_s = Drone_Services.distance(vehicle.location.global_frame,
                                              line[0])
                d_e = Drone_Services.distance(vehicle.location.global_frame,
                                              line[1])
                d = min(d_e, d_s)
                if (d_best == None) or (d < d_best):
                    d_best = d
                    v_best = vehicle
                    p_best = polygon
                    l_best = line
                    swap = (d_e < d_s)
    if swap:
        l_best = reversed(l_best)

    return ["poly", v_best, l_best, d_best, swap]