# An In-Vehicle Smartphone RTK/DR Positioning Method Combined with OSM Road Network
## 2 Materials and Methods
### Smartphone RTK Model
When the forward acceleration is higher than 0.5 m/s\({}^{2}\) and the horizontal distance between adjacent RTK results is higher than 2 m, the initialisation process of the starting point is triggered. The specific formula is as follows:  
\[\left\{ \begin{array}{l}POS^{DR}=POS^{RTK}\\ v_{\eta}^{DR}=v_{\pi}^{RTK}\\ v_{\phi}^{DR}=v_{e}^{RTK}\\ v_{u}^{DR}=0\\ tx=\cos\left(B_{k-1}^{RTK}\right)\sin\left(B_{k}^{RTK}\right)-\sin\left(B_{k- 1}^{RTK}\right)\cos\left(B_{k}^{RTK}\right)\cos\left(L_{k}^{RTK}-L_{k-1}^{RTK}\right) \\ ty=\sin\left(L_{k}^{RTK}-L_{k-1}^{RTK}\right)\cos\left(B_{k}^{RTK}\right)\\ \psi^{DR}=\psi^{RTK}=\arctan\left(\frac{ty}{tx}\right)\end{array} \right. \tag{9}\]  
In the above formula, \(POS\) represents the latitude, precision, and geodetic height; \(v_{\mu}\), \(v_{e}\), and \(v_{u}\) represent the velocity in the E, N, and U directions, respectively; \(tx\) and \(ty\) represent the temporary variables; \(k\) represents RTK positioning epoch number; and \(\psi\) represents the heading angle. Smartphones can directly output attitude quaternions. By converting the raw attitude quaternion into Euler angles, it is possible to find that the heading angle has a systematic deviation from the actual value, due to the disturbance of the vehicle magnetic field. Therefore, \(\psi^{DR}\) was used to replace the raw heading angle during the initialisation phase. The roll and pitch angles are directly output by using the smartphone. Finally, the new Euler angles are converted into quaternions. The second step is attitude update. The attitude update was carried out through the Mahony complementary filter algorithm, which uses the cross product of acceleration and gravity to compensate for gyroscope data. In the carrier phase coordinate system (b coordinate system), the acceleration of the smartphone is normalised to obtain:  
\[a_{b,norm}=\frac{1}{\left|a_{b}\right|}\left[a_{x}\quad a_{y}\quad a_{z}\right] \tag{10}\]  
When the carrier phase is at rest, the normalised gravity of the navigation coordinate system (n coordinate system) is \(g_{n}= \begin{bmatrix}0&0&1\end{bmatrix} ^{T}\), which is transformed into the carrier phase coordinate system:  
\[g_{b}=(C_{b}^{n})g_{n}= \begin{bmatrix}2(q_{1}q_{3}-q_{0}q_{2})\\ 2(q_{2}q_{3}+q_{0}q_{1})\\ q_{0}^{2}-q_{1}^{2}-q_{2}^{2}+q_{3}^{2}\end{bmatrix}  \tag{11}\]  
The cross product of \(a_{b,norm}\) and \(g_{b}\) is the error correction amount of the gyroscope:  
\[e_{acc}=a_{b,norm}\times g_{b} \tag{12}\]  
Finally, the PI controller is used to compensate for the angular velocity:  
\[gyro=gyro+k_{s}e_{acc}+k_{i}\int e_{acc} \tag{13}\]  
In the above formula, \(gyro\) represents the angular velocity in the carrier coordinate system; \(k_{s}=1\) and \(k_{i}=0.001\). The compensated angular velocity was used to update the attitude quaternion and convert the updated attitude quaternion into Euler angles in order to accomplish the attitude update process. The third step is velocity update. There are two ways to measure the velocity of smartphones, i.e., acceleration integration and the Doppler velocimetry. Figure 1 shows the velocity obtained using the two methods. The blue line represents the velocity obtained through acceleration integration. The orange line represents the velocity obtained through Doppler velocimetry, and the red line represents the actual velocity. It can be found that because the accelerometer noise of smartphones is significant, the velocity and actual value of the integral acceleration calculation are high. The velocity measured using Doppler data is more consistent with the actual value. Therefore, the Doppler velocimetry is used to update the velocity. The Doppler velocity measurement is related to RTK positioning results, and the direction of velocity is inconsistent with the RTK positioning heading angle, so DR velocity cannot be directly assigned. In the actual positioning process, RTK velocity is measured in the WGS84 coordinate system.