赞
踩
主要是学习了关于od格式地图的导入工作,是关于两个函数的学习与研究,具体过程和笔记在源码注释里面:
- """
- 项目开会时,拿到了一份之间实验场地的od格式的地图,老师要求我用rr制作出路网,
- 但我导入到rr的时候发现直接崩溃了,联系了matlab公司,售后表示过几天才会有回复.
- 所以目前只能先在导入到carla里面进行显示
- 然后就是翻看官方的文档,官方比较详细的在CARLA-ECOSYSTEM中的opendrive界面里面提到了直接用自带的config.py
- 导入直接生成.然后我尝试了一下,果然可以.但之后的演示肯定不方便
- 所以就在api里面查找了相关的函数,发现是generate_opendrive_world()函数
- generate_opendrive_world(self, opendrive, parameters=(2.0, 50.0, 1.0, 0.6, true, true), reset_settings=True)
- Loads a new world with a basic 3D topology generated from the content of an OpenDRIVE file.
- This content is passed as a string parameter. It is similar to client.load_world(map_name)
- but allows for custom OpenDRIVE maps in server side. Cars can drive around the map,
- but there are no graphics besides the road and sidewalks.
- Parameters:
- opendrive (str) - Content of an OpenDRIVE file as string, not the path to the .xodr.
- parameters (carla.OpendriveGenerationParameters) - Additional settings for the mesh generation.
- If none are provided, default values will be used.
- reset_settings (bool) - Option to reset the episode setting to default values, set to false to keep the current settings.
- This is useful to keep sync mode when changing map and to keep deterministic scenarios.
- 然后就准备直接使用,发现一直报错,说无法贴合什么od文件啥的.
- 在我仔细研究了config.py的内容后发现,原来是对于这句话没有深刻的理解
- "opendrive (str) - Content of an OpenDRIVE file as string, not the path to the .xodr. "
- 实现的代码应该是把它read成一个data.
- """
-
- # 下面是完整的代码结构
- import os
- import carla
- def show_x_points(world, points):
- for point in points:
- world.debug.draw_string(point.transform.location, 'X', draw_shadow=False,
- color=carla.Color(r=0, g=255, b=0), life_time=50,
- persistent_lines=True)
-
- def main():
- client = carla.Client('localhost', 2000)
- client.set_timeout(2.0)
-
- xodr_path = "/media/hhh/75c0c2a9-f565-4a05-b2a5-5599a918e2f0/hhh/carlaLearning/learning_notes/wuhan2045.xodr"
- data = open(xodr_path, encoding='utf-8').read()
-
- # 将围墙的高度添加到了2米
- world = client.generate_opendrive_world(data,carla.OpendriveGenerationParameters(
- vertex_distance=2.0,
- max_road_length=50.0,
- wall_height=2.0,
- additional_width=0.6,
- smooth_junctions=True,
- enable_mesh_visibility=True))
-
- spawn_points = world.get_map().get_spawn_points()
- way_points = world.get_map().generate_waypoints(distance=1.0)
- # generate_waypoints和get_waypoint是两个不一样的东西,
- # 第一个是:
- # Returns a list of waypoints with a certain distance between them for every lane and centered inside of it.
- # Waypoints are not listed in any particular order.
- # Remember that waypoints closer than 2cm within the same road, section and lane will have the same identificator.
- # 主要生成的还是道路中间的点
- # 第二个是:
- # Returns a waypoint that can be located in an exact location or translated to the center of the nearest lane.
- # Said lane type can be defined using flags such as LaneType.
- # Driving & LaneType.Shoulder.
- # The method will return None if the waypoint is not found, which may happen only when trying to retrieve a waypoint for an exact location.
- # That eases checking if a point is inside a certain road, as otherwise, it will return the corresponding waypoint.
- # 是确定vehicled 位置的点
- # 两个的差别很大
- vehicle_spawn_point = spawn_points[0]
- blueprint_library = world.get_blueprint_library()
- bp_vehicle = blueprint_library.find('vehicle.audi.tt')
- # vehicle = world.spawn_actor(bp_vehicle, vehicle_spawn_point)
- # show_x_points(world, spawn_points)
- show_x_points(world, way_points)
-
-
- main()
官方的API文档真的是宝藏,什么都解释的很详细.
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。