自动驾驶实时轨迹规划,2022 ICRA 的一个文章复现(顶级机器人会议),可论文。 采用速度路径解耦的方式,linux系统ros,提供场景和源码(apollo路径规划,autoware路径规划)。

最近在复现2022年ICRA上的一篇关于自动驾驶实时轨迹规划的论文,感觉挺有意思的。论文的核心思想是采用速度路径解耦的方式来进行轨迹规划,这种方法在复杂场景下表现尤为出色。复现过程中,我用到了Linux系统和ROS,还参考了Apollo和Autoware的路径规划源码。

先来说说速度路径解耦。简单来说,就是把路径规划和速度规划分开处理。路径规划负责生成一条从起点到终点的路径,而速度规划则在这条路径上决定车辆的速度。这样做的好处是,可以更灵活地应对不同的驾驶场景,比如突然出现的障碍物或者复杂的交通状况。

在复现过程中,我首先搭建了一个基于ROS的仿真环境。ROS的节点通信机制非常适合这种多模块的系统,路径规划和速度规划可以分别作为独立的节点运行,通过话题进行数据交换。下面是一个简单的ROS节点初始化代码:
cpp
#include <ros/ros.h>
int main(int argc, char **argv) {
ros::init(argc, argv, "trajectory_planner");
ros::NodeHandle nh;
// 初始化路径规划节点
PathPlanner path_planner(nh);
// 初始化速度规划节点
SpeedPlanner speed_planner(nh);
ros::spin();
return 0;
}
接下来是路径规划部分。我参考了Apollo的路径规划算法,采用了A算法来生成初始路径。A算法在搜索过程中会综合考虑路径的成本和启发式估计,确保生成的路径既短又安全。代码实现如下:
cpp
std::vector<Node> AStarPlanner::plan(const Node& start, const Node& goal) {
std::priority_queue<Node, std::vector<Node>, CompareNode> open_set;
std::unordered_map<Node, Node, NodeHash> came_from;
std::unordered_map<Node, double, NodeHash> cost_so_far;
open_set.push(start);
came_from[start] = start;
cost_so_far[start] = 0;
while (!open_set.empty()) {
Node current = open_set.top();
open_set.pop();
if (current == goal) {
break;
}
for (const Node& neighbor : getNeighbors(current)) {
double new_cost = cost_so_far[current] + getCost(current, neighbor);
if (!cost_so_far.count(neighbor) || new_cost < cost_so_far[neighbor]) {
cost_so_far[neighbor] = new_cost;
double priority = new_cost + heuristic(neighbor, goal);
neighbor.priority = priority;
open_set.push(neighbor);
came_from[neighbor] = current;
}
}
}
return reconstructPath(came_from, start, goal);
}
速度规划部分,我借鉴了Autoware的速度规划模块。这里采用了基于动态窗口法(DWA)的速度规划算法。DWA算法会在当前速度的基础上,生成一系列可能的速度窗口,然后选择最优的速度组合。代码片段如下:
cpp
Velocity DWAPlanner::plan(const Velocity& current_velocity, const std::vector<Obstacle>& obstacles) {
std::vector<Velocity> possible_velocities = generateVelocities(current_velocity);
Velocity best_velocity;
double best_score = -std::numeric_limits<double>::max();
for (const Velocity& v : possible_velocities) {
double score = evaluateVelocity(v, obstacles);
if (score > best_score) {
best_score = score;
best_velocity = v;
}
}
return best_velocity;
}
整个复现过程中,最让我头疼的是如何在实际场景中验证算法的效果。为此,我搭建了一个包含多种复杂场景的仿真环境,比如交叉路口、环形车道和突然出现的障碍物。通过这些场景的测试,我发现速度路径解耦的方法确实能够有效提高轨迹规划的实时性和安全性。
总的来说,这次复现让我对自动驾驶的轨迹规划有了更深入的理解。虽然过程中遇到了不少挑战,但最终的结果还是令人满意的。如果你也对自动驾驶感兴趣,不妨试试复现这篇论文,相信你会有不少收获。