Beispiel #1
0
def request_robot(conn, addr):
    print("Tachikoma!")
    worker_ip = addr[0]
    dock_id = db_manager.get_dock_id_by_ip(worker_ip)
    responsible_robot_ip = planning.nearest_free_robot_to_dock(dock_id)
    if responsible_robot_ip != "":
        planning.robot_perform_task(responsible_robot_ip, planning.Task(planning.TaskType.TO_DOCK, dock_id, 0))
        print(responsible_robot_ip, "is called")
Beispiel #2
0
def dismiss_robot(conn, addr):
    container_id = unpack("B", receive_message(conn, 1))[0]
    dock_id = db_manager.get_dock_id_by_ip(addr[0])
    # find where the grasper for the robot is
    is_grasper_right = db_manager.is_on_dock_robot_grasper_on_right(dock_id)
    # decouple the robot from the dock
    robot_ip = db_manager.robot_leave_dock(dock_id)
    # tell the robot which container it is carrying
    # if the container has already been taken away, mark the robot free
    container_exist = db_manager.set_robot_container(robot_ip, container_id)
    if not container_exist:
        assigned_task = planning.add_free_robot(robot_ip)
        if assigned_task is None:
            planning.robot_go_idle(robot_ip)
        else:
            planning.robot_perform_task(robot_ip, assigned_task)
        return
    # otherwise
    # find the nearest empty shelf slot for the robot to put its container
    # send the route to this robot
    (x, y, slot, level) = planning.nearest_empty_shelf_slot(dock_id, is_grasper_right)
    (route, last_road_orientation) = planning.route_dock_to_shelf(dock_id, ShelfLoc(x, y, slot, level))
    print("robot", robot_ip, "dismissed to", ShelfLoc(x, y, slot, level), "en route", route)
    if dock_id == 1:
        robot_pos = CorLoc(1, 0, 2, 0)
    elif dock_id == 2:
        robot_pos = CorLoc(2, 0, 3, 0)
    else:
        raise Exception("dismiss_robot: robot", robot_ip, "dismissed from unknown dock #", dock_id)
    message = planning.compile_to_shelf_message(robot_pos, route, last_road_orientation, x, y, slot, level, True)
    status = planning.send_route(robot_ip, message)
    # the robot cannot possibly have moved
    assert not status, "dismiss_robot: robot has moved, impossible case"
    # update bookkeeping
    db_manager.set_robot_dest_shelf(robot_ip, x, y, slot, level)
    db_manager.update_container_dest(container_id, x, y, slot, level)
    # TODO: if PACKING, tell worker app to disable "dismiss" button (maybe not?)
    print("Robot " + addr[0] + " is dismissed")
Beispiel #3
0
def request_item(conn, addr):
    worker_ip = addr[0]
    dock_id = db_manager.get_dock_id_by_ip(worker_ip)
    # receive the rest of the message
    data = receive_message(conn, 1)
    item_id = unpack("B", data)[0]
    print("Please fetch me item #" + str(item_id))
    # get info about the container
    result = db_manager.locate_item(item_id)
    if not result:
        # the item does not exist, reply to the app [6]
        send_message(worker_sockets[dock_id], pack("B", 6))
        return
    (container_id, row, col, slot, level, status) = result
    # tell the worker app in which container the requested item is
    send_message(worker_sockets[dock_id], pack("BB", 4, container_id))
    # if the container is going to PACKING dock or has been reserved, we can't do it now
    if status == "TO_PACKING" or status == "RESERVED":
        planning.pend_fetching_task_to(container_id, dock_id)
    # if the container is on shelf, try to find the nearest robot to fetch it and carry to the dock
    elif status == "ON_SHELF":
        responsible_robot_ip = planning.nearest_free_robot_to_shelf(ShelfLoc(row, col, slot, level),
                                                                    container_id, dock_id)
        if responsible_robot_ip != "":
            planning.robot_perform_task(responsible_robot_ip,
                               planning.Task(planning.TaskType.FOR_CONTAINER, dock_id, container_id))
    # if the container is to IMPORT dock or is TO_SHELF, call the robot over
    elif status == "TO_SHELF":
        responsible_robot_ip = db_manager.get_container_carrier(container_id)
        planning.robot_perform_task(responsible_robot_ip, planning.Task(planning.TaskType.TO_DOCK, dock_id, 0))
        # update bookkeeping
        db_manager.set_container_status(container_id, "TO_PACKING")
    # TODO: if called over TO_IMPORT, need to call someone else to that IMPORT dock
    # TODO: or maybe not, because for the moment there can be no container being carried TO_IMPORT anyway
    else:
        raise Exception("request_item: item cannot possibly TO_IMPORT")