当前位置:   article > 正文

carla学习笔记(九)_carla导入opendrive

carla导入opendrive

主要是学习了关于od格式地图的导入工作,是关于两个函数的学习与研究,具体过程和笔记在源码注释里面:

  1. """
  2. 项目开会时,拿到了一份之间实验场地的od格式的地图,老师要求我用rr制作出路网,
  3. 但我导入到rr的时候发现直接崩溃了,联系了matlab公司,售后表示过几天才会有回复.
  4. 所以目前只能先在导入到carla里面进行显示
  5. 然后就是翻看官方的文档,官方比较详细的在CARLA-ECOSYSTEM中的opendrive界面里面提到了直接用自带的config.py
  6. 导入直接生成.然后我尝试了一下,果然可以.但之后的演示肯定不方便
  7. 所以就在api里面查找了相关的函数,发现是generate_opendrive_world()函数
  8. generate_opendrive_world(self, opendrive, parameters=(2.0, 50.0, 1.0, 0.6, true, true), reset_settings=True)
  9. Loads a new world with a basic 3D topology generated from the content of an OpenDRIVE file.
  10. This content is passed as a string parameter. It is similar to client.load_world(map_name)
  11. but allows for custom OpenDRIVE maps in server side. Cars can drive around the map,
  12. but there are no graphics besides the road and sidewalks.
  13. Parameters:
  14. opendrive (str) - Content of an OpenDRIVE file as string, not the path to the .xodr.
  15. parameters (carla.OpendriveGenerationParameters) - Additional settings for the mesh generation.
  16. If none are provided, default values will be used.
  17. reset_settings (bool) - Option to reset the episode setting to default values, set to false to keep the current settings.
  18. This is useful to keep sync mode when changing map and to keep deterministic scenarios.
  19. 然后就准备直接使用,发现一直报错,说无法贴合什么od文件啥的.
  20. 在我仔细研究了config.py的内容后发现,原来是对于这句话没有深刻的理解
  21. "opendrive (str) - Content of an OpenDRIVE file as string, not the path to the .xodr. "
  22. 实现的代码应该是把它read成一个data.
  23. """
  24. # 下面是完整的代码结构
  25. import os
  26. import carla
  27. def show_x_points(world, points):
  28. for point in points:
  29. world.debug.draw_string(point.transform.location, 'X', draw_shadow=False,
  30. color=carla.Color(r=0, g=255, b=0), life_time=50,
  31. persistent_lines=True)
  32. def main():
  33. client = carla.Client('localhost', 2000)
  34. client.set_timeout(2.0)
  35. xodr_path = "/media/hhh/75c0c2a9-f565-4a05-b2a5-5599a918e2f0/hhh/carlaLearning/learning_notes/wuhan2045.xodr"
  36. data = open(xodr_path, encoding='utf-8').read()
  37. # 将围墙的高度添加到了2米
  38. world = client.generate_opendrive_world(data,carla.OpendriveGenerationParameters(
  39. vertex_distance=2.0,
  40. max_road_length=50.0,
  41. wall_height=2.0,
  42. additional_width=0.6,
  43. smooth_junctions=True,
  44. enable_mesh_visibility=True))
  45. spawn_points = world.get_map().get_spawn_points()
  46. way_points = world.get_map().generate_waypoints(distance=1.0)
  47. # generate_waypoints和get_waypoint是两个不一样的东西,
  48. # 第一个是:
  49. # Returns a list of waypoints with a certain distance between them for every lane and centered inside of it.
  50. # Waypoints are not listed in any particular order.
  51. # Remember that waypoints closer than 2cm within the same road, section and lane will have the same identificator.
  52. # 主要生成的还是道路中间的点
  53. # 第二个是:
  54. # Returns a waypoint that can be located in an exact location or translated to the center of the nearest lane.
  55. # Said lane type can be defined using flags such as LaneType.
  56. # Driving & LaneType.Shoulder.
  57. # 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.
  58. # That eases checking if a point is inside a certain road, as otherwise, it will return the corresponding waypoint.
  59. # 是确定vehicled 位置的点
  60. # 两个的差别很大
  61. vehicle_spawn_point = spawn_points[0]
  62. blueprint_library = world.get_blueprint_library()
  63. bp_vehicle = blueprint_library.find('vehicle.audi.tt')
  64. # vehicle = world.spawn_actor(bp_vehicle, vehicle_spawn_point)
  65. # show_x_points(world, spawn_points)
  66. show_x_points(world, way_points)
  67. main()

官方的API文档真的是宝藏,什么都解释的很详细.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/91350
推荐阅读