def __init__(self, args, statistics_manager):
        """
        Setup CARLA client and world
        Setup ScenarioManager
        """
        self.statistics_manager = statistics_manager
        self.sensors = []

        # First of all, we need to create the client that will send the requests
        # to the simulator. Here we'll assume the simulator is accepting
        # requests in the localhost at port 2000.
        self.client = carla.Client(args.host, int(args.port))
        if args.timeout:
            self.client_timeout = float(args.timeout)
        self.client.set_timeout(self.client_timeout)

        dist = pkg_resources.get_distribution("carla")
        if LooseVersion(dist.version) < LooseVersion('0.9.6'):
            raise ImportError(
                "CARLA version 0.9.6 or newer required. CARLA version found: {}"
                .format(dist))

        # Load agent
        module_name = os.path.basename(args.agent).split('.')[0]
        sys.path.insert(0, os.path.dirname(args.agent))
        self.module_agent = importlib.import_module(module_name)

        # Create the ScenarioManager
        self.manager = ScenarioManager(args.debug, args.challenge_mode,
                                       args.track, self.client_timeout)

        # Time control for summary purposes
        self._start_time = GameTime.get_time()
        self._end_time = None
    def __init__(self, args, statistics_manager, customized_data=None):
        """
        Setup CARLA client and world
        Setup ScenarioManager
        """

        self.statistics_manager = statistics_manager
        self.sensors = []
        self._vehicle_lights = carla.VehicleLightState.Position | carla.VehicleLightState.LowBeam

        # First of all, we need to create the client that will send the requests
        # to the simulator. Here we'll assume the simulator is accepting
        # requests in the localhost at port 2000.
        self.client = carla.Client(args.host, int(args.port))
        if args.timeout:
            self.client_timeout = float(args.timeout)
        self.client.set_timeout(self.client_timeout)

        dist = pkg_resources.get_distribution("carla")
        if LooseVersion(dist.version) < LooseVersion('0.9.9'):
            raise ImportError(
                "CARLA version 0.9.9 or newer required. CARLA version found: {}"
                .format(dist))

        # Load agent
        module_name = os.path.basename(args.agent).split('.')[0]
        sys.path.insert(0, os.path.dirname(args.agent))
        self.module_agent = importlib.import_module(module_name)

        # Create the ScenarioManager
        self.manager = ScenarioManager(args.debug, args.sync,
                                       args.challenge_mode, args.track,
                                       self.client_timeout)

        # Time control for summary purposes
        self._start_time = GameTime.get_time()
        self._end_time = None

        # addition
        parent_folder = args.save_folder
        print('-' * 100, args.agent, os.environ['TEAM_AGENT'], '-' * 100)
        if not os.path.exists(parent_folder):
            os.mkdir(parent_folder)
        string = pathlib.Path(os.environ['ROUTES']).stem
        current_record_folder = pathlib.Path(parent_folder) / string

        if os.path.exists(str(current_record_folder)):
            import shutil
            shutil.rmtree(current_record_folder)
        current_record_folder.mkdir(exist_ok=False)
        (current_record_folder / 'rgb').mkdir()
        (current_record_folder / 'rgb_left').mkdir()
        (current_record_folder / 'rgb_right').mkdir()
        (current_record_folder / 'topdown').mkdir()
        (current_record_folder / 'rgb_with_car').mkdir()
        # if args.agent == 'leaderboard/team_code/auto_pilot.py':
        #     (current_record_folder / 'topdown').mkdir()

        self.save_path = str(current_record_folder / 'events.txt')
Esempio n. 3
0
    def __init__(self, args, statistics_manager):
        """
        Setup CARLA client and world
        Setup ScenarioManager
        """
        self.statistics_manager = statistics_manager
        self.sensors = None
        self.sensor_icons = []
        self._vehicle_lights = carla.VehicleLightState.Position | carla.VehicleLightState.LowBeam

        # First of all, we need to create the client that will send the requests
        # to the simulator. Here we'll assume the simulator is accepting
        # requests in the localhost at port 2000.
        self.client = carla.Client(args.host, int(args.port))
        if args.timeout:
            self.client_timeout = float(args.timeout)
        self.client.set_timeout(self.client_timeout)

        self.traffic_manager = self.client.get_trafficmanager(
            int(args.trafficManagerPort))

        dist = pkg_resources.get_distribution("carla")
        if dist.version != 'leaderboard':
            if LooseVersion(dist.version) < LooseVersion('0.9.10'):
                raise ImportError(
                    "CARLA version 0.9.10.1 or newer required. CARLA version found: {}"
                    .format(dist))

        # Load agent
        module_name = os.path.basename(args.agent).split('.')[0]
        sys.path.insert(0, os.path.dirname(args.agent))
        self.module_agent = importlib.import_module(module_name)

        # Create the ScenarioManager
        self.manager = ScenarioManager(args.timeout, args.debug > 1)

        # Time control for summary purposes
        self._start_time = GameTime.get_time()
        self._end_time = None

        # Create the agent timer
        self._agent_watchdog = Watchdog(int(float(args.timeout)))
        signal.signal(signal.SIGINT, self._signal_handler)

        # Set scenario class
        self._scenario_class = {
            'route_scenario': RouteScenario,
            'train_scenario': TrainScenario,
            'nocrash_train_scenario': NoCrashTrainScenario,
            'nocrash_eval_scenario': NoCrashEvalScenario,
        }.get(args.scenario_class)

        if args.scenario_class == 'train_scenario':
            self.town = args.town
        else:
            self.town = None
Esempio n. 4
0
    def __init__(self, args, statistics_manager):
        """
        Setup CARLA client and world
        Setup ScenarioManager
        """
        self.statistics_manager = statistics_manager
        self.sensors = None
        self.sensor_icons = []

        # First of all, we need to create the client that will send the requests
        # to the simulator. Here we'll assume the simulator is accepting
        # requests in the localhost at port 2000.
        self.client = carla.Client(args.host, args.port)
        if args.timeout:
            self.client_timeout = args.timeout
        self.client.set_timeout(self.client_timeout)

        self.traffic_manager = self.client.get_trafficmanager(
            args.traffic_manager_port)

        dist = pkg_resources.get_distribution("carla")
        if dist.version != 'leaderboard':
            if LooseVersion(dist.version) < LooseVersion('0.9.10'):
                raise ImportError(
                    "CARLA version 0.9.10.1 or newer required. CARLA version found: {}"
                    .format(dist))

        # Load agent
        module_name = os.path.basename(args.agent).split('.')[0]
        sys.path.insert(0, os.path.dirname(args.agent))
        self.module_agent = importlib.import_module(module_name)

        # Create the ScenarioManager
        self.manager = ScenarioManager(args.timeout, args.debug > 1)

        # Time control for summary purposes
        self._start_time = GameTime.get_time()
        self._end_time = None

        # Prepare the agent timer
        self._agent_watchdog = None
        signal.signal(signal.SIGINT, self._signal_handler)
Esempio n. 5
0
    def __init__(self,
                 args,
                 statistics_manager,
                 launch_server=False,
                 episode_max_time=10000):
        """
        Setup CARLA client and world
        Setup ScenarioManager
        """

        self.statistics_manager = statistics_manager
        self.sensors = []
        self._vehicle_lights = carla.VehicleLightState.Position | carla.VehicleLightState.LowBeam
        self.episode_max_time = episode_max_time

        # First of all, we need to create the client that will send the requests
        # to the simulator. Here we'll assume the simulator is accepting
        # requests in the localhost at port 2000.

        # This is currently set to be consistent with os.environ['HAS_DISPLAY'].
        # however, it is possible to control them separately.
        if os.environ['HAS_DISPLAY'] == '0':
            os.environ["DISPLAY"] = ''

        gpu = port_to_gpu[args.port]

        # if os.environ.get('SUDO_USER') is not None:
        #     username = os.environ['SUDO_USER']
        # else:
        #     username = os.environ['USER']

        # print('\n'*10, 'username', username, '\n'*10)
        os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)
        self.cmd_list = shlex.split(
            'sh ../carla_0994_no_rss/CarlaUE4.sh -opengl -carla-rpc-port=' +
            str(args.port) + ' -carla-streaming-port=0')

        if launch_server:
            while is_port_in_use(args.port):
                try:
                    subprocess.run('kill $(lsof -t -i :' + str(args.port) +
                                   ')',
                                   shell=True)
                    print('-' * 20, 'kill server at port', port)
                    time.sleep(2)
                except:
                    continue
            subprocess.Popen(self.cmd_list)
            print('-' * 20, 'start server at port', args.port)
            # 10s is usually enough
            time.sleep(10)

        while True:
            try:
                self.client = carla.Client(args.host, int(args.port))
                break
            except:
                logging.exception("__init__ error")
                traceback.print_exc()

        if args.timeout:
            self.client_timeout = float(args.timeout)
        self.client.set_timeout(self.client_timeout)

        dist = pkg_resources.get_distribution("carla")
        if LooseVersion(dist.version) < LooseVersion('0.9.9'):
            raise ImportError(
                "CARLA version 0.9.9 or newer required. CARLA version found: {}"
                .format(dist))

        # Load agent
        module_name = os.path.basename(args.agent).split('.')[0]
        sys.path.insert(0, os.path.dirname(args.agent))
        self.module_agent = importlib.import_module(module_name)

        # Create the ScenarioManager
        self.manager = ScenarioManager(args.debug, args.sync,
                                       args.challenge_mode, args.track,
                                       self.client_timeout,
                                       self.episode_max_time)

        # Time control for summary purposes
        self._start_time = GameTime.get_time()
        self._end_time = None

        # addition
        parent_folder = args.save_folder
        if not os.path.exists(parent_folder):
            os.mkdir(parent_folder)
        string = pathlib.Path(os.environ['ROUTES']).stem
        current_record_folder = pathlib.Path(parent_folder) / string

        if os.path.exists(str(current_record_folder)):
            import shutil
            shutil.rmtree(current_record_folder)
        current_record_folder.mkdir(exist_ok=False)
        (current_record_folder / 'rgb').mkdir()
        (current_record_folder / 'rgb_left').mkdir()
        (current_record_folder / 'rgb_right').mkdir()
        (current_record_folder / 'topdown').mkdir()
        (current_record_folder / 'rgb_with_car').mkdir()
        # if args.agent == 'leaderboard/team_code/auto_pilot.py':
        #     (current_record_folder / 'topdown').mkdir()

        self.save_path = str(current_record_folder / 'events.txt')
Esempio n. 6
0
    def __init__(self,
                 args,
                 statistics_manager,
                 launch_server=False,
                 episode_max_time=10000):
        """
        Setup CARLA client and world
        Setup ScenarioManager
        """

        self.statistics_manager = statistics_manager
        self.sensors = []
        self._vehicle_lights = (carla.VehicleLightState.Position
                                | carla.VehicleLightState.LowBeam)
        self.episode_max_time = episode_max_time

        # First of all, we need to create the client that will send the requests
        # to the simulator.

        # This is currently set to be consistent with os.environ['HAS_DISPLAY'].
        # however, it is possible to control them separately.
        if os.environ["HAS_DISPLAY"] == "0":
            os.environ["DISPLAY"] = ""

        gpu = port_to_gpu(int(args.port))
        os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu)

        if launch_server:
            start_server(args.port)
        start_client(self, args.host, int(args.port))

        if args.timeout:
            self.client_timeout = float(args.timeout)
        self.client.set_timeout(self.client_timeout)

        dist = pkg_resources.get_distribution("carla")
        if LooseVersion(dist.version) < LooseVersion("0.9.9"):
            raise ImportError(
                "CARLA version 0.9.9 or newer required. CARLA version found: {}"
                .format(dist))

        # Load agent
        module_name = os.path.basename(args.agent).split(".")[0]
        sys.path.insert(0, os.path.dirname(args.agent))
        self.module_agent = importlib.import_module(module_name)

        # Create the ScenarioManager
        self.manager = ScenarioManager(
            args.debug,
            args.sync,
            args.challenge_mode,
            args.track,
            self.client_timeout,
            self.episode_max_time,
        )

        # Time control for summary purposes
        self._start_time = GameTime.get_time()
        self._end_time = None

        # addition
        parent_folder = args.save_folder
        if not os.path.exists(parent_folder):
            os.mkdir(parent_folder)
        string = pathlib.Path(os.environ["ROUTES"]).stem
        current_record_folder = pathlib.Path(parent_folder) / string

        if os.path.exists(str(current_record_folder)):
            import shutil

            shutil.rmtree(current_record_folder)
        current_record_folder.mkdir(exist_ok=False)
        (current_record_folder / "rgb").mkdir()
        (current_record_folder / "rgb_left").mkdir()
        (current_record_folder / "rgb_right").mkdir()
        (current_record_folder / "topdown").mkdir()
        (current_record_folder / "rgb_with_car").mkdir()
        # if args.agent == 'leaderboard/team_code/auto_pilot.py':
        #     (current_record_folder / 'topdown').mkdir()

        self.save_path = str(current_record_folder / "events.txt")