## 3 Adaptive Cruise Controller Design
### MPC Controller Design
#### 3.1.2 Definition of Cost Function  
Personnel safety is the most important part of the driving process of the vehicle. The main vehicle and the vehicle in front should always maintain a safe distance, that is, it must be ensured that \(x_{rel}>d_{0}\) is always established.  
The tracking performance is mainly reflected in the relative distance and relative speed of the two vehicles while driving. In order to improve the tracking performance of the vehicle while driving, the cost function of tracking performance was defined:  
\[J_{tracking}=\sum\limits_{i=1}^{N}\left[\left(x_{rel}(k+i)-x_{ref}(k+i)\right)^ {2}+\left(v_{rel}(k+i)-v_{ref}(k+i)\right)^{2}\right] \tag{19}\]  
Comfort is mainly a reflection of the impact on passengers when the vehicle accelerates or brakes. In order to improve the riding comfort of passengers, the cost function of comfort was defined and constraints were set with the goal of reducing acceleration and jerk during driving:  
\[J_{comfort}=\sum\limits_{i=1}^{N}\left[a^{2}(k+i)+\hat{f}^{2}(k+i)\right] \tag{20}\]  
\[\left\{\begin{array}{l}a_{\min}<a(k)<a_{\max}\\ j_{\min}<j(k)<j_{\max}\end{array}\right.\]  
The decay characteristic of the battery is reflected in the reduction in available capacity. The \(Q_{loss}\) described above can objectively evaluate the decay of the battery, and define the cost function:  
\[J_{loss}=\sum\limits_{i=1}^{N}Q_{loss}(i) \tag{21}\]  
Combining the above cost functions, the cost function of the entire control process was obtained:  
\[J=\omega_{1}\cdot J_{tracking}+\omega_{2}\cdot J_{comfort}+\omega_{3}\cdot J_ {loss} \tag{22}\]  
where \(\omega_{1}\), \(\omega_{2}\), \(\omega_{3}\) represent the weights of tracking, comfort, and battery capacity degradation characteristics, respectively.  
In order to improve computational efficiency, we simplified the cost function. First of all, we took \(J_{1}=\omega_{1}\cdot J_{\text{tracking}}+\omega_{2}\cdot J_{\text{comfort}}\), and arrived at \(J_{1}=\sum\limits_{i=1}^{N}\left[Y(k+i)-Y_{ref}(k+i)\right]^{\text{T}}\), \(Q\left[Y(k+i)-Y_{ref}(k+i)\right]\), so \(J_{1}=(Y_{k}-Y_{ref})^{\text{T}}Q(Y_{k}-Y_{ref})\), where \(Q\) is the weight matrix. \(Y_{ref}=[x_{des},\,0,\,0,\,0]^{\text{T}}\) indicates that the expected value of the relative distance is the expected distance and the relative speed, and the absolute value of the acceleration of the main vehicle and the shock degree during the driving process are at their smallest. We took \(L_{1}\cdot x(k)+L3\cdot a_{lk}=E\) and combined Formula (18) to arrive at \(Y_{k}-Y_{ref}=E+L_{2}\cdot U_{k}-Y_{ref}\), so \(J_{1}\) can be transformed into Formula (23):  
\[\begin{array}{c}J_{1}=\left(E+L_{2}U_{k}-Y_{ref}\right)^{\text{T}}Q\left(E+L _{2}U_{k}-Y_{ref}\right)=E^{\text{T}}QE+2E^{\text{T}}QL_{2}U_{k}\\ \qquad\qquad-2E^{\text{T}}QY_{ref}-2Y_{ref}{}^{\text{T}}QL_{2}U_{k}+U_{k}{}^{ \text{T}}L_{2}{}^{\text{T}}QL_{2}U_{k}+Y_{ref}{}^{\text{T}}QY_{ref}\end{array} \tag{23}\]  
By eliminating polynomials that have no effect on the control outcome, a new cost function \(J_{1}{}^{*}\) for integrated tracking and comfort can be obtained, as shown in Formula (24):  
\[J_{1}^{*}=2\left(E^{\text{T}}QL_{2}-Y_{ref}{}^{\text{T}}QL_{2}\right)U_{k}+U_{ k}{}^{\text{T}}L_{2}{}^{\text{T}}QL_{2}U_{k} \tag{24}\]  
When setting weights in traditional MPC controllers, the cost function is often designed with fixed weights which cannot consider the performance requirements of the vehicle under different driving conditions. Therefore, this study designed a variable weight cost function.