1.BehaviorAgent:
BehaviorAgent实现一个代理,该代理导航场景以到达给定的目标目的地,通过计算到它的最短可能路径。该代理可以正确遵循交通标志、速度限制、,交通信号灯,同时也考虑到附近的车辆。换车道可以通过分析周围环境做出决策,例如超车或避免尾随。可以添加到这些行为,代理还可以与前面的汽车保持安全距离通过跟踪碰撞的瞬时时间并将其保持在一定范围内。最后,从谨慎的角度出发,你可以在代理中编码不同的行为和控制。
2. 模块位于以及引用为
from carla.agents.navigation.behavior_agent import BehaviorAgent
agent = BehaviorAgent(ego_vehicle, behavior="cautious")
goal_spawn_points = world.get_map().get_spawn_points()[27]
#random.shuffle(goal_spawn_points)
if goal_spawn_points.location != agent.vehicle.get_location():
destination = goal_spawn_points.location
else:
destination = goal_spawn_points.location
agent.set_destination(agent.vehicle.get_location(), destination, clean=True)
while True:
agent.update_information()
world.tick()
if len(agent._local_planner.waypoints_queue)<1:
print('======== Success, Arrivied at Target Point!')
break
spectator = world.get_spectator()
transform = ego_vehicle.get_transform()
spectator.set_transform(carla.Transform(transform.location ++carla.Location(z=40),carla.Rotation(pitch=-90)))
speed_limit = ego_vehicle.get_speed_limit()
agent.get_local_planner().set_speed(speed_limit)
control = agent.run_step(debug=True)
ego_vehicle.apply_control(control)
3.重要代码片段解读(原代码见附件)
(1)类中有三个参数,要控制的参与者、是否忽略红绿灯、行为模式(有三个模式,挑normal介绍),可以看到normal模式下面是Cautions()对象,三个模式之间只是对速度等一些信息进行了限制,具体可以看Normal()类。
def __init__(self, vehicle, ignore_traffic_light=False, behavior='normal'):

本文详细介绍了CARLA模拟器中的BehaviorAgent类,它负责自动驾驶车辆的行为决策,包括路径规划、交通信号响应及避障等功能。通过实例代码展示了如何设置目标点、调整驾驶行为以及执行导航任务。
最低0.47元/天 解锁文章
369

被折叠的 条评论
为什么被折叠?



