def container_stored(conn, addr): print("Robot " + addr[0] + " said goodbye to his container") robot_ip = addr[0] db_manager.update_container_pos(robot_ip) # tell it where to go next 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)
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")