# LSTM-DQN-APF Path Planning Algorithm Empowered by Twins in Complex Scenarios
## 3 Method
### Extended Kalman Filter Data Fusion Algorithm  
To address the issues of perception accuracy and data reliability that exist with a single sensor in dynamic environments and to enhance the decision-making accuracy of LSTM-DQN-APF, multi-sensor fusion is needed to achieve precise environmental perception and state estimation. This paper adopts LiDAR (light detection and ranging) and IMU for data fusion. LiDAR is typically used for environmental perception (such as mapping, detecting obstacles, etc.), while IMU provides motion state information (such as acceleration, angular velocity, etc.). Through the virtual-real data fusion mechanism, by combining virtual sensor data (from the twin platform's simulated environment) with real sensor data (IMU and LiDAR measurements from the physical UAV) and using an extended Kalman filter for multi-source data fusion, the system's ability to respond to environmental changes can be effectively enhanced, thus improving path planning accuracy. The Algorithm 2 steps are as follows:  
```
Input: Virtual sensor data, real sensor data (timestamps, raw coordinates, velocity, obstacle point clouds); Output: Final fused data; Initialize state variables: Position information (x, y, z), Velocity (vx, vy, vz), Attitude angles and angular velocity (roll, pitch, yaw, p, q, r); Initialize state covariance matrix \(\mathrm{P}(\mathrm{k}|\mathrm{k})\); Initialize process noise matrix \(\mathrm{Q}\); Initialize observation noise matrix \(\mathrm{R}\); Initialize observation information, \(\mathrm{H}\) is the Jacobian matrix of the observation model, \(\mathrm{R}\) is the observation noise matrix;  While UAV has not reached the target point:  Predict the IMU state, \(\mathrm{\hat{x}}(\mathrm{k}+1\mid\mathrm{k})=\mathrm{F}\mathrm{\hat{x}}( \mathrm{k}\mid\mathrm{k})+\mathrm{Bu}(\mathrm{k})\);  PredicttheIMUcovariance, \(\mathrm{P}(\mathrm{k}+1\mid\mathrm{k})=\mathrm{FP}(\mathrm{k}\mid\mathrm{k}) \mathrm{F}^{\mathrm{T}}+\mathrm{Q}\);  PerformLidarobservationupdate, computeKalmangain, \(\mathrm{K}(\mathrm{k})=\mathrm{P}(\mathrm{k}+1\mid\mathrm{k})\mathrm{H}^{ \mathrm{T}}\left(\mathrm{HP}(\mathrm{k}+1\mid\mathrm{k})\mathrm{H}^{\mathrm{T }}+\mathrm{R}\right)^{-1}\);  Updatestate, \(\mathrm{\hat{x}}(\mathrm{k}+1\mid\mathrm{k}+1)=\mathrm{\hat{x}}(\mathrm{k}+1 \mid\mathrm{k})+\mathrm{K}(\mathrm{k})(\mathrm{z}(\mathrm{k})-\mathrm{h}( \mathrm{\hat{x}}(\mathrm{k}+1\mid\mathrm{k})))\);  Updatecovariance, \(\mathrm{P}(\mathrm{k}+1\mid\mathrm{k}+1)=(\mathrm{I}-\mathrm{K}(\mathrm{k}) \mathrm{H})\mathrm{P}(\mathrm{k}+1\mid\mathrm{k})\); end while end
```  
**Algorithm 2**Extended Kalman Filter Data Fusion Algorithm  
Throughout the process, the IMU continuously provides motion state information, while the LiDAR provides distance information about the environment. The extended Kalman filter continuously fuses the IMU and LiDAR data through prediction and update steps to obtain more accurate state estimates. The result of this virtual-real fusion can further be used in the lower-level APF module, supporting the collaborative decision-making ability of the DQN-APF, thereby improving obstacle avoidance accuracy.