在CARLA中获取CARLA自动生成的全局路径规划

CARLA生成全局路径规划的代码在

复制代码
carla/PythonAPI/carla/agents/navigation

在自己的carla客户端py文件中

python 复制代码
from agents.navigation.basic_agent import BasicAgent  # pylint: disable=import-error

如果是pycharm开发,要在pycharm的Settings - Project Structure, Add Content Root中加入agents的上级文件夹。

获得所有的生成点

python 复制代码
spawn_points = world.get_map().get_spawn_points()

在其中选择一个起点和一个终点

python 复制代码
start_location = spawn_points[0]
destination = spawn_points[38]

调用BasicAgent的set_destination函数,生成一个全局导航路径。

python 复制代码
agent = BasicAgent(vehicle, 30)
global_route_trace = agent.set_destination(destination.location, start_location=start_location)

上面代码的vehicle是一个汽车的类实例(如何生成一个汽车,参见博主另一篇文章:在CARLA中手动开车,添加双目相机stereo camera,激光雷达Lidar-CSDN博客

设置观察视角

python 复制代码
spectator = world.get_spectator()
transform = carla.Transform()
bv_transform = carla.Transform(transform.location + carla.Location(z=250,x=0), carla.Rotation(yaw=0, pitch=-90))
spectator.set_transform(bv_transform)

将路径可视化,画出上图的效果

python 复制代码
world.debug.draw_string(destination.location, str("destination"), life_time=100)
world.debug.draw_arrow(destination.location, destination.location + destination.get_forward_vector(), life_time=100)

for tup_i in global_route_trace:
    waypoint_i = tup_i[0]
    location = waypoint_i.transform.location
    world.debug.draw_arrow(location, location + waypoint_i.transform.get_forward_vector(), life_time=100)

以上!

相关推荐
To_OC8 小时前
LC 128 最长连续序列:别上来就排序,O (n) 解法才是这题的灵魂
javascript·算法·leetcode
05Kevin21 小时前
lk每日冒险题--数据结构6.27
算法
To_OC1 天前
从一次栈溢出报错说起,我把递归彻底扒明白了
javascript·算法·程序员
千纸鹤安安2 天前
千问Qwen-AgentWorld来了:一个语言模型搞定七大Agent场景,GPT-5.4都输了
算法
七牛开发者2 天前
MCP 到底是什么?为什么 Agent 都想接上它
算法·aigc·agent
kisshyshy2 天前
从递归到迭代,一文吃透二叉树的核心知识与 JavaScript 实现
javascript·算法·代码规范
To_OC2 天前
LC 49 字母异位词分组:想到哈希表很简单,选对 key 才是精髓
javascript·算法·leetcode