MCPcopy Create free account
hub / github.com/OpenDriveLab/TCP / main

Function main

tools/generate_random_routes.py:289–353  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

287
288
289def main():
290 client = carla.Client('localhost', 2000)
291 client.set_timeout(200.0)
292 world = client.load_world(args.town)
293 print ('loaded world')
294
295 waypoint_list = world.get_map().generate_waypoints(2.0)
296 print ('got %d possible waypoint'%len(waypoint_list))
297
298 actors = world.get_actors()
299 traffic_lights_list = actors.filter('*traffic_light')
300 print ('got %d traffic lights'%len(traffic_lights_list))
301
302 max_dist = 300
303 min_dist = 50
304
305 valid_route_list = []
306 number = 0
307
308 distance_list = []
309 is_junction_list = []
310
311 world_map = world.get_map()
312
313 root = ET.Element('routes')
314 while number < args.route_num:
315 start_wp = random.choice(waypoint_list)
316 end_wp = random.choice(waypoint_list)
317 start_wp = world_map.get_waypoint(start_wp.transform.location,project_to_road=True, lane_type=carla.LaneType.Driving)
318 end_wp = world_map.get_waypoint(end_wp.transform.location,project_to_road=True, lane_type=carla.LaneType.Driving)
319
320 if start_wp.transform.location.distance(end_wp.transform.location) < min_dist or start_wp.transform.location.distance(end_wp.transform.location) > max_dist:
321 continue
322
323 wp_list, distance, is_junction = interpolate_trajectory(world_map, [start_wp.transform.location, end_wp.transform.location])
324 if wp_list is None:
325 continue
326 if distance <= min_dist or distance >= max_dist:
327 continue
328 distance_list.append(distance)
329 is_junction_list.append(is_junction)
330
331 route = ET.SubElement(root, 'route', id='%d'%number, town=args.town)
332
333 # choose a random weather
334 weather = random.choice(list(WEATHER_LIST.keys()))
335 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'])
336
337 x, y, yaw = start_wp.transform.location.x, start_wp.transform.location.y, start_wp.transform.rotation.yaw
338 ET.SubElement(route, 'waypoint', x='%f'%x, y='%f'%y, z='0.0',
339 pitch='0.0', roll='0.0', yaw='%f'%yaw)
340 x, y, yaw = end_wp.transform.location.x, end_wp.transform.location.y, end_wp.transform.rotation.yaw
341 ET.SubElement(route, 'waypoint', x='%f'%x, y='%f'%y, z='0.0',
342 pitch='0.0', roll='0.0', yaw='%f'%yaw)
343
344 number += 1
345 print(number)
346

Callers 1

Calls 5

get_mapMethod · 0.80
get_actorsMethod · 0.80
distanceMethod · 0.80
writeMethod · 0.80
interpolate_trajectoryFunction · 0.70

Tested by

no test coverage detected