Vehicle Motion Planning/Local Planner
局部规划的输出是带有速度信息的一系列轨迹点组成的轨迹,其保证了车辆控制器在车辆跟踪控制过程中的平稳性和安全性。
Stochastic Sampling Methods
RRT(RRT*)
在这个代码中,M是地图环境,x_init是起始位置,x_goal是目标位置。路径经过的随机节点是x_rand。
- 路径空间搜索的过程从起点开始,先随机撒点x_rand;
- 然后查找距离x_rand最近的节点x_near;
- 然后沿着x_near到x_rand方向用步长stepsize的距离得到x_new;
- (RRT*: 以x_new为圆点,r为半径画圆,找到cost最小从x_init - x_near - x_new的路径,此时cost最小路径中的x_near作为父节点。)
- CollisionFree(M, E)方法检测Edge(x_new, x_near)是否与地图M上的障碍物有碰撞,如果没有碰撞,则将这两个点之间增加一条边到图E中;
- 重复上述过程,直至达到目标位置。
Lattice Planner
- Sample based motion planner;
- Plan in Frenet coordinate;
- 通过预定义的网格(即“格子”)创建可能的路径选择;
- The output is a smooth, safe and collision-free local trajectory that satisfies the vehicle’s kinematics and speed constraints which is directly feed into controller.
The basic process of Lattice planner:
- 将车辆当前位姿信息转换到frenet坐标系下,获得车辆在frenet坐标系的初始状态;根据当前速度计算前瞻距离,获得前瞻点,获得车辆在前瞻点位置frenet坐标系下的目标状态。
- 对轨迹状态(轨迹运行时间t,目标速度v,及到参考线的横向位移d)进行采样,通过这三个规划参数可以获得采样状态。
- 构建横向位移和纵向位移的多项式规划函数s(t),d(s)
- 获得横向位移和纵向位移的规划函数后,进行时间插值就可以获得参考线frenet坐标系下的轨迹点
- 最后将轨迹点从frenet坐标系转换到cartesian坐标系,就可以获得物理世界采样轨迹,由于横向和纵向都是通过高次多项式插值获得,以此cartesian坐标系下的轨迹也是光滑的。
- 采样轨迹的碰撞检测、曲率约束及最优轨迹(cost)打分。采样轨迹是一系列满足速度约束的光滑轨迹,但其还需要满足无碰撞和车辆运动学曲率约束的强制约束,及远离障碍物和靠近参考线等组成的代价约束。采样轨迹的打分就是为了获得一条最优的满足约束条件的无碰撞光滑轨迹。该轨迹也是lattice输出到controller用于车辆跟随的轨迹。
Frenet coordinate and Cartesian coordinate transformation(1,5)
Frenet coordinate is a frame on the reference line, is a moving frame. Its origin point r is the nearest point from the vehicle to the path. The t-axis is along the tangiential direction at r while n-axis is pependicular to t-axis.
Cartesian to Frenet
The transformation equations from Cartesian to Frenet coordinates are as follows:
s = s r , s ˙ = v x cos ( θ x − θ r ) 1 − k r l , s ¨ = a x cos ( θ x − θ r ) − s ˙ 2 ( l ′ ( k x 1 − k r l cos ( θ x − θ r ) − k r ) − ( k r ′ l + k r l ′ ) ) 1 − k r l , l = sign ( ( x x − x r ) cos ( θ r ) ( y x − y r ) sin ( θ r ) ) ( ( x − x r ) 2 + ( y − y r ) 2 ) − 1 2 , l ′ = ( 1 − k r l ) tan ( θ x − θ r ) , l ′ ′ = − ( k ′ r l + k r l ′ ) tan ( θ x − θ r ) + 1 − k r l cos 2 ( θ x − θ r ) ( 1 − k r l cos ( θ x − θ r ) k x − k r ) , \begin{align*} s &= s_r, \\ \dot{s} &= \frac{v_x \cos(\theta_x - \theta_r)}{1 - k_r l}, \\ \ddot{s} &= \frac{a_x \cos(\theta_x - \theta_r) - \dot s^2\left(l' ( k_x\frac{1 - k_r l}{\cos(\theta_x - \theta_r)}- k_r ) - (k'_r l + k_r l')\right)}{1 - k_r l}, \\ l &= \text{sign}\left((x_x - x_r) \cos(\theta_r)(y_x - y_r) \sin(\theta_r)\right)((x - x_r)^2 + (y - y_r)^2)^\frac{-1}{2}, \\ l' &= (1 - k_r l)\tan(\theta_x - \theta_r), \\ l'' &= -({k'}_r l+ k_r l')\tan(\theta_x - \theta_r) + \frac{1 - k_r l}{\cos^2(\theta_x - \theta_r)}\left(\frac{1 - k_r l} {\cos(\theta_x - \theta_r)}k_x - k_r \right), \\ \end{align*} ss˙s¨ll′l′′=sr,=1−krlvxcos(θx−θr),=1−krlaxcos(θx−θr)−s˙2(l′(kxcos(θx−θr)1−krl−kr)−(kr′l+krl′)),=sign((xx−xr)cos(θr)(yx−yr)sin(θr))((x−xr)2+(y−yr)2)2−1,=(1−krl)tan(θx−θr),=−(k′rl+krl′)tan(θx−θr)+cos2(θx−θr)1−krl(cos(θx−θr)1−krlkx−kr),
Frenet to Cartesian
The transformation equations from Frenet to Cartesian coordinates are as follows:
x x = x r − l sin ( θ r ) , y x = y r + l cos ( θ r ) , θ x = arctan ( l ′ 1 − k r l ) + θ r , v x = [ s ˙ ( 1 − k r l ) 2 + ( s ˙ l ′ ) 2 ] , a x = s ¨ 1 − k r l cos ( θ x − θ r ) + s ˙ 2 cos ( θ x − θ r ) ( l ′ ( k x 1 − k r l cos ( θ x − θ r ) − k r ) − ( k r ′ l + k r l ′ ) ) , k x = ( ( l ′ ′ + ( k r ′ l + k r l ′ ) tan ( θ x − θ r ) ) cos 2 ( θ x − θ r ) ( 1 − k r l ) + k r ) cos ( θ x − θ r ) 1 − k r l , \begin{align*} x_x &= x_r - l \sin(\theta_r), \\ y_x &= y_r + l \cos(\theta_r), \\ \theta_x &= \arctan\left(\frac{l'}{1 - k_r l}\right) + \theta_r, \\ v_x &= \sqrt{[\dot s(1 - k_r l)^2 + (\dot sl')^2]}, \\ a_x &= \ddot s\frac{1 - k_r l}{\cos(\theta_x - \theta_r)} + \frac{\dot s^2}{{\cos(\theta_x - \theta_r)}} \left(l' (k_x \frac{1 - k_r l}{\cos(\theta_x - \theta_r)}-k_r) - (k_r' l + k_r l')\right), \\ k_x &= \left((l'' + (k'_r l + k_r l') \tan(\theta_x - \theta_r))\frac{\cos^2(\theta_x - \theta_r)}{(1 - k_r l)} + k_r \right)\frac{ \cos(\theta_x - \theta_r)}{1 - k_r l}, \end{align*} xxyxθxvxaxkx=xr−lsin(θr),=yr+lcos(θr),=arctan(1−krll′)+θr,=[s˙(1−krl)2+(s˙l′)2],=s¨cos(θx−θr)1−krl+cos(θx−θr)s˙2(l′(kxcos(θx−θr)1−krl−kr)−(kr′l+krl′)),=((l′′+(kr′l+krl′)tan(θx−θr))(1−krl)cos2(θx−θr)+kr)1−krlcos(θx−θr),
Lattice planner sampling(2)
Lattice规划器的轨迹采样,主要分为横向采样、纵向采样以及轨迹时间周期采样。 横向轨迹的采样需要涵盖多种横向运动状态,需要根据车道宽度设置横向采样的采样区间,通过横向采样间隔,形成不同的横向采样偏移量。纵向采样的采样区间可以通过前瞻点的位移长度s,作为基准采样长度,然后通过对轨迹速度ds进行采样。时间周期采样,就是对轨迹的运行周期时间进行采样。
而百度Apollo的轨迹采样,只对横向位移和纵向位移进行了采样,并设计了采样状态横向偏移量,-0.5,0.0和0.5,以及四个到达这些横向偏移量的纵向位移,分别为10,20,40,80来得到采样状态。所以Lattice规划器的轨迹采样主要是对轨迹横纵向状态进行采样,但采样方式可以根据环境情况进行调整。
speed planning(3)
有了前面的采样状态,现在需要做的是根据采样状态生成横向和纵向和规划函数.
两种规划函数都是通过多项式进行拟合求解生成。主要使用了4次和5次多項式拟合,从而满足了车辆运行过程中的一阶导,二阶导联系,也就是速度和加速度连续,保证了轨迹的平滑性要求。
longitudinal planning function 𝑠(𝑡)
在停车和跟车状态,都是五次多项式,但对于巡航状态,由于我们不需要确定状态的S值,所以只有五个变量,因此用四次多项式就可以了。
In stop and go, or spacing control (5th order)
The equations are given by:
- Position (s):
s ( t ) = c 1 t 5 + c 2 t 4 + c 3 t 3 + c 4 t 2 + c 5 t + c 6 s(t) = c_1 t^5 + c_2 t^4 + c_3 t^3 + c_4 t^2 + c_5 t + c_6 s(t)=c1t5+c2t4+c3t3+c4t2+c5t+c6 - Velocity (v):
v ( t ) = 5 c 1 t 4 + 4 c 2 t 3 + 3 c 3 t 2 + 2 c 4 t + c 5 v(t) = 5c_1 t^4 + 4c_2 t^3 + 3c_3 t^2 + 2c_4 t + c_5 v(t)=5c1t4+4c2t3+3c3t2+2c4t+c5 - Acceleration (a):
a ( t ) = 20 c 1 t 3 + 12 c 2 t 2 + 6 c 3 t + 2 c 4 a(t) = 20c_1 t^3 + 12c_2 t^2 + 6c_3 t + 2c_4 a(t)=20c1t3+12c2t2+6c3t+2c4
解方程组,即可得到多项式系数 。
In cruise control (4th order)
The equations are outlined as:
- Position (s):
s ( t ) = b 1 t 4 + b 2 t 3 + b 3 t 2 + b 4 t + b 5 s(t) = b_1 t^4 + b_2 t^3 + b_3 t^2 + b_4 t + b_5 s(t)=b1t4+b2t3+b3t2+b4t+b5 - Velocity (v):
v ( t ) = 4 b 1 t 3 + 3 b 2 t 2 + 2 b 3 t + b 4 v(t) = 4b_1 t^3 + 3b_2 t^2 + 2b_3 t + b_4 v(t)=4b1t3+3b2t2+2b3t+b4 - Acceleration (a):
a ( t ) = 12 b 1 t 2 + 6 b 2 t + 2 b 3 a(t) = 12b_1 t^2 + 6b_2 t + 2b_3 a(t)=12b1t2+6b2t+2b3
解方程组,即可得到多项式系数 。
lateral planning function 𝑙(𝑠)
对于横向轨迹也使用了五次多项式拟合。
lateral planning function 𝑙(𝑠)
Lateral fitting polynomial solution
The polynomial equations are:
-
Lateral displacement ( d(s) ):
d ( s ) = k 1 s 5 + k 2 s 4 + k 3 s 3 + k 4 s 2 + k 5 s + k 6 d(s) = k_1 s^5 + k_2 s^4 + k_3 s^3 + k_4 s^2 + k_5 s + k_6 d(s)=k1s5+k2s4+k3s3+k4s2+k5s+k6 -
Lateral velocity ( d_v(t) ):
d v ( t ) = 5 k 1 s 4 + 4 k 2 s 3 + 3 k 3 s 2 + 2 k 4 s + k 5 d_v(t) = 5k_1 s^4 + 4k_2 s^3 + 3k_3 s^2 + 2k_4 s + k_5 dv(t)=5k1s4+4k2s3+3k3s2+2k4s+k5 -
Lateral acceleration ( d_a(t) ):
d a ( t ) = 20 k 1 s 3 + 12 k 2 s 2 + 6 k 3 s + 2 k 4 d_a(t) = 20k_1 s^3 + 12k_2 s^2 + 6k_3 s + 2k_4 da(t)=20k1s3+12k2s2+6k3s+2k4
Constraint function
The polynomial constraint functions are defined as:
-
For ( s = s_0 ) (initial condition):
d ( s 0 ) = k 1 s 0 5 + k 2 s 0 4 + k 3 s 0 3 + k 4 s 0 2 + k 5 s 0 + k 6 = d 0 d(s_0) = k_1 s_0^5 + k_2 s_0^4 + k_3 s_0^3 + k_4 s_0^2 + k_5 s_0 + k_6 = d_0 d(s0)=k1s05+k2s04+k3s03+k4s02+k5s0+k6=d0
d v ( s 0 ) = 5 k 1 s 0 4 + 4 k 2 s 0 3 + 3 k 3 s 0 2 + 2 k 4 s 0 + k 5 = s d 0 d_v(s_0) = 5k_1 s_0^4 + 4k_2 s_0^3 + 3k_3 s_0^2 + 2k_4 s_0 + k_5 = sd_0 dv(s0)=5k1s04+4k2s03+3k3s02+2k4s0+k5=sd0
d a ( s 0 ) = 20 k 1 s 0 3 + 12 k 2 s 0 2 + 6 k 3 s 0 + 2 k 4 = s s d 0 d_a(s_0) = 20k_1 s_0^3 + 12k_2 s_0^2 + 6k_3 s_0 + 2k_4 = ssd_0 da(s0)=20k1s03+12k2s02+6k3s0+2k4=ssd0 -
For ( s = s_1 ) (sampled condition):
d ( s 1 ) = k 1 s 1 5 + k 2 s 1 4 + k 3 s 1 3 + k 4 s 1 2 + k 5 s 1 + k 6 = d 1 d(s_1) = k_1 s_1^5 + k_2 s_1^4 + k_3 s_1^3 + k_4 s_1^2 + k_5 s_1 + k_6 = d_1 d(s1)=k1s15+k2s14+k3s13+k4s12+k5s1+k6=d1
d v ( s 1 ) = 5 k 1 s 1 4 + 4 k 2 s 1 3 + 3 k 3 s 1 2 + 2 k 4 s 1 + k 5 = s d 1 d_v(s_1) = 5k_1 s_1^4 + 4k_2 s_1^3 + 3k_3 s_1^2 + 2k_4 s_1 + k_5 = sd_1 dv(s1)=5k1s14+4k2s13+3k3s12+2k4s1+k5=sd1
d a ( s 1 ) = 20 k 1 s 1 3 + 12 k 2 s 1 2 + 6 k 3 s 1 + 2 k 4 = s s d 1 d_a(s_1) = 20k_1 s_1^3 + 12k_2 s_1^2 + 6k_3 s_1 + 2k_4 = ssd_1 da(s1)=20k1s13+12k2s12+6k3s1+2k4=ssd1 -
d_0
: initial lateral displacement -
sd_0
: initial lateral speed -
ssd_0
: initial lateral acceleration -
d_1
: sampled lateral displacement -
sd_1
: sampled lateral speed -
ssd_1
: sampled lateral acceleration
知道了位姿点在frenet坐标系和cartesian坐标系的相互转换关系,因此现在我们需要做的就是对横纵向轨迹函数s(t)和l(s)进行轨迹的时间细分形成规划函数的横纵向轨迹规划点s(t_i)和l(s(t_i)),该规划点是在frenet坐标系中,因此需要进行frenet坐标系到cartesian坐标系的坐标转换,从而形成控制器可用的采样轨迹。
Constraint evaluation
For every trajectory generated, it needs to be evaluated to check if it violates any constraint and remove it if it does.
- 开始轨迹评估:初始化轨迹评估过程。
- 对每条轨迹进行约束评估:按序对每条轨迹进行检查。
- 对每个样本进行约束评估:在每条轨迹中,逐个检查每个样本点是否符合速度、加速度和急动度的限制。
- 如果样本点不符合约束,移除整条轨迹,回到第2步,检查下一条轨迹。如果样本点符合约束,继续检查轨迹的下一个样本。
- 完成所有样本的检查:对一条轨迹的所有样本完成约束检查。
- 完成所有轨迹的检查:当一条轨迹的所有样本点都符合约束条件后,继续进行下一条轨迹的评估,直到所有轨迹都被检查。
trajectory cost function(6)
Objective: to choose a feasible path that is nearest to the static reference path, and at the same time, avoid large speed change to ensure comfortability and stay away from obstacles.(满足车辆的运动学控制要求,速度尽量不发生大突变,满足舒适性要求,且尽量远离障碍物和无碰撞要求)
The cost function J is defined as:
J = k l o n g i × J l o n g i + k c o m f o r t × J c o m f o r t + k c o l l i s i o n × J c o l l i s i o n J = k_{longi} \times J_{longi} + k_{comfort} \times J_{comfort} + k_{collision} \times J_{collision} J=klongi×Jlongi+kcomfort×Jcomfort+kcollision×Jcollision
- tracking cost, considering speed error, distance to travel.
- comfort cost, considering longitudinal jerk(有的考虑横向向误差,综合考虑了横向加速度误差及横向偏移误差的影响。)
- cost of collision to the near objects.
选择出代价值最好的一条轨迹输入到控制器,用于控制器的跟踪控制。
Longitudinal Objective achievement cost
to choose a feasible path that is nearest to the static reference path.(有停车指令时,高速cost会很大,相反,低速cost会很大通过V_ref)
Comfort Objective:
to choose a feasible path that is having less jerk
Centripetal Objective:
to choose a feasible path that is having less less centripetal accel jerk.
Collision Objective:
to choose a path that is furthest from obstacles
Lateral offset Objective:
to choose a feasible path that is more close to the reference (center line)
Lateral Acceleration Objective:
to choose a feasible path that is having smoother lane change
最后选择出代价值最好的一条轨迹输入到控制器,用于控制器的跟踪控制。