# A Frame-to-Frame Scan Matching Algorithm for 2D Lidar Based on Attention
## 3 Attention Area Selection Module
### Reference Frame Attention Area Selection  
In the reference frame, attention area selection is equivalent to a human selecting a landmark when he or she is walking. Once a landmark is selected, no errors can be accumulated until the landmark completely disappears. Therefore, landmark selection greatly  
Figure 1: System overview. impacts the matching results. When conducting multiple experiments, it is understood that better performance is achieved when the following three conditions of the attention area are satisfied:  
1. The attention area must be away far enough from the original pose of the reference frame. 2. The selected attention area must ensure that there is enough information that can be obtained from the pose of the current frame. 3. There must be a sufficient number of laser points in the selected attention area. The distance in condition (1) can be considered as the drift-free running distance of the ASM algorithm. Obviously, when the other two conditions are met, the longer the distance, and the higher the scan matching accuracy. Since 2D laser data has angle constraints naturally, the constraint in condition (2) refers to the translation constraint in the \(X\)-axis direction and the \(Y\)-axis direction, and the selected attention area must provide sufficient constraints in both the \(X\)-axis and \(Y\)-axis directions. Condition (3) ensures the stability of the solution through the use of enough laser points. This is because when the number of laser points is too small, then the solution that is obtained is unstable even if there are sufficient constraints. Obviously, condition (3) is easy to implement, and it only requires the number of lidar points in the attention area to be counted. However, condition (1) can be satisfied by selecting the area the farther away from the areas that meet the condition (2) and condition (3), and condition (2) requires additional processing. When a certain key frame is determined as the reference frame, the normal vector of each lidar point in the reference frame is calculated. For a certain point \(p_{i}\), the surrounding point cloud obeys the Gaussian distribution, and the covariance matrix of the Gaussian distribution is obtained. For 2D data, the covariance matrix is two-dimensional, the eigenvector corresponding to its large eigenvalue represents the direction vector of the point, and the eigenvector corresponding to the smallest eigenvalue represents the normal vector of the point. In order to obtain the normal vector of \(p_{i}\), the covariance matrix of the Gaussian distribution is calculated using Equation (1):  
\[ \begin{split} u_{i}&=\frac{1}{|N_{i}|}\sum\limits_ {p_{j}\in N_{i}}p_{j}\\ \Sigma_{i}&=\frac{1}{|N_{i}|}\sum\limits_{p_{j}\in N _{i}}(p_{j}-u_{i})^{T}(p_{j}-u_{i}),\end{split}  \tag{1}\]  
where \(u_{i}\) represents the mean value of the Gaussian distribution. \(\sum_{i}\) represents the covariance matrix of the Gaussian distribution, and \(N_{i}\) represents the set of points near \(p_{i}\). The calculation of the normal vector requires the covariance matrix to perform eigenvalue decomposition:  
\[\Sigma_{i}=\left[ \begin{array}{cc}v_{1}&v_{2}\end{array} \right]\left[ \begin{array}{cc}\lambda_{1}&0\\ 0&\lambda_{2}\end{array} \right]\left[ \begin{array}{c}v_{1}^{T}\\ v_{2}^{T}\end{array} \right], \tag{2}\]  
where \(\lambda_{1}\) and \(\lambda_{2}\) represent the eigenvalues of the covariance matrix to be \(\lambda_{1}>\lambda_{2}\). \(v_{1}\) and \(v_{2}\) are the eigenvectors corresponding to the eigenvalues. Moreover, the normal vector expression of point pi is shown in Equation (3). \[n_{i}=v_{2} \tag{3}\]  
When the normal vector is known, the translation constraint of point \(p_{i}\) in the \(X\)-axis and \(Y\)-axis directions needs to be computed.