# A Driving Behavior Planning and Trajectory Generation Method for Autonomous Electric Bus
## 5 Optimal Trajectory Generation  
The global reference points cannot provide a feasible path for a bus to follow since they are usually sparse and unconstrained. It is proved that the mobile vehicle's trajectory generation from start to end can be solved by using polynomial parameterizations [24]. To balance between computing complexity and constraints, cubic polynomial is applied to generate the optimal trajectory which is smooth and consistent with the bus kinetic constraints. In Figure 8, \(l_{1}\) is the fitted global path based on global reference points, the point \(G(x_{f},y_{f},\theta)\) is a target point that is selected in global reference points to determine the expression of cubic polynomial. \(\theta\) is the global desired heading, \(T\) represents the cubic polynomial curve, \(l_{0}\) is parallel to the X axis. The cubic polynomial can be written as  
\[Y(X)=a_{0}+a_{1}x+a_{2}x^{2}+a_{3}x^{3} \tag{6}\]  
where the coordinate system XOY is fixed with the center of the headstock. In the established coordinate system, the initial position is coordinate origin and initial heading of the bus is zero, that is, the constraints are expressed as  
\[Y(0)=0\]  
Figure 7: Check zone in unstructured driving. (7)  
combined with Equations (6)-(8), we can obtain the constant coefficients in (9). \[a_{0}=a_{1}=0 \tag{9}\]  
To ensure the bus to track the global reference points finally, the trajectory in point \(G\) is tangent to \(l_{1}\).The first derivative of cubic polynomial in the target point \(G(x_{f},y_{f},\theta)\) i.e., the slope of \(l_{1}\). Combined with Equations (6) and (9), the equation is expressed in (10)  
\[ \begin{array}{ll}y^{\prime}(x_{f})&=2a_{2}x_{f}+3a_{3}{x_{f}}^{2}\\ &=\tan\theta\end{array}  \tag{10}\]  
Then, \(y_{offset}\) (the offset of the target point) is written as (11). \[y_{offset}=y_{f}\cos\theta+x_{f}\sin\theta \tag{11}\]  
The target point \((x_{f},y_{f},\theta)\) is also a point on the cubic trajectory, so it satisfies the function  
\[Y_{f}=a_{2}{x_{f}}^{2}+a_{3}x_{f}^{3} \tag{12}\]  
combined with Equations (10)-(14) are obtained as  
\[a_{2}=\frac{3y_{offset}}{{x_{f}}^{2}\cos\theta}-\frac{4\tan\theta}{x_{f}} \tag{13}\]  
\[a_{3}=\frac{3\tan\theta}{{x_{f}}^{2}}-\frac{2y_{offset}}{{x_{f}}^{3}\cos\theta} \tag{14}\]  
Therefore, the cubic polynomial is related to the target point \(G(x_{f},y_{f},\theta)\), that is, different target points determine different trajectories. For instance, when the values of \(x_{f}\) and \(y_{f}\) are fixed but \(\theta\in(0\sim 45^{\circ})\), the trajectory clusters are showed in Figure 9a. Trajectory clusters of different target points are illustrated in Figure 9.  
Figure 8: Trajectory generation. Therefore, an appropriate target point is essential for optimal trajectory. Besides, several constraints should be satisfied. On one hand, the maximum steering angle of the front wheel is limited for bus. The bus can travel through the target point with maximum front wheel angle. According to Figure 10, turning radius R can be written as (15). \[R=d/\sin\delta_{f} \tag{15}\]  
where \(\delta_{f}\) is front wheel angle and d means the wheelbase. For the bus, the range of the front wheel \(Rg\in[\delta_{\text{fmin}},\delta_{\text{fmax}}]\). From (15), the minimum turning radius is obtained by (16). \[R_{\text{min}}=d/\sin\delta_{\text{fmax}} \tag{16}\]  
where \(\delta_{\text{fmax}}\) is the maximum angle of front wheel. On the other hand, the faster of the bus travels, the longer of trajectory should be. In this paper, a piecewise turning radius is defined by the equation  
\[L_{a}= \begin{cases}R_{\text{min}}&v<v_{th}\\ R_{\text{min}}+K_{la}v&v\geq v_{th}\end{cases}  \tag{17}\]  
where \(K_{la}\) is an adjusted coefficient, \(v\) represents the current speed, \(v_{th}\) is a velocity threshold. Hence, the turning radius of a feasible target point is larger than \(L_{a}\). Therefore, the optimal trajectory generation algorithm is described as Algorithm 1. Figure 10: Steering kinematics mode front wheel.