基于OBCA的开放空间路径规划
在上文中,我们提到了利用Hbyrid A*和ReedShepp算法规划开放空间无碰撞的路径。该算法通过对空间离散化以及迭代的思想求解。但是这一算法存在的问题是由于Hybrid A*对转向角度离散化,所以两个节点的曲率是突变的;ReedShepp曲线也是,在两个曲线交点位置曲率也是突变的,这样的轨迹是不适合控制车辆跟踪轨迹行驶的。所以还需要规划出一条平滑无碰撞的路径。apollo基于OBCA改进了一种TDR-OBCA算法实现路径和速度的规划,并发表了《TDR-OBCA: A Reliable Planner for Autonomous Driving in Free-Space Environment》论文。OBCA算法是基于模型预测控制(MPC)建立模型,并用优化算法进行求解。
对于MPC问题,首先定义状态变量xk,包含了在第k时间的x,y坐标、车速以及航向角:
https://www.zhihu.com/equation?tex=x%28k%29+%3D%5Cbegin%7Bpmatrix%7D+++x_x%28k%29+%5C%5C+x_y%28k%29%5C%5C+x_v%28k%29%5C%5C+x_%5Cphi%28k%29++%5Cend%7Bpmatrix%7D
输入变量为前轮转角和加速度:
https://www.zhihu.com/equation?tex=u%28k%29%3D%5B%5Cdelta+%28k%29%2Ca%28k%29%5D%5ET
则根据车辆运动学模型有预测方程:
https://www.zhihu.com/equation?tex=x_x%28k%2B1%29%3Dx_v%28k%29cos%28x_%5Cphi%28k%29%29dt_t%2Bx_x%28k%29%5C%5C+x_y%28k%2B1%29%3Dx_v%28k%29sin%28x_%5Cphi%28k%29%29dt_t%2Bx_y%28k%29%5C%5C+x_%5Cphi%28k%2B1%29%3Dx_v%28k%29tan%28%5Cfrac%7Btan%28%5Cdelta%28k%29%29%7D%7BL%7D%29d_t%2Bx_%7B%5Cphi%7D%28k%29%5C%5C+x_v%28k%2B1%29%3Da%28k%29dt_t%2Bx_v%28k%29
简化为:
https://www.zhihu.com/equation?tex=x%28k%29%3Df%28x%28k-1%29%2Cu%28k-1%29%29
超平面构建障碍物约束
在OBCA算法中是用超平面构建障碍物集,对于二维空间,超平面就是条直线。
比如对于障碍物的Bonding Box有4条边,则用4条直线描述障碍物占据的空间。
比如对于一条边线的超平面:
过A(x1,y1),B(x2,y2)可以求解出直线y=ax+b为过A,B两点的超平面则可以坐标系空间分成两个部分,
直线以上空间可以表示为y>ax+b,直线以下空间可以表示为y<ax+b。
定义
https://www.zhihu.com/equation?tex=tmp1%3D%5Cbegin%7Bbmatrix%7D++x1+%261+%5C%5C+++x2%261+%5Cend%7Bbmatrix%7D%5C%5C+tmp2%3D%5Cbegin%7Bpmatrix%7D++y1+%5C%5C+++y2+%5Cend%7Bpmatrix%7D%5C%5C+ab+%3D+%5Cbegin%7Bpmatrix%7D++a%5C%5C+++b+%5Cend%7Bpmatrix%7D%5C%5C
则有
https://www.zhihu.com/equation?tex=tmp1%5Ctimes+ab+%3Dtmp2%5C%5C+ab+%3Dtmp1%5E%7B%28-1%29%7Dtmp2
由此可以计算出直线a,b的取值
对于任意选择的A,B两点,我们期望从A到B的右侧为y<ax+b,从A到B的左侧为y>ax+b。
假设x1<x2:
集合可以表示为y<ax+b,转化为矩阵约束的形式:
https://www.zhihu.com/equation?tex=A_m%3D%5Cbegin%7Bpmatrix%7D++-a+%5C%5C+++1+%5Cend%7Bpmatrix%7D%5C%5C+b_m%3Db%5C%5C+X%3D%5Cbegin%7Bpmatrix%7D++x+%5C%5C+++y+%5Cend%7Bpmatrix%7D%5C%5C+A_mX%5Cleq+b_m
假设x1>x2:
集合可以表示为y>ax+b,转化为矩阵约束形式:
https://www.zhihu.com/equation?tex=A_m%3D%5Cbegin%7Bpmatrix%7D++a+%5C%5C+++-1+%5Cend%7Bpmatrix%7D%5C%5C+b_m%3D-b%5C%5C+X%3D%5Cbegin%7Bpmatrix%7D++x+%5C%5C+++y+%5Cend%7Bpmatrix%7D%5C%5C+A_mX%5Cleq+b_m
如果一个障碍物有四个边,则有4个超平面相交构成的集合:
则可以将障碍物m的集合写成
https://www.zhihu.com/equation?tex=O%5Em%3D+%5Cleft%5C%7B++o%5Cin+%5Cmathbb%7BR%7D%5E2%3AA%5Emo+%5Cleq+b%5E%7Bm%7D+%5Cright+%5C%7D+%5Cqquad+%5Cforall+m+%3D1%2C...%2CM%5C%5C+A%5Em+%5Cin+%5Cmathbb%7BR%7D%5E%7B4%5Ctimes+2%7D+%5Cquad%5C+b%5Em+%5Cin+%5Cmathbb+R%5E4+%5Cquad%5C+o++%5Cin+%5Cmathbb%7BR%7D%5E2
对应代码:
bool OpenSpaceRoiDecider::GetHyperPlanes(
const size_t &obstacles_num, const Eigen::MatrixXi &obstacles_edges_num,
const std::vector<std::vector<Vec2d>> &obstacles_vertices_vec,
Eigen::MatrixXd *A_all, Eigen::MatrixXd *b_all) {
...
// start building H representation
for (size_t i = 0; i < obstacles_num; ++i) {
// take two subsequent vertices, and computer hyperplane
for (size_t j = 0; j < current_vertice_num; ++j) {
Vec2d v1 = obstacles_vertices_vec;
Vec2d v2 = obstacles_vertices_vec;
Eigen::MatrixXd A_tmp(2, 1), b_tmp(1, 1), ab(2, 1);
// find hyperplane passing through v1 and v2
if (std::abs(v1.x() - v2.x()) < kEpsilon) {
if (v2.y() < v1.y()) {
A_tmp << 1, 0;
b_tmp << v1.x();
} else {
A_tmp << -1, 0;
b_tmp << -v1.x();
}
} else if (std::abs(v1.y() - v2.y()) < kEpsilon) {
if (v1.x() < v2.x()) {
A_tmp << 0, 1;
b_tmp << v1.y();
} else {
A_tmp << 0, -1;
b_tmp << -v1.y();
}
} else {
Eigen::MatrixXd tmp1(2, 2);
tmp1 << v1.x(), 1, v2.x(), 1;
Eigen::MatrixXd tmp2(2, 1);
tmp2 << v1.y(), v2.y();
ab = tmp1.inverse() * tmp2;
double a = ab(0, 0);
double b = ab(1, 0);
if (v1.x() < v2.x()) {
A_tmp << -a, 1;
b_tmp << b;
} else {
A_tmp << a, -1;
b_tmp << -b;
}
}
自车占据空间的也可以为4个超平面相交的集合表示,假设自车中心位于原点的空间表示为
https://www.zhihu.com/equation?tex=%5Cmathbb%7BB%7D%3A%3D%5Cleft%5C%7B+e%3AGe+%5Cleq+g+%5Cright%5C%7D
图中,w代表车宽,l代表车长,则有
https://www.zhihu.com/equation?tex=G+%3D%5Cbegin%7Bbmatrix%7D+1%260%5C%5C+0%261%5C%5C+-1%260%5C%5C+0%26-1+%5Cend%7Bbmatrix%7D%2C+g+%3D%5Cbegin%7Bbmatrix%7D+%5Cfrac%7Bl%7D%7B2%7D%5C%5C+%5Cfrac%7Bw%7D%7B2%7D%5C%5C+%5Cfrac%7Bl%7D%7B2%7D%5C%5C+%5Cfrac%7Bw%7D%7B2%7D+%5Cend%7Bbmatrix%7D
用R(x(k))表示在k时间主车相对原点位置的旋转,t(x(k))表示k时间主车相对原点位置的平移,则有表示第k时间主车占据的位置:
https://www.zhihu.com/equation?tex=%5Cmathbb+E%28x%28k%29%29%3DR%28x%28k%29%29%5Cmathbb+B%2Bt%28x%28k%29%29+
其中旋转矩阵R(x(k))为:
https://www.zhihu.com/equation?tex=R%28x%28k%29%29%3D%5Cbegin%7Bbmatrix%7D+cos%28x_%5Cphi%28k%29%29%26%26sin%28x_%5Cphi%28k%29%29%5C%5C+sin%28x_%5Cphi%28k%29%29%26%26cos%28x_%5Cphi%28k%29%29+%5Cend%7Bbmatrix%7D
平移向量t(x(k))为:
https://www.zhihu.com/equation?tex=t%28x%28k%29%29%3D%5Cbegin%7Bbmatrix%7D+x_x%28k%29%2Bcos%28x_%5Cphi%28k%29%29%5Ccdot+l_%7Boffset%7D%5C%5C+x_y%28k%29%2Bsin%28x_%5Cphi%28k%29%29%5Ccdot+l_%7Boffset%7D%5C%5C+%5Cend%7Bbmatrix%7D
其中l_offset是后轴中心到车辆几何中心的偏移,因为x_x,x_y指的都是车辆后轴中心的位置,要换算到几何中心上来
https://www.zhihu.com/equation?tex=l_%7Boffset%7D%3Dego_%7Blengh%7D+-ego_%7Bback%5C_to%5C_center%7D
构建免碰撞约束
如果要求主车和障碍物没有碰撞,显然有:
https://www.zhihu.com/equation?tex=%5Cmathbb%7BE%7D%28x%28k%29%29%5Ccap+%5Cmathbb%7BO%7D%5E%7B%28m%29%7D%3D%5Cemptyset++%5Cqquad+%5Cforall+m+%3D1%2C...%2CM
就是自车在时间k的空间和所有障碍物的空间交集为空。
如果我们需要自车和障碍物至少保证d_min的间距,我们定义一个自车和障碍物最短距离的函数dist:
https://www.zhihu.com/equation?tex=dist%28%5Cmathbb+E%28x%29%2C%5Cmathbb+O_m%29%3A%3D%5Cmin_%7Bt%7D++%5C%7B%5Cleft+%5C%7C+t+%5Cright+%5C%7C%3A%28%5Cmathbb%7BE%7D%28x%29%2Bt+%29%5Ccap+%5Cmathbb%7BO_m%7D+%3D%5Cemptyset+%5C%7D
对于第m个障碍物根据论文的推论有:
https://www.zhihu.com/equation?tex=dist%28%5Cmathbb+E%28x%29%2C%5Cmathbb+O_m%29%3Ed_%7Bmin%7D%5C%5C+%5CLeftrightarrow+%5Cexists+%5Clambda_m+%5Cgeq+0+%5Cmu_m+%5Cgeq+0%3A-g%5E%5Ctop+%5Cmu_m%2B%28A%5E%7B%28m%29%7Dt%28x%28k%29%29-b_m%29%5E%5Ctop%5Clambda+_m%3Ed_%7Bmin%7D+%5C%5C+G%5E%5Ctop%5Cmu_m%2BR%28x%29%5E%5Ctop+A%5E%7B%28m%29%5Ctop%7D+%5Clambda_m++%3D0+%5C%5C+%5Cleft+%5C%7C++A%5E%7B%28m%29%5Ctop%7D+%5Clambda+%5Cright+%5C%7C_2+%5Cle+1%5C%5C++%5Clambda_m+%5Cgeq+0%2C++%5Cmu_m+%5Cgeq+0%5C%5C
式中引入了两个对偶变量 https://www.zhihu.com/equation?tex=%5Cmu+%5Cin+%5Cmathbb+R%5E4%2C%5Clambda+%5Cin+%5Cmathbb+R%5E%7Bn%7D 其中n是第m个障碍物的边数,注意这里边数可以不为4,也可以不是闭合的。
MPC主体框架
接下来可以介绍OBCA的MPC问题目标函数和约束了,假设每两个控制状态之间的采样时间是固定的ts:
https://www.zhihu.com/equation?tex=%5Cmin_%7Bx%2Cy%2C%5Cmu+%2C%5Clambda%7D+%7B%5Csum_%7Bk+%3D+1%7D%5E%7BK%7Dl%28x%28k%29%2Cu%28k-1%29%29+%7D%5C%5C+subject%5Cspace++to%3A%5C%5C+x%280%29%3Dx_0%5C%5C+x%28K%29%3Dx_F%5C%5C+x%28k%29%3Df%28x%28k-1%29%2Cu%28k-1%29%29%5C%5C+h%28x%28k%29%2Cu%28k%29%29+%5Cleq+0%5C%5C+-g%5E%5Ctop+%5Cmu_m%28k%29%2B%28A%5E%7B%28m%29%7Dt%28x%28k%29%29-b_m%29%5E%5Ctop%5Clambda+_m%28k%29%3Ed_%7Bmin%7D+%5C%5C+G%5E%5Ctop%5Cmu_m%28k%29%2BR%28x%28k%29%29%5E%5Ctop+A%5E%7B%28m%29%5Ctop%7D+%5Clambda_m%28k%29++%3D0+%5C%5C+%5Cleft+%5C%7C++A%5E%7B%28m%29%5Ctop%7D+%5Clambda+%5Cright+%5C%7C_2+%5Cle+1%5C%5C++%5Clambda_m%28k%29+%5Cgeq+0%2C++%5Cmu_m%28k%29+%5Cgeq+0%5C%5C+for+%5Cspace+k%3D1...K%2Cm%3D1...M
其中l为目标函数:
https://www.zhihu.com/equation?tex=l%28x%28k%29%2Cu%28k-1%29%29+%3Da+_x%5Cleft+%5C%7C+x%28k%29-x_%7Bref%7D%28k%29+%5Cright+%5C%7C_2%5E2%2B+a+_u%5Cleft+%5C%7C+u%28k-1%29+%5Cright+%5C%7C_2%5E2%2B%5C%5C+a_%7B%5Ctilde%7Bu%7D+%7D%5Cleft+%5C%7C+%5Cfrac%7Bu%281%29-+%5Ctilde%7Bu%7D%7D%7Bt_s%7D%5Cright+%5C%7C_2%5E2+%2B+a_%7Bu%27%7D%5Cleft+%5C%7C+%5Cfrac%7B%28u%28k-1%29-u%28k-2%29%29%7D%7Bt_s%7D+%5Cright+%5C%7C_2%5E2+
l的第一项描述了状态量和参考值尽可能的小,参考值也是就是算法优化的初始值,因为对于非线性优化算法来讲,初始值的选择对优化结果有着非常重要的影响,所以这里选用了Hybrid A*产生的轨迹作为优化算法的初始值(warm start)。ax为状态变量的权重向量,
l的第二项描述了期望控制量(方向盘转角,加减速度)尽可能小
l的第三项描述了控制量第一个分量和轨迹初始点的加速度、方向盘转角越接近越好,官文给出的原因是因为连续控制决策之间的较大波动可能会使执行器无法跟踪所需的控制命令
l的第四项描述了控制量的变化率越小越好
从约束来看:
第一项是初始点值和给定的起点一致
第二项是终点状态和给定的终点一致
第三项是控制状态满足车辆运动学约束
第四项是对控制状态和输入的约束:
https://www.zhihu.com/equation?tex=-%5Cdelta%27_%7Bmax%7D%5Cleq%5Cfrac%7Bx_%5Cphi%28k%29-x_%5Cphi%28k-1%29%7D%7Bts%7D+%5Cleq+%5Cdelta%27_%7Bmax%7D
第五、六、七、八项是障碍物相关约束,前文已经介绍过了。这个就是apollo DISTANCE_APPROACH_IPOPT_FIXED_TS算法的建模过程,然后调用ipopt算法进行求解。ipopt的优化变量结构定义为:
https://www.zhihu.com/equation?tex=%5Cbegin%7Barray%7D%7Bc%7D+%28x%280%29%2Cy%280%29%2C%5Cphi%280%29%2Cv%280%29%2Cx%281%29%2Cy%281%29%2C%5Cphi%281%29%2Cv%281%29%2C...%2Cx%28K%29%2Cy%28K%29%2C%5Cphi+%28K%29%2Cv%28K%29%2C%5C%5C++%5Cdelta%280%29%2Ca%280%29%2C...%2C%5Cdelta%28K-1%29%2Ca%28K-1%29%2C%5C%5C+%5Clambda+_%7B0%2C0%7D%2C...%2C%5Clambda+_%7BE%2C0%7D%2C+%5Clambda+_%7B0%2C1%7D%2C...%2C%5Clambda+_%7BE%2CK%7D%2C%5C%5C+%5Cmu+_%7B0%2C0%7D%2C...%2C%5Cmu+_%7B4M%2C0%7D%2C+%5Clambda+_%7B0%2C1%7D%2C...%2C%5Clambda+_%7B4M%2CK%7D%2C%29%5C%5C+%5Cend%7Barray%7D
其中E表示障碍物总边数,M为障碍物的数量
ipopt的起始点定义get_start_point()函数,来自于Hybrid A*+ReedShepp规划的轨迹采样点。还有对偶变量λ和μ的初始值会在后文讲到。
代码可以参考modules/planning/open_space/trajectory_smoother/http://distance_approach_ipopt_fixed_ts_interface.cc
此外根据场景需求不同,apollo还设计了几种变形的算法:
采样时间可变的OBCA算法
在该算法中优化变量增加了一个采样时间变化系数t(k),则每两个控制状态之间的时间间隔为t(k)*ts,则问题定义变成:
https://www.zhihu.com/equation?tex=%5Cmin_%7Bx%2Cy%2C%5Cmu+%2C%5Clambda%2Ct%7D+%7B%5Csum_%7Bk+%3D+1%7D%5E%7BK%7Dl%28x%28k%29%2Cu%28k-1%29%29+%7D%5C%5C+subject%5Cspace++to%3A%5C%5C+x%280%29+%3D+x_0%5C%5C+x%28K%29+%3D+x_F%5C%5C+x%28k%29+%3D+f%28x%28k-1%29%2Cu%28k-1%29%2Ct%28k%29%29%5C%5C+h%28x%28k%29%2Cu%28k%29%2Ct%28k%29%29+%5Cleq+0%5C%5C+-g%5E%5Ctop+%5Cmu_m%28k%29%2B%28A%5E%7B%28m%29%7Dt%28x%28k%29%29-b_m%29%5E%5Ctop%5Clambda+_m%28k%29%3Ed_%7Bmin%7D+%5C%5C+G%5E%5Ctop%5Cmu_m%28k%29%2BR%28x%28k%29%29%5E%5Ctop+A%5E%7B%28m%29%5Ctop%7D+%5Clambda_m%28k%29+%3D+0+%5C%5C+%5Cleft+%5C%7C++A%5E%7B%28m%29%5Ctop%7D+%5Clambda+%5Cright+%5C%7C_2+%5Cle+1%5C%5C++%5Clambda_m%28k%29+%5Cgeq+0%2C++%5Cmu_m%28k%29+%5Cgeq+0%5C%5C+for+%5Cspace+k+%3D+1...K%2Cm+%3D+1...M
车辆运动学约束函数变成:
https://www.zhihu.com/equation?tex=x_x%28k%2B1%29%3Dx_x%28k%29%2Bt_st%28k%29%28x_v%28k%29%2B%5Cfrac%7B1%7D%7B2%7Dt_st%28k%29a%28k%29+%29cos%28x_%5Cphi%28k%29%2B%5Cfrac%7B1%7D%7B2%7Dt_st%28k%29x_v%28k%29+tan%28%5Cfrac%7B%5Cdelta%28k%29%7D%7BL%7D%29%29%5C%5C+x_y%28k%2B1%29%3Dx_y%28k%29%2Bt_st%28k%29%28x_v%28k%29%2B%5Cfrac%7B1%7D%7B2%7Dt_st%28k%29a%28k%29+%29sin%28x_%5Cphi%28k%29%2B%5Cfrac%7B1%7D%7B2%7Dt_st%28k%29x_v%28k%29+tan%28%5Cfrac%7B%5Cdelta%28k%29%7D%7BL%7D%29%29%5C%5C+x_%5Cphi%28k%2B1%29%3Dx_%7B%5Cphi%7D%28k%29%2Bt_st%28k%29%28x_v%28k%29%29%2B%5Cfrac%7B1%7D%7B2%7Dt_st%28k%29a%28k%29%29tan%28%5Cfrac%7B%5Cdelta%28k%29%7D%7BL%7D%29+%5C%5C+x_v%28k%2B1%29%3Dx_v%28k%29%2Bt_st%28k%29a%28k%29
状态变量和输入量约束函数h变成:
https://www.zhihu.com/equation?tex=-%5Cdelta%27_%7Bmax%7D%5Cleq%5Cfrac%7Bx_%5Cphi%28k%29-x_%5Cphi%28k-1%29%7D%7Bt_st%28k%29%7D+%5Cleq+%5Cdelta%27_%7Bmax%7D
https://www.zhihu.com/equation?tex=+t%28k%29%3Dt%28k-1%29
https://www.zhihu.com/equation?tex=t_%7Bmin%5C_sample%5C_scaling%7D%5Cleq+t%28k%29%5Cleq+t_%7Bmax%5C_sample%5C_scaling%7D
目标函数l变为:
https://www.zhihu.com/equation?tex=l%28x%28k%29%2Cu%28k-1%29%29+%3Da+_x%5Cleft+%5C%7C+x%28k%29-x_%7Bref%7D%28k%29+%5Cright+%5C%7C_2%5E2%2B+a+_u%5Cleft+%5C%7C+u%28k-1%29+%5Cright+%5C%7C_2%5E2%2B%5C%5C+a_%7B%5Ctilde%7Bu%7D+%7D%5Cleft+%5C%7C+%5Cfrac%7Bu%281%29-+%5Ctilde%7Bu%7D%7D%7Bt_st%28k%29%7D%5Cright+%5C%7C_2%5E2+%2B+a_%7Bu%27%7D%5Cleft+%5C%7C+%5Cfrac%7B%28u%28k-1%29-u%28k-2%29%29%7D%7Bt_st%28k%29%7D+%5Cright+%5C%7C_2%5E2+%2Ba_%7Bt2%7Dt%28k%29%5E2%2B%2Ba_%7Bt1%7Dt%28k%29
多了关于时间系数的优化(为什么要约束1阶和2阶两次)
对应apollo 中DISTANCE_APPROACH_IPOPT的算法
modules/planning/open_space/trajectory_smoother/http://distance_approach_problem.cc
放松终点状态约束
在之前的算法终点位置是硬约束的,硬约束会导致ipopt求解速度变慢,因此apollo将硬约束转化为软约束,因此新的目标函数变为:
https://www.zhihu.com/equation?tex=+J%28x%2Cu%29+%3D%5Csum_%7Bk+%3D+1%7D%5E%7BK%7Dl%28x%28k%29%2Cu%28k-1%29%29%2B%5Calpha_e+%5C%7Cx%28K%29-x_F%5C%7C_2%5E2
对应apollo中 DISTANCE_APPROACH_IPOPT_RELAX_END 算法
modules/planning/open_space/trajectory_smoother/http://distance_approach_ipopt_relax_end_interface.cc
安全距离可调
在之前的算法中安全距离d_min是一个常值,对于任何障碍物都是一样的。但是自动驾驶驾驶中可能有这样的需求,对于行人、对于车辆、对于道路边沿期望的安全距离要求不一样,apollo将安全距离也加入cost函数中,新的目标函数变为:
https://www.zhihu.com/equation?tex=+J%28x%2Cu%29+%3D%5Csum_%7Bk+%3D+1%7D%5E%7BK%7Dl%28x%28k%29%2Cu%28k-1%29%29%2B%5Calpha_e+%5C%7Cx%28K%29-x_F%5C%7C_2%5E2%2B%5Cbeta+%5Csum_%7Bm+%3D+1%7D%5E%7BM%7D%5Csum_%7Bk+%3D+1%7D%5E%7BK%7Dd_m%28k%29%5C%5C+%5Cbeta%3E0%5Cquad+d_m%28k%29%3C0
其中d_m(k)是安全距离的相反数,则约束变为:
https://www.zhihu.com/equation?tex=subject%5Cspace++to%3A%5C%5C+x%280%29+%3D+x_0%5C%5C+x%28k%2B1%29+%3D+f%28x%28k%29%2Cu%28k%29%2Ct%28k%29%29%5C%5C+h%28x%28k%29%2Cu%28k%29%2Ct%28k%29%29+%5Cleq+0%5C%5C+-g%5E%5Ctop+%5Cmu_m%28k%29%2B%28A%5E%7B%28m%29%7Dt%28x%28k%29%29-b_m%29%5E%5Ctop%5Clambda+_m%28k%29%2Bd_%7Bmin%7D%3D0+%5C%5C+G%5E%5Ctop%5Cmu_m%28k%29%2BR%28x%28k%29%29%5E%5Ctop+A%5E%7B%28m%29%5Ctop%7D+%5Clambda_m%28k%29+%3D+0+%5C%5C+%5Cleft+%5C%7C++A%5E%7B%28m%29%5Ctop%7D+%5Clambda+%5Cright+%5C%7C_2+%5Cle+1%5C%5C++%5Clambda_m%28k%29+%5Cgeq+0%2C++%5Cmu_m%28k%29+%5Cgeq+0%EF%BC%8Cd_m%28k%29%3C0%5C%5C+for+%5Cspace+k+%3D+1...K%2Cm+%3D+1...M
对偶变量和轨迹初始值
对于OBCA优化问题,是非凸优化问题,因此算法优化变量初始的猜想值对于最终的优化结果至关重要,不同的初始值会导致求解器获得不同的局部最优解。对于路径的初始值只要来自于上一篇文章介绍的基于Hybrid A*和ReedSheep曲线的Open Space规划器,对于速度、加速度的初始值采用基于二次规划的速度规划算法,文章可以参见:
代码位于modules/planning/open_space/coarse_trajectory_generator/hybrid_a_star.cc:
bool HybridAStar::GenerateSCurveSpeedAcceleration(HybridAStartResult* result) {
...
std::vector<double> x_ref(num_of_knots, path_length);
piecewise_jerk_problem.set_x_ref(ref_s_weight_, std::move(x_ref));
piecewise_jerk_problem.set_dx_ref(ref_v_weight_, max_v * 0.8);
piecewise_jerk_problem.set_weight_ddx(acc_weight_);
piecewise_jerk_problem.set_weight_dddx(jerk_weight_);
piecewise_jerk_problem.set_x_bounds(std::move(x_bounds));
piecewise_jerk_problem.set_dx_bounds(std::move(dx_bounds));
piecewise_jerk_problem.set_ddx_bounds(std::move(ddx_bounds));
piecewise_jerk_problem.set_dddx_bound(max_acc_jerk_);
// solve the problem
if (!piecewise_jerk_problem.Optimize()) {
AERROR << &#34;Piecewise jerk speed optimizer failed!&#34;;
return false;
}
// extract output
const std::vector<double>& s = piecewise_jerk_problem.opt_x();
const std::vector<double>& ds = piecewise_jerk_problem.opt_dx();
const std::vector<double>& dds = piecewise_jerk_problem.opt_ddx();
...
}
再通过采样时间对轨迹离散,就获得了离散后状态变量x(k),和输入量u(k)的初始值。
有了x和u的初始值,计算对偶变量的初始值就可以引入前文介绍的d_min转化为以下优化问题:
https://www.zhihu.com/equation?tex=%5Cmin_%7B%5Cmu%2C%5Clambda+%2Cd%7D%7B%5Csum_%7Bm%3D1%7D%5E%7BM%7D%5Csum_%7Bk%3D1%7D%5E%7BK%7D%7Dd_m%28k%29%5C%5C+subject+%5Cspace+to%3A%5C%5C++-g%5E%5Ctop+%5Cmu_m%28k%29%2B%28A%5E%7B%28m%29%7Dt%28x%28k%29%29-b_m%29%5E%5Ctop%5Clambda+_m%28k%29%2Bd_%7Bmin%7D%3D0+%5C%5C+G%5E%5Ctop%5Cmu_m%28k%29%2BR%28x%28k%29%29%5E%5Ctop+A%5E%7B%28m%29%5Ctop%7D+%5Clambda_m%28k%29+%3D+0+%5C%5C+%5Cleft+%5C%7C++A%5E%7B%28m%29%5Ctop%7D+%5Clambda+%5Cright+%5C%7C_2+%5Cle+1%5C%5C++%5Clambda_m%28k%29+%5Cgeq+0%2C++%5Cmu_m%28k%29+%5Cgeq+0%EF%BC%8Cd_m%28k%29%3C0%5C%5C+for+%5Cspace+k+%3D+1...K%2Cm+%3D+1...M
根据论文所述,这是一个二次约束的二次规划问题(QCQP,但是目标函数是一阶的啊?),不好求解,apollo进一步简化成了一个基本QP问题,主要方法是把二次不等式约束拿到目标函数中:
apollo中也提供了3套求解器,第一个算法用的ipopt求解:
modules/planning/open_space/trajectory_smoother/http://dual_variable_warm_start_ipopt_interface.cc
第二个算法既用了ipopt求解也用了osqp求解(为啥还用ipopt求解?):
modules/planning/open_space/trajectory_smoother/http://dual_variable_warm_start_ipopt_qp_interface.cc
modules/planning/open_space/trajectory_smoother/http://dual_variable_warm_start_osqp_interface.cc
仿真与结果分析
选取sunnyvale with office地图,调用open space规划器,使主车泊入纵向车位:
仿真结果如下所示:
几种算法路径仿真结果:
几种OBCA算法和warm start规划路径比较
终点松弛后,终点位置发生了变化
phi-t曲线
相比于与Hybrid A*产生的路径,OBCA算法产生的结果更为平滑,另外对于relax_end和relax_end_slack由于对终点位置进行了松弛,终点位置发生了变化。从航向角随时间变化曲线中,也可以看出来整体phi的变化相较于warm start曲线也更为平滑,relax_end算法的终点姿态也因为松弛不再是期望终点姿态,relax_end曲率变化更小。
几种算法速度仿真结果
速度曲线v-t
加速度曲线a-t
速度变化曲线可以看出,fix_ts和warm_start曲线采样时间相同(0.5s),所以整体规划时间要比其他obca 采样时间可变的算法(0.4s)要长,obca算法速度和加速度变化相比与warm start也更为平滑。在速度曲线中由于relax_end算法终点位置没做约束,导致规划的终点速度不是0,车辆可能无法及时停下来。个人认为位置终点虽然松弛了,但是终点的速度还是需要加一个硬约束。另外由于没有对输入量施加约束,几种算法终点的加速度也都不是0.
参考
[*]^TDR-OBCA: A Reliable Planner for Autonomous Driving in Free-Space Environmenthttps://arxiv.org/abs/2009.11345
[*]^Optimization-Based Collision Avoidancehttps://arxiv.org/abs/1711.03449
页:
[1]