()
| 296 | time.sleep(5) |
| 297 | |
| 298 | def main(): |
| 299 | carla_path = os.environ["CARLA_ROOT"] |
| 300 | cmd = 'DISPLAY= bash ' + os.path.join(carla_path, 'CarlaUE4.sh')+f' -opengl -carla-rpc-port={args.port} -nosound' |
| 301 | server_process = subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid) |
| 302 | time.sleep(10) ## Wait for carla |
| 303 | client = carla.Client('localhost', int(args.port)) |
| 304 | client.set_timeout(200.0) |
| 305 | print("find carla!", args, flush=True) |
| 306 | |
| 307 | world = client.load_world(args.town) |
| 308 | |
| 309 | print ('loaded world') |
| 310 | |
| 311 | waypoint_list = world.get_map().generate_waypoints(2.0) |
| 312 | print ('got %d possible waypoint'%len(waypoint_list)) |
| 313 | |
| 314 | actors = world.get_actors() |
| 315 | traffic_lights_list = actors.filter('*traffic_light') |
| 316 | print ('got %d traffic lights'%len(traffic_lights_list)) |
| 317 | |
| 318 | max_dist = 300 |
| 319 | min_dist = 50 |
| 320 | |
| 321 | valid_route_list = [] |
| 322 | number = 0 |
| 323 | |
| 324 | distance_list = [] |
| 325 | is_junction_list = [] |
| 326 | |
| 327 | world_map = world.get_map() |
| 328 | |
| 329 | root = ET.Element('routes') |
| 330 | while number < args.route_num: |
| 331 | start_wp = random.choice(waypoint_list) |
| 332 | end_wp = random.choice(waypoint_list) |
| 333 | start_wp = world_map.get_waypoint(start_wp.transform.location,project_to_road=True, lane_type=carla.LaneType.Driving) |
| 334 | end_wp = world_map.get_waypoint(end_wp.transform.location,project_to_road=True, lane_type=carla.LaneType.Driving) |
| 335 | |
| 336 | if start_wp.transform.location.distance(end_wp.transform.location) < min_dist or start_wp.transform.location.distance(end_wp.transform.location) > max_dist: |
| 337 | continue |
| 338 | |
| 339 | wp_list, distance, is_junction = interpolate_trajectory(world_map, [start_wp.transform.location, end_wp.transform.location]) |
| 340 | if wp_list is None: |
| 341 | continue |
| 342 | if distance <= min_dist or distance >= max_dist: |
| 343 | continue |
| 344 | distance_list.append(distance) |
| 345 | is_junction_list.append(is_junction) |
| 346 | |
| 347 | route = ET.SubElement(root, 'route', id='%d'%number, town=args.town) |
| 348 | |
| 349 | # choose a random weather |
| 350 | weather = random.choice(list(WEATHER_LIST.keys())) |
| 351 | route = ET.SubElement(route, 'weather', id=weather, cloudiness='%f'%WEATHER_LIST[weather]['cloudiness'], precipitation='%f'%WEATHER_LIST[weather]['precipitation'], precipitation_deposits='%f'%WEATHER_LIST[weather]['precipitation_deposits'], wind_intensity='%f'%WEATHER_LIST[weather]['wind_intensity'], sun_azimuth_angle='%f'%WEATHER_LIST[weather]['sun_azimuth_angle'], sun_altitude_angle='%f'%WEATHER_LIST[weather]['sun_altitude_angle'], fog_density='%f'%WEATHER_LIST[weather]['fog_density'], fog_distance='%f'%WEATHER_LIST[weather]['fog_distance'], fog_falloff='%f'%WEATHER_LIST[weather]['fog_falloff'],wetness='%f'%WEATHER_LIST[weather]['wetness']) |
| 352 | |
| 353 | x, y, yaw = start_wp.transform.location.x, start_wp.transform.location.y, start_wp.transform.rotation.yaw |
| 354 | ET.SubElement(route, 'waypoint', x='%f'%x, y='%f'%y, z='0.0', |
| 355 | pitch='0.0', roll='0.0', yaw='%f'%yaw) |
no test coverage detected