# GNSS Spoofing Identification and Smoothing Localization Method for GNSS/Visual SLAM System
## 3 Time-Localization Verification and Smoothing Localization Method
### Smoothing Localization Method  
In the smoothing localization method, there are mainly two stages: the initialization stage and the stable operation process. In the initialization phase, the external parameters (\(R^{\mathrm{GV}},t^{\mathrm{GV}}\)) of the camera are estimated based on the measurement data of GNSS and visual SLAM system, so that the visual SLAM frame after calibration and the GNSS frame are both in the ENU coordinate system. External parameters are also a prerequisite for the realization of the localization verification process. In the stable operation process, the external parameters need to be continuously updated and optimized based on the verified GNSS data. In this phase, one of two smoothing localization strategies is selected according to the input verification flags. If GNSS spoofing occurs, the spoofed GNSS result will be input into the external parameter optimization process, causing errors in the calculation results of the external parameters and affecting the coordinate conversion results of the visual SLAM data frame. However, we do not know when the GNSS spoofing attack will happen. We assume that no spoofing occurred in the initial phase, and that the spoofing attack occurred only during the stable operation phase. Therefore, we need to initial the external parameters in the initialization stage, providing input for the localization verification. In order to ensure the reliability of the initialization phase, we set a localization verification sliding window (the size of the localization verification window is set to \(h\)) to optimize the external parameters. Suppose that at the current time \(i\), the coordinate vector of the mobile terminal in the ENU coordinate system calculated by the GNSS data frame is \(\chi_{i}^{\text{G}}\), and the coordinate vector of the visual SLAM data frame in the camera body coordinate system is \(\chi_{i}^{\text{V}}\). For the data frames in the localization verification sliding window, the distance errors are minimized according to the Umeyama algorithm [23], and the rotation matrix and translation matrix of GNSS and visual SLAM system are estimated, as shown in the following formula:  
\[\min F(\mathbf{R}_{i}^{\text{GV}},\mathbf{t}_{i}^{\text{GV}})=\left\{ \begin{array}{c} \frac{1}{h}\sum\limits_{j=1}^{i}\left\|\chi_{j}^{\text{G}}-(\mathbf{R}_{i}^{\text{ GV}}\times\mathbf{\chi}_{j}^{\text{V}}+\mathbf{t}_{i}^{\text{GV}})\right\|^{2},i<h\\ \frac{1}{h}\sum\limits_{j=i-h+1}^{i}\left\|\chi_{j}^{\text{G}}-(\mathbf{R}_{i}^{ \text{GV}}\times\mathbf{\chi}_{j}^{\text{V}}+\mathbf{t}_{i}^{\text{GV}})\right\|^{2}, i\geq h\end{array} \right. \tag{31}\]  
When \(i<h\), only the existing data frames in the localization verification sliding window are optimized, and the initialization of \((\mathbf{R}^{\text{GV}},\mathbf{t}^{\text{GV}})\) is not completed; when \(i=h\), the data frames in the window are full. After optimizing the data frames in the window, the initialization of \((\mathbf{R}^{\text{GV}},\mathbf{t}^{\text{GV}})\) is completed. When \(i>h\), the system comes into the stable operation process and it is still necessary to continue updating \((\mathbf{R}^{\text{GV}},\mathbf{t}^{\text{GV}})\) according to Equation (31). During the initialization process, GNSS verification is not performed. At this time, a smoothing localization strategy \(\mathbf{S}_{1}\) will be adopted: update the external parameters \((\mathbf{R}^{\text{GV}},\mathbf{t}^{\text{GV}})\) of the camera to obtain the coupling localization result of GNSS/Visual SLAM. After the initialization phase, spoofing detection is required. The system is always vigilant and verifies every GNSS data frame when it arrives to determine whether GNSS spoofing occur. We use the external parameters generated at the previous time and the visual data frame at the current time to invert the position offset of the GNSS at the current time and then, select the verified GNSS data frames to mutually optimize the external parameters according to Equations (16) and (20).