## 2 Materials and Methods
### Navigation Decision Module Design
#### 2.3.3. Deviation Calculation Based on Dynamic Path Search  
The driving trajectory of a tractor in a field is generally composed of straight-line segments and curved segments; sometimes, obstacle avoidance is also required. A unified waypoint search framework was developed in this work, determining a deviation calculation for different path segments. As shown in Figure 8a, the straight-line and curved segments are connected by discrete waypoints \(R_{i}\), and each waypoint has its allowable deviation limitation, i.e., \(\epsilon\) and \(\sigma\) for straight-line and curved paths, respectively. The current reference waypoint \(\overline{R}_{k}\) is queried in the current segment index vector, and \(d_{e}\) is the shortest distance between the current tractor position and its predefined path. The path planning is performed in the \(g\)-frame. The geometric center of the vehicle body in the \(g\)-frame is \(P_{k}\big{(}x_{g},y_{g}\big{)}\), which was transformed using Equation (3). \begin{table}
\begin{tabular}{c c c} \hline \hline
**Path Segment** & **Operation** & **Speed** \\ \hline Straight Line & Tool Drop & High Speed \\ Headland Turning & Tool Lift & Low Speed \\ Headland Straight Transition & Tool Lift & High Speed \\ Working Interruption/Termination & Tool Lift & Idle Speed \\ Anomaly & Remote Emergency Stop & Engine Shutdown \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Path-planning scheme for whole-field coverage. Figure 7: Path-planning module design. (**a**) Field path planning; (**b**) headland turning path generation. Suppose that, at time \(k\), the reference waypoint is \(\overline{R}_{k}\big{(}x_{R_{k}},y_{R_{k}}\big{)}\) and the heading deviation \(\psi_{e}\) is the difference between the current heading angle of the tractor and the heading angle of the planned path. \(D_{i}\) is the projection of the vehicle geometric center onto the path segment. The heading information of the reference waypoint, denoted as \(\varphi_{r}\), can be calculated as follows:  
\[\psi_{r}=\arctan\left(\frac{y_{R_{k}}-y_{R_{k-1}}}{x_{R_{k}}-x_{R_{k-1}}}\right) \tag{5}\]  
The heading \(\psi\) of the tractor at time \(k\) is provided by the dual-antenna RTK-GNSS system. Therefore, the heading deviation of the tractor is expressed as follows:  
\[\psi_{e}=\psi-\psi_{r} \tag{6}\]  
The lateral deviation \(d_{e}\) is calculated by using the distance calculation for point \(P_{k}\) to the straight line \(R_{k}R_{k+1}\), which can be written as follows:  
\[d_{e}=\frac{\left|Ax_{g}+By_{g}+C\right|}{\sqrt{A^{2}+B^{2}}} \tag{7}\]  
where \(A=y_{R_{k+1}}-y_{R_{k}}\), \(B=x_{R_{k}}-x_{R_{k+1}}\), and \(C=x_{R_{k+1}}y_{R_{k}}-x_{R_{k}}y_{R_{k+1}}\). To further refine the calculation of \(d_{e}\), we need to determine onto which line segment point \(D_{i}\) is projected, using a vector product form as follows:  
\[S=\left(\overline{R_{k-1}R_{k}^{\prime}}\cdot\overline{R_{k-1}P_{i}}\right) \left(\overline{R_{k-1}R_{k}^{\prime}}\cdot\overline{R_{k}D_{i}^{\prime}}\right) \tag{8}\]  
If \(S>0\), then \(D_{i}\) belongs to line segment \(R_{k}R_{k+1}\); otherwise, it is on line segment \(R_{k-1}\)\(R_{k}\). The sign of lateral deviation \(d_{e}\) is defined following [27], and we define the lateral deviation as positive if \(P_{k}\) is on the left side of the predefined line segment. Let the window length be \(L\). The flowchart of dynamic path search is shown in Figure 8b. Suppose that the tractor is located at \(P_{k-1}\) at time \(k-1\). If \(d_{e}<\varsigma\), then \(\overline{R}_{k}=\overline{R}_{k}+1\); otherwise, if \(d_{e}>\varsigma\), e.g., at time \(k\), then the distances of the adjacent tractor positions are determined with respect to \(\overline{R}_{k}\). If \(|P_{k-1}R_{i}|<|P_{k}R_{i}|\), then \(\overline{R}_{k}=\overline{R}_{k}+1\); otherwise, if \(d_{e}>\varsigma\) and \(|P_{k-1}R_{i}|>|P_{k}R_{i}|\), then we compare \(|P_{k}R_{i}|\) with \(|P_{k}R_{i+1}|\). If \(|P_{k}R_{i+1}|<|P_{k}R_{i}|\), then \(\overline{R}_{k}=\overline{R}_{k}+1\); otherwise, the reference waypoint is unchanged.