保姆级教程:在Apollo 8.0中,如何一步步从Routing结果生成Planning用的参考线?

张开发
2026/4/6 11:18:51 15 分钟阅读

分享文章

保姆级教程:在Apollo 8.0中,如何一步步从Routing结果生成Planning用的参考线?
从Routing到PlanningApollo 8.0参考线生成全流程拆解在自动驾驶系统的决策规划模块中参考线的生成质量直接影响最终轨迹的平滑度和安全性。本文将深入Apollo 8.0框架逐步解析如何将Routing模块输出的宏观路径转换为Planning模块可用的高精度参考线。不同于宏观概念介绍我们聚焦代码级的实现细节帮助开发者掌握数据流转的关键环节。1. 路由数据预处理从RoadSegment到RouteSegments当Routing模块完成路径搜索后会返回RoadSegment结构体组成的导航结果。这些原始数据需要经过预处理才能用于参考线生成。在Apollo 8.0中这项工作主要由pnc_map模块完成// modules/map/pnc_map/pnc_map.cc void PncMap::UpdateRoutingResponse(const routing::RoutingResponse routing_response) { route_indices_.clear(); all_route_segments_.clear(); // 转换RoadSegment为RouteSegments for (const auto road : routing_response.road()) { for (const auto passage : road.passage()) { RouteSegments segments; for (const auto lane : passage.segment()) { segments.emplace_back(lane); } all_route_segments_.push_back(segments); } } }关键处理步骤包括车道连续性检查验证相邻LaneSegment的连通性变道类型标记识别LEFT/RIGHT变道区域SL坐标系转换建立局部参考坐标系路径缝合处理处理多段RouteSegments的连接处注意RouteSegments的stitch()方法会处理路径重叠部分确保参考线连续无跳变2. 参考线提供器的工作机制ReferenceLineProvider是连接路由数据与规划模块的核心组件其工作流程可分为三个阶段2.1 路由段匹配与筛选根据车辆当前位置从预处理后的RouteSegments中筛选出候选路径// modules/planning/reference_line/reference_line_provider.cc bool ReferenceLineProvider::GetRouteSegments( const common::VehicleState vehicle_state, std::listRouteSegments* const route_segments) { // 获取车辆最近的车道 auto point common::util::MakePointENU(vehicle_state.x(), vehicle_state.y()); LaneWaypoint waypoint; if (!pnc_map_-GetNearestPointFromRouting(point, waypoint)) { return false; } // 获取可用的RouteSegments return pnc_map_-GetRouteSegments(vehicle_state, route_segments); }筛选标准包括与车辆当前位置的距离阈值默认20米车道行驶方向一致性检查变道可行性评估交通规则约束如单行道2.2 原始参考线生成将RouteSegments转换为原始ReferenceLine的核心过程// modules/planning/reference_line/reference_line.cc bool ReferenceLineProvider::CreateReferenceLine( const std::listRouteSegments route_segments, std::listReferenceLine* reference_lines) { for (const auto segments : route_segments) { std::vectorReferencePoint ref_points; // 1. 提取车道中心线点集 auto raw_points ExtractCenterLinePoints(segments); // 2. 点集平滑处理 if (!smoother_-Smooth(raw_points, smoothed_points)) { return false; } // 3. 构建参考线属性 for (const auto point : smoothed_points) { ref_points.emplace_back(point.x(), point.y(), point.z(), point.heading(), point.kappa(), point.dkappa()); } reference_lines-emplace_back(ref_points); } return true; }2.3 参考线优化与缓存生成的原始参考线需要经过二次优化优化类型实现方法作用范围曲率平滑二次规划(QP)全路径坡度优化三次样条插值纵向剖面速度适配Frenet帧转换动态调整段障碍物避让代价函数调整局部区域# 示例参考线平滑的二次规划问题构建 def build_smoothing_problem(ref_points): # 构建目标函数最小化曲率变化 H build_hessian_matrix(ref_points) f build_gradient_vector(ref_points) # 构建约束条件路径偏差不超过阈值 A, lb, ub build_constraints(ref_points) # 求解QP问题 smoothed_points solve_qp(H, f, A, lb, ub) return smoothed_points3. 多参考线处理策略在复杂场景下如变道、路口系统需要同时处理多条参考线3.1 参考线优先级判定// modules/planning/reference_line/reference_line_info.cc void ReferenceLineInfo::SetPriority() { // 计算每条参考线的cost for (auto ref_line : reference_lines_) { double cost 0.0; cost CalculatePathCost(ref_line); cost CalculateStaticObstacleCost(ref_line); cost CalculateDynamicObstacleCost(ref_line); ref_line.set_priority(cost); } // 按cost升序排序 std::sort(reference_lines_.begin(), reference_lines_.end(), [](const auto a, const auto b) { return a.priority() b.priority(); }); }3.2 参考线合并场景当多条参考线满足合并条件时如完成变道执行合并操作重叠区域检测通过SL坐标系识别路径交叉点平滑过渡处理在合并点附近应用五次多项式插值属性继承规则保留高优先级参考线的速度限制合并交通规则约束更新障碍物投影信息提示合并操作会触发参考线缓存更新需注意线程安全问题4. 调试与性能优化实践4.1 关键日志分析在调试参考线生成问题时应重点关注以下日志信息I|reference_line_provider.cc:345] Created reference line with 128 points, length156.2m W|pnc_map.cc:712] RouteSegments gap detected at s42.3m, stitching... E|qp_spline_smoother.cc:156] QP problem infeasible, fallback to spiral smoother常见问题与解决方法问题现象可能原因解决方案参考线断裂地图数据不连续检查lane_sequence完整性曲率突变平滑权重不合理调整smoother_config参数生成延迟点集密度过高设置合适的resolution参数车辆抖动参考线不平滑启用二次平滑处理4.2 性能优化技巧预计算加速在RouteSegments更新时预先计算静态属性并行化处理对多条候选参考线使用多线程生成缓存复用对未变化的路径段复用上一周期结果动态分辨率根据车速调整参考线点间距// 动态调整参考线密度的实现示例 void ReferenceLineProvider::AdjustResolution() { double speed vehicle_state_.linear_velocity(); double resolution std::max(0.5, std::min(2.0, 1.0 / (speed 0.1))); smoother_config_.set_max_constraint_interval(resolution); }在实际项目中我们发现参考线生成耗时与路径复杂度呈非线性关系。当RouteSegments包含超过5个变道点时建议启用简化模式牺牲部分平滑度换取实时性。

更多文章