Carla中实现车辆轨迹获得

Carla中实现车辆循迹及车道保持(使用MPC和强化学习)carla. carla..World 强化学习部分 模仿学习( )
:Carla-Env 需要用到的api carla.map
通过carla.map可以获得当前地图的信息,包括道路的信息和航向点的管理的类函数 。
# 创建一个空图G = nx.Graph()for i in range(len(topology)):waypoint1 = topology[i][0]waypoint2 = topology[i][1]waypoint1_info = "%s-%s-%s" % (waypoint1.road_id, waypoint1.section_id, waypoint1.lane_id)waypoint2_info = "%s-%s-%s" % (waypoint2.road_id, waypoint2.section_id, waypoint2.lane_id)G.add_edge(waypoint1_info, waypoint2_info)# nx.draw_networkx(G)# plt.show()
建立有向图带权重
G = nx.DiGraph()for i in range(len(topology)):waypoint1 = topology[i][0]waypoint2 = topology[i][1]waypoint1_info = "%s-%s-%s" % (waypoint1.road_id, waypoint1.section_id, waypoint1.lane_id)waypoint2_info = "%s-%s-%s" % (waypoint2.road_id, waypoint2.section_id, waypoint2.lane_id)distance = math.sqrt(math.pow((waypoint2.transform.location.x - waypoint1.transform.location.x), 2) +math.pow((waypoint2.transform.location.y - waypoint1.transform.location.y), 2))# G.add_edge(waypoint1_info, waypoint2_info)G.add_weighted_edges_from([(waypoint1_info, waypoint2_info, distance)])
之后使用A*算法即可得到从起点到终点的路径 。
path = nx.astar_path(G, "8-0--2", "483-0-4")
一个简单的方法实现路径规划
【Carla中实现车辆轨迹获得】通过地图给出的拓扑结构,以及的最短路径规划功能可以实现一个简单的路径规划,给定两点的,上述所获得的拓扑图G,键值对信息{key(道路名称):velue(航向点carla.)},以及地图信息即可获得从起始点到终点的路径规划 。注:没有验证是最短路径规划
# 输入起始点和终点的transform,拓扑图,航向点键值对,以及地图,输出从起始点到终点的路径规划def generate_routelist(start, end, G, waypoints_info,_map):start_waypoint = _map.get_waypoint(start.location)start_info = "%s-%s-%s" % (start_waypoint.road_id, start_waypoint.section_id, start_waypoint.lane_id)end_waypoint = _map.get_waypoint(end.location)end_info = "%s-%s-%s" % (end_waypoint.road_id, end_waypoint.section_id, end_waypoint.lane_id)path = nx.astar_path(G, start_info, end_info)print(path)# print(path)RouteList = []list_to_end = start_waypoint.next_until_lane_end(0.25)for j in range(len(list_to_end)):temp_waypoint = list_to_end[j]temp_x = temp_waypoint.transform.location.xtemp_y = temp_waypoint.transform.location.yRouteList.append([temp_x, temp_y])for i in range(1, len(path)):_waypoint = waypoints_info[path[i]]list_to_end = _waypoint.next_until_lane_end(0.25)for j in range(len(list_to_end)):temp_waypoint = list_to_end[j]temp_x = temp_waypoint.transform.location.xtemp_y = temp_waypoint.transform.location.yRouteList.append([temp_x, temp_y])return RouteList
carla.
carla中的航向点,为一个3D的坐标,其中包括carla.具有表示车帘位置的信息和表示车辆方向的信息,同时存储该点与其有关车道的道路信息 。
carla.

Carla中实现车辆轨迹获得

文章插图
十分方便的一个工具包,里面包括了在地图中描点,画箭头、线段,方框的函数
在获得世界信息后使用
debug = world.debug
即可得到实例化类型
carla.World
通过此类,可以获得一个世界对象,world中包括我们要使用的carla.map和carla. 。
此外我们可以对该对象进行设置,包括同步或者异步的属性,通过carla.对象可以对world对象进行属性设置 。