行业知识
参考线平滑 - FemPosDeviation算法
FemPosDeviation参考���平滑方法是离散点平滑方法
参考文章:
(1)参考线平滑-FemPosDeviation-OSQP
(2)Planning基础库——散点曲线平滑
(3)参考线平滑-FemPosDeviation-SQP
(4)Apollo planning之参考线平滑算法
(5)解析百度Apollo之参考线与轨迹
(6)百度Apollo代码阅读:参考线平滑FemPosDeviationSmoother
(7)Apollo:参考线ReferenceLine是如何定义的
(8)apollo介绍之参考线(二十七)
1 参考线的作用
参考线在planning中的作用相当于一个地基,所有决策与优化都是在参考线的基础上进行
为什么需要参考线
(1)HD map一般都是人为采集离散点,也就使得原始路径不平滑
(2)全局导航的路径过长,障碍物的投影点也可能不唯一
(3)生成一个局部一定长度且光滑的参考线节省算力
2 ReferenceLine数据结构
参考线是根据车辆位置相对局部的一个数据,它包含了车辆前后一定范围内的路径信息。在车辆行驶过程中,Planning会在每一个计算周期中生成ReferenceLine。
// modules/planning/reference_line/reference_line.huint32_t priority_ = 0; // 优先级struct SpeedLimit { double start_s = 0.0; double end_s = 0.0; double speed_limit = 0.0; // unit m/s};std::vector speed_limit_; // 限速数据std::vector reference_points_; // 一系列的点,点包含了位置的信息。因此这些点就是生成车辆行驶轨迹的基础数据hdmap::Path map_path_; 说明:
Vec2d描述一个二维的点:
double x_:描述点的x坐标
double y_:描述点的y坐标
MapPathPoint描述了一个地图上的点:
double heading_:描述点的朝向。
std::vector lane_waypoints_:描述路径上的点。有些车道可能会存在重合的部分,所以地图上的一个点可能同时属于多个车道,因此这里的数据是一个vector结构。
ReferencePoint描述了参考线中的点:
double kappa_:描述曲线的曲率。
double dkappa_:描述曲率的导数。
ReferencePoint中的朝向和曲率直接影响车辆的方向控制。如果ReferenceLine中的ReferencePoint之间存在朝向和曲率大小震动或者数据跳变将可能导致车辆方向盘的相应变化,这种变化对于乘车体验来说是非常糟糕的。
3 参考线处理流程
① 生成参考线,这主要由Routing模块的输出决定
② 参考线平滑,接下来会详细讲解参考线的平滑的算法
4 参考线平滑算法
4.1 算法分类
Apollo参考线平滑有三种:
① 离散点平滑:Cos和Fem
② 螺线曲线平滑
③ QPSpline平滑
通过配置参数选择要采用的平滑算法
if (smoother_config_.has_qp_spline()) { smoother_.reset(new QpSplineReferenceLineSmoother(smoother_config_)); } else if (smoother_config_.has_spiral()) { smoother_.reset(new SpiralReferenceLineSmoother(smoother_config_)); } else if (smoother_config_.has_discrete_points()) { smoother_.reset(new DiscretePointsReferenceLineSmoother(smoother_config_)); } else { ACHECK(false) if (!FLAGS_enable_smooth_reference_line) { *reference_line = raw_reference_line; return true; } // 设置中间点 std::vectorSmooth(raw_reference_line, reference_line)) { AERROR AERROR common::PathPoint path_point; double lateral_bound = 0.0; // 裕度(留有一定余地) double longitudinal_bound = 0.0; // 裕度 // 强制更平滑以严格遵循此参考点 bool enforced = false;}; case DiscretePointsSmootherConfig::COS_THETA_SMOOTHING: status = CosThetaSmooth(raw_point2d, anchorpoints_lateralbound, &smoothed_point2d); break; case DiscretePointsSmootherConfig::FEM_POS_DEVIATION_SMOOTHING: status = FemPosSmooth(raw_point2d, anchorpoints_lateralbound, &smoothed_point2d); break; default: AERROR AERROR const auto& fem_pos_config = config_.discrete_points().fem_pos_deviation_smoothing(); FemPosDeviationSmoother smoother(fem_pos_config); // box contraints on pos are used in fem pos smoother, thus shrink the // bounds by 1.0 / sqrt(2.0) // 裕度收缩 std::vector bound *= box_ratio; } std::vector AERROR AERROR // 考虑曲率约束 if (config_.apply_curvature_constraint()) { if (config_.use_sqp()) { // 线性求解 return SqpWithOsqp(raw_point2d, bounds, opt_x, opt_y); } else { // 非线性求解 return NlpWithIpopt(raw_point2d, bounds, opt_x, opt_y); } } // 不考虑曲率约束 else { // 线性求解(默认) return QpWithOsqp(raw_point2d, bounds, opt_x, opt_y); } return true;} CHECK_GT(num_of_variables_, 4); // Three quadratic penalties are involved: // 1. Penalty x on distance between middle point and point by finite element // estimate; // 2. Penalty y on path length; // 3. Penalty z on difference between points and reference points // General formulation of P matrix is as below(with 6 points as an example): // I is a two by two identity matrix, X, Y, Z represents x * I, y * I, z * I // 0 is a two by two zero matrix // |X+Y+Z, -2X-Y, X, 0, 0, 0 | // |0, 5X+2Y+Z, -4X-Y, X, 0, 0 | // |0, 0, 6X+2Y+Z, -4X-Y, X, 0 | // |0, 0, 0, 6X+2Y+Z, -4X-Y, X | // |0, 0, 0, 0, 5X+2Y+Z, -2X-Y| // |0, 0, 0, 0, 0, X+Y+Z| // Only upper triangle needs to be filled std::vector columns[col].emplace_back(col, weight_fem_pos_deviation_ + weight_path_length_ + weight_ref_deviation_); ++col_num; } for (int col = 2; col 对约束的代码实现:
void FemPosDeviationOsqpInterface::CalculateAffineConstraint( std::vector* A_data, std::vector* A_indices, std::vector* A_indptr, std::vector* lower_bounds, std::vector* upper_bounds) { int ind_A = 0; for (int i = 0; i push_back(1.0); A_indices->push_back(i); A_indptr->push_back(ind_A); ++ind_A; } A_indptr->push_back(ind_A); for (int i = 0; i push_back(ref_point_xy.first + bounds_around_refs_[i]); upper_bounds->push_back(ref_point_xy.second + bounds_around_refs_[i]); lower_bounds->push_back(ref_point_xy.first - bounds_around_refs_[i]); lower_bounds->push_back(ref_point_xy.second - bounds_around_refs_[i]); }} OSQP还需要设定迭代初值,设定迭代初值为原始参考点坐标
void FemPosDeviationOsqpInterface::SetPrimalWarmStart( std::vector* primal_warm_start) { CHECK_EQ(ref_points_.size(), static_cast(num_of_points_)); for (const auto& ref_point_xy : ref_points_) { primal_warm_start->push_back(ref_point_xy.first); primal_warm_start->push_back(ref_point_xy.second); } 将相关参数输入osqp求解器
data->n = kernel_dim;data->m = num_affine_constraint;data->P = csc_matrix(data->n, data->n, P_data->size(), P_data->data(), P_indices->data(), P_indptr->data());data->q = q->data();data->A = csc_matrix(data->m, data->n, A_data->size(), A_data->data(), A_indices->data(), A_indptr->data());data->l = lower_bounds->data();data->u = upper_bounds->data();*work = osqp_setup(data, settings);osqp_warm_start_x(*work, primal_warm_start->data());// Solve Problemosqp_solve(*work);
从work中抽取计算结果
x_.resize(num_of_points_);y_.resize(num_of_points_);for (int i = 0; i solution->x[index]; y_.at(i) = work->solution->x[index + 1];}
5 缝合参考线(Stitch)
缝合参考线是把2段参考线连接起来,代码中也给出了下面2种情况。并且每次拼接的时候,会尽可能多的采用自身的参考线。最终效果如下:
* Example 1 * this: |--------A-----x-----B------| * other: |-----C------x--------D-------| * Result: |------A-----x-----B------x--------D-------| * In the above example, A-B is current reference line, and C-D is the other * reference line. If part B and part C matches, we update current reference * line to A-B-D. ** Example 2 * this: |-----A------x--------B-------| * other: |--------C-----x-----D------| * Result: |--------C-----x-----A------x--------B-------| * In the above example, A-B is current reference line, and C-D is the other * reference line. If part A and part D matches, we update current reference * line to C-A-B.
bool ReferenceLine::Stitch(const ReferenceLine& other) { // 1. 找到起点的交点 auto first_point = reference_points_.front(); common::SLPoint first_sl; if (!other.XYToSL(first_point, &first_sl)) { AWARN 0 && first_sl.s()
上一篇:拼接屏电脑设置教程