def create_single_api_client(self, config, idx): robot_config = config['robots'][idx] configuration = mir100_client.Configuration() configuration.host = robot_config['base_url'] configuration.username = robot_config['user'] configuration.password = robot_config['password'] api_client = mir100_client.ApiClient(configuration) api_client.default_headers['Accept-Language'] = 'en-US' return api_client
def create_robot_command_handles(config, handle_data, dry_run=False): robots = {} for robot_name, robot_config in config['robots'].items(): # CONFIGURE MIR ======================================================= mir_config = robot_config['mir_config'] rmf_config = robot_config['rmf_config'] configuration = mir100_client.Configuration() configuration.username = mir_config['base_url'] configuration.host = mir_config['user'] configuration.password = mir_config['password'] api_client = mir100_client.ApiClient(configuration) api_client.default_headers['Accept-Language'] = 'en-US' # CONFIGURE HANDLE ==================================================== robot = MiRCommandHandle(name=robot_name, node=handle_data['node'], rmf_graph=handle_data['graph'], robot_state_update_frequency=rmf_config.get( 'robot_state_update_frequency', 1), dry_run=dry_run) robot.mir_api = mir100_client.DefaultApi(api_client) robot.transforms = handle_data['transforms'] robot.rmf_map_name = rmf_config['start']['map_name'] if not dry_run: with MiRRetryContext(robot): _mir_status = robot.mir_api.status_get() robot.mir_name = _mir_status.robot_name robot.load_mir_missions() robot.load_mir_positions() else: robot.mir_name = "DUMMY_ROBOT_FOR_DRY_RUN" robots[robot.name] = robot # OBTAIN PLAN STARTS ================================================== start_config = rmf_config['start'] # If the plan start is configured, use it, otherwise, grab it if (start_config.get('waypoint_index') and start_config.get('orientation')): starts = [ plan.Start(handle_data['adapter'].now(), start_config.get('waypoint_index'), start_config.get('orientation')) ] else: starts = plan.compute_plan_starts( handle_data['graph'], start_config['map_name'], robot.get_position(rmf=True, as_dimensions=True), handle_data['adapter'].now()) assert starts, ("Robot %s can't be placed on the nav graph!" % robot_name) # Insert start data into robot start = starts[0] if start.lane.has_value: # If the robot is in a lane robot.rmf_current_lane_index = start.lane.value robot.rmf_current_waypoint_index = None robot.rmf_target_waypoint_index = None else: # Otherwise, the robot is on a waypoint robot.rmf_current_lane_index = None robot.rmf_current_waypoint_index = start.waypoint robot.rmf_target_waypoint_index = None print("MAP_NAME:", start_config['map_name']) robot.rmf_map_name = start_config['map_name'] # INSERT UPDATER ====================================================== def updater_inserter(handle_obj, rmf_updater): """Insert a RobotUpdateHandle.""" handle_obj.rmf_updater = rmf_updater handle_data['fleet_handle'].add_robot(robot, robot.name, handle_data['profile'], starts, partial(updater_inserter, robot)) handle_data['node'].get_logger().info( f"successfully initialized robot {robot.name}" f" (MiR name: {robot.mir_name})") return robots