# A Trajectory Generation Method for Multi-Rotor UAV Based on Adaptive Adjustment Strategy
## 3 Method
### Definition of Optimization Function and Adaptive Adjustment Method
#### 3.2.1 Optimization Function Definition  
The trajectory of multi-rotor UAVs must have simultaneously the characteristics of safety, dynamic feasibility, and smoothness, so this paper defines the loss function of comprehensive safety, smoothness, and dynamic feasibility. The definition of the loss function is shown in Formula (15), which is determined by the safety loss \(f_{c}\), smoothness loss \(f_{s}\), and dynamic feasibility loss \(f_{t,v}\), \(f_{t,a}\). \[f_{sum}=\lambda_{1}\ f_{c}+\lambda_{2}\ f_{s}+\lambda_{3}\ (f_{t,v}+f_{t,a}) \tag{15}\]  
where \(f_{c}\) and \(f_{s}\) are smoothness and collision cost; \(f_{t,v}\) and \(f_{t,a}\) are soft limits on velocity and acceleration; and \(\lambda_{1}\), \(\lambda_{2}\) and \(\lambda_{3}\) trade off the smoothness, safety, and dynamic feasibility. The trajectory safety loss is to make the distance between the trajectory control point and the obstacle meet the trajectory safety condition of Formula (14). In order to ensure trajectory safety, it is necessary to make the control point meet \(d(Q)\geq e_{max}+0.5l\), where \(l\) is the distance between adjacent control points. Considering the control error of a multi-rotor UAV, set the safety distance to \(d_{thr}=e_{max}+0.5l+0.1\). Therefore, the goal of the trajectory  
Figure 2: The red line is a b-spline curve. The green dash line is the line connecting two control points. \(P\) is an arbitrary point on the B-spline curve. B and C are the control points of the B-spline. \(P^{\prime}\) is the corresponding point of \(P\) point on the control polygon. The distance between \(P\) point and the obstacle is recorded as \(d(P)\). The distance between \(P^{\prime}\) and the obstacle is recorded as \(d(P^{\prime})\), and the distance between \(P\) and \(P^{\prime}\) is recorded as \(d(P,P^{\prime})\). \(d(C)\) is the distance between the control point \(C\) and the obstacle. safety loss function \(f\) is to make control point \(\mathbf{Q}_{i}\) satisfy \(d(\mathbf{Q}_{i})\geq d_{thr}\). For control point \(\mathbf{Q}_{i}\), its safety loss is defined as  
\[F_{c}(\mathbf{Q}_{i})=\left\{ \begin{array}{cc}(d(\mathbf{Q}_{i})-d_{thr})^{2}&d(Q_{i}) \leq d_{thr}\\ 0&d(Q_{i})>d_{thr}\end{array} \right. \tag{16}\]  
The trajectory safety loss function is the sum of safety loss for all the control points:  
\[f_{c}=\sum_{i=0}^{N}F_{c}(\mathbf{Q}_{i}) \tag{17}\]  
The second term of the loss function is smooth loss. In this paper, the trajectory acceleration is taken as the evaluation index of the trajectory smoothing term. According to Formula (7), the size of the acceleration control point is proportional to the second derivative of the position control point, so this paper uses the square of the second derivative of the position control point to represent the smoothness of the trajectory, which is defined as Formula (18). \[f_{s}=\sum_{i=0}^{N-2}\|\mathbf{Q}_{i}+\mathbf{Q}_{i+2}-2\mathbf{Q}_{i+1}\|^{2} \tag{18}\]  
where \(\mathbf{Q}_{i}\), \(\mathbf{Q}_{i+1}\) and \(\mathbf{Q}_{i+2}\) are the control points of the B-Spline. The last item is the flight-time loss of the trajectory. In order to ensure that the trajectory meets the dynamic feasibility, the speed control point and the acceleration control point cannot exceed the maximum speed and acceleration, that is:  
\[v_{i}=\left|\frac{p_{b}(\mathbf{Q}_{i+1}-\mathbf{Q}_{i})}{t_{i+p_{b}+1}-t_{i+1}}\right| \leq v_{max} \tag{19}\]  
Thus,  
\[t_{i+p_{b}+1}-t_{i+1}\geq\left|\frac{p_{b}(\mathbf{Q}_{i+1}-\mathbf{Q}_{i})}{v_{max}}\right| \tag{20}\]  
That is, the time interval between \(t_{i+1}\) and \(t_{i+p_{b}+1}\) is proportional to \(|\mathbf{Q}_{i+1}-\mathbf{Q}_{i}|\).