MPC功能包梳理

1 MPC 节点 输入输出接口

MPC节点接收的参数参数的物理含义
vector <double> ptsx全局路径 x
vector <double> ptsy全局路径 y
double px当前x坐标
double py当前y坐标
double psi当前航向角
double v当前车辆速度
double delta当前方向盘转角
double a当前节气门开度
MPC节点输出的参数参数的物理含义

2. 车辆模型 (约束条件)(状态方程)

考虑道路曲率变化的车辆运动学模型

x t + 1 = x t + v t c o s ( ψ t ) ∗ d t y t + 1 = y t + v t s i n ( ψ t ) ∗ d t ψ t + 1 = ψ t + v t L f δ t ∗ d t v t + 1 = v t + a t ∗ d t v c t e t + 1 = f ( x t ) − y t + ( v t s i n ( e ψ t ) d t ) c t e e ψ t + 1 = ψ t − ψ d e s t + ( v t L f δ t d t ) where: ψ d e s t = arctan ⁡ [ f ′ ( x t ) ] x_{t+1} = x_t + v_t cos(\psi_t) * dt \\ y_{t+1} = y_t + v_t sin(\psi_t) * dt \\ \psi_{t+1} = \psi_t + \frac {v_t} { L_f} \delta_t * dt \\ v_{t+1} = v_t + a_t * dtv \\ cte_{t+1} = f(x_t) - y_t + (v_t sin(e\psi_t) dt)cte \\ e\psi_{t+1} = \psi_t - \psi{des}_t + (\frac{v_t} { L_f} \delta_t dt)\\ \text{where:}\psi{des}_t=\arctan\left[f'\left(x_{t}\right)\right] xt+1=xt+vtcos(ψt)dtyt+1=yt+vtsin(ψt)dtψt+1=ψt+Lfvtδtdtvt+1=vt+atdtvctet+1=f(xt)yt+(vtsin(eψt)dt)cteeψt+1=ψtψdest+(Lfvtδtdt)where:ψdest=arctan[f(xt)]

状态变量:
[ x y ψ v c t e e ψ ] \begin{bmatrix} x\\ y\\ \psi\\ v\\ cte\\ e\psi \end{bmatrix} xyψvcteeψ

输入变量:

[ δ a ] \begin{bmatrix} \delta\\ a \end{bmatrix} [δa]

3. MPC 控制器使用说明

  • MPC控制模块的参考轨迹是用xy坐标系下的多项式系数表达的。
    • polyfit函数可以使用(x,y)点集进行拟合得到。
    • polyeval函数,根据x坐标和多项式系数,拟合出y坐标
  • 实车无法获取节气门开度,因此使用车辆加速度作为节气门开度

4. Ipopt优化求解器构造

4.1 求解器标准形式

m i n x ∈ R n f ( x ) s . t . g L ≤ g ( x ) ≤ g U x L ≤ x ≤ x U \underset {x ∈ R^n}{min}f(x)\\ s.t. g_L ≤ g(x) ≤ g_U\\ x_L ≤ x ≤ x_U xRnminf(x)s.t.gLg(x)gUxLxxU
where f(x): Rⁿ --> R is the objective function, and g(x): Rⁿ --> Rᵐ are the constraint functions. The vectors g_L and g_U denote the lower and upper bounds on the constraints, and the vectors x_L and x_U are the bounds on the variables x. The functions f(x) and g(x) can be nonlinear and nonconvex, but should be twice continuously differentiable. Note that equality constraints can be formulated in the above formulation by setting the corresponding components of g_L and g_U to the same value.
优化器每次求解完成得到的结果是控制时域内的所有状态变量的值以及控制量的值

4.2 cost function里的项

  • cross track error
  • headin error
  • velocity error
  • 控制信号幅值
  • 控制信号变化率

4.3 约束条件 void operator()(ADvector& fg, const ADvector& vars)

fg:存放目标函数和车辆模型/约束条件(车辆模型是动态规划的等式约束条件)
fg[0] 存放,目标函数,将目标函数的各个组成部分加起来,然后存在这里:cross_error heading_error, velocity_error

车辆模型:
f(x(t))是参考路径
x t + 1 = x t + v t c o s ( ψ t ) ∗ d t y t + 1 = y t + v t s i n ( ψ t ) ∗ d t ψ t + 1 = ψ t + v t L f δ t ∗ d t v t + 1 = v t + a t ∗ d t c t e t + 1 = f ( x t ) − y t + ( v t s i n ( e ψ t ) d t ) e ψ t + 1 = ψ t − ψ d e s t + ( v t L f δ t d t ) x_{t+1} = x_t + v_t cos(\psi_t) * dt\\ y_{t+1} = y_t + v_t sin(\psi_t) * dt\\ \psi_{t+1} = \psi_t + \frac {v_t} { L_f} \delta_t * dt\\ v_{t+1} = v_t + a_t * dt\\ cte_{t+1} = f(x_t) - y_t + (v_t sin(e\psi_t) dt)\\ e\psi_{t+1} = \psi_t - \psi{des}_t + (\frac{v_t} { L_f} \delta_t dt) xt+1=xt+vtcos(ψt)dtyt+1=yt+vtsin(ψt)dtψt+1=ψt+Lfvtδtdtvt+1=vt+atdtctet+1=f(xt)yt+(vtsin(eψt)dt)eψt+1=ψtψdest+(Lfvtδtdt)

vars:存放目标函数和模型需要用到的参数
[ x , y , ψ , v , c t e , e ψ ] [x, y, \psi, v, cte, e\psi] [x,y,ψ,v,cte,eψ]
[ δ , a ] [\delta, a] [δ,a]
vars 是一个长的一维向量,当N的值为25的时候,
v a r s [ 0 ] , . . . , v a r s [ 24 ] ⟶ x 1 , . . . , x 25 ​ v a r s [ 25 ] , . . . , v a r s [ 49 ] ⟶ y 1 , . . . , y 25 ​ v a r s [ 50 ] , . . . , v a r s [ 74 ] ⟶ ψ 1 , . . . , ψ 25 ​ v a r s [ 75 ] , . . . , v a r s [ 99 ] ⟶ v 1 , . . . , v 25 v a r s [ 100 ] , . . . , v a r s [ 124 ] ⟶ c t e 1 , . . . , c t e 25 ​ v a r s [ 125 ] , . . . , v a r s [ 149 ] ⟶ e ψ 1 , . . . , e ψ 25 v a r s [ 150 ] , . . . , v a r s [ 173 ] ⟶ δ 1 , . . . , δ 24 ​ v a r s [ 174 ] , . . . , v a r s [ 197 ] ⟶ a 1 , . . . , a 24 {vars[0], ..., vars[24] \longrightarrow x_1, ..., x_{25}}\\ ​vars[25], ..., vars[49] \longrightarrow y_1, ..., y_{25}\\ ​vars[50], ..., vars[74] \longrightarrow \psi_1, ..., \psi_{25}\\ ​vars[75], ..., vars[99] \longrightarrow v_1, ..., v_{25}\\ vars[100], ..., vars[124] \longrightarrow cte_1, ..., cte_{25}\\ ​vars[125], ..., vars[149] \longrightarrow e\psi_1, ..., e\psi_{25}\\ vars[150], ..., vars[173] \longrightarrow \delta_1, ..., \delta_{24}\\ ​vars[174], ..., vars[197] \longrightarrow a_1, ..., a_{24}\\ vars[0],...,vars[24]x1,...,x25vars[25],...,vars[49]y1,...,y25vars[50],...,vars[74]ψ1,...,ψ25vars[75],...,vars[99]v1,...,v25vars[100],...,vars[124]cte1,...,cte25vars[125],...,vars[149]eψ1,...,eψ25vars[150],...,vars[173]δ1,...,δ24vars[174],...,vars[197]a1,...,a24

目标函数

 // The part of the cost based on the reference state.
 // minimize our cross track, heading, and velocity errors
    for (int t = 0; t < N; t++) {
      fg[0] += CppAD::pow(vars[cte_start + t], 2);
      fg[0] += CppAD::pow(vars[epsi_start + t], 2);
      fg[0] += CppAD::pow(vars[v_start + t] - ref_v, 2);
    }

    // Minimize the use of actuators.
    // A further enhancement is to constrain erratic control inputs.
    //For example, if we're making a turn, we'd like the turn to be smooth, not sharp. Additionally, the vehicle velocity should not change too radically
    for (int t = 0; t < N - 1; t++) {
      fg[0] += CppAD::pow(vars[delta_start + t], 2);
      fg[0] += CppAD::pow(vars[a_start + t], 2);
    }

    // Minimize the value gap between sequential actuations.
    // The goal of this final loop is to make control decisions more consistent, or smoother. The next control input should be similar to the current one.
    for (int t = 0; t < N - 2; t++) {
      fg[0] += CppAD::pow(vars[delta_start + t + 1] - vars[delta_start + t], 2);
      fg[0] += CppAD::pow(vars[a_start + t + 1] - vars[a_start + t], 2);
    }

MPC 参数标定流程

车辆航向角与横摆角以及质心侧偏角的关系

车辆航向角: 地面坐标系下,车辆质心速度与横轴的夹角
车辆质心侧偏角:车辆质心速度方向与车头指向的夹角
车辆横摆角 = 航向角 - 质心侧偏角
如下图: θ \theta θ是航向角; β \beta β是质心侧偏角; ϕ \phi ϕ是横摆角
θ = β + ϕ \theta=\beta+\phi θ=β+ϕ
在这里插入图片描述

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值