# Smart Obstacle Avoidance Using a Danger Index for a Dynamic Environment
## 2 The Proposed Method
### Dynamic Window Based Artificial Potential Field (DAPF)
 \tag{8}\]  
where \(F_{req1}(\phi)\) and \(F_{req2}(\phi)\) are two components of the \(F_{req}(\phi)\), which are defined in Equation (9) and (10):  
\[F_{req1}(\phi)=k_{r}(\frac{1}{d(\phi)}-\frac{1}{d_{max}})\frac{1}{d(\phi)^{2} }(\phi-\phi_{g})^{n}\cdot\frac{\partial d(\phi)}{\partial\phi}, \tag{9}\]  
\[F_{req2}(\phi)=\frac{1}{2}k_{r}n(\frac{1}{d(\phi)}-\frac{1}{d_{max}})^{2}(\phi -\phi_{g})^{n-1}\cdot\frac{\partial(\phi-\phi_{g})}{\partial\phi}. \tag{10}\]  
The direction of \(F_{req1}(\phi)\) is from the obstacle to the mobile robot, and \(F_{req2}(\phi)\) is from the robot to the target point. Figure 2: Problems of a traditional artificial potential field (APF): (**a**) unreachable goals with obstacles nearby (GNRON) and (**b**) trapped in a local minimum region. For solving the local minima problem, we propose a dynamic APF approach (DAPF), which employs the dynamic window approach (DWA) to predict the local minimum region and solve the oscillations. The key idea of the DWA is to sample a number of predicted trajectories according to the current position \((x_{t},y_{t})\), direction \(\theta_{t}\) and velocity \(v_{r}\) as shown in Figure 3. The sampled directions \(\theta_{\omega}\) are the following:  
\[\theta_{\omega}=\theta_{t}+(\omega-t)\triangle\theta,\omega=(1,...,t,...,n), \tag{11}\]  
where \(\theta_{t}\) is the current direction of the robot, \(\triangle\theta\) is the angular step between samples and \(n\) is the number of samples. Using these sampled directions, we simulate a number of positions that the robot might go as  
\[ \begin{bmatrix}x_{1}^{\prime}&y_{1}^{\prime}\\...&...\\ x_{t}^{\prime}&y_{t}^{\prime}\\...&...\\ x_{n}^{\prime}&y_{n}^{\prime}\\ \end{bmatrix} = \begin{bmatrix}x_{t}&y_{t}\\...&...\\ x_{t}&y_{t}\\...&...\\ x_{t}&y_{t}\\ \end{bmatrix} + \begin{bmatrix}v_{r}\triangle t\cos(\theta_{1})&v_{r}\triangle t \sin(\theta_{1})\\...&...\\ v_{r}\triangle t\cos(\theta_{t})&v_{r}\triangle t\sin(\theta_{t})\\...&...\\ v_{r}\triangle t\cos(\theta_{n})&v_{r}\triangle t\sin(\theta_{n})\\ \end{bmatrix} , \tag{12}\]  
where \(x_{1}^{\prime},...,x_{n}^{\prime}\) and \(y_{1}^{\prime},...,y_{n}^{\prime}\) are coordinates of simulated positions, and \(v_{r}\) is the velocity of the robot. The final choice of the position can be defined as the one whose APF cost function is minimum:  
\[ \begin{bmatrix}x&y\\ \end{bmatrix} =\min(APF( \begin{bmatrix}x_{1}^{\prime}&y_{1}^{\prime}\\...&...\\ x_{t}^{\prime}&y_{t}^{\prime}\\...&...\\ x_{n}^{\prime}&y_{n}^{\prime}\\ \end{bmatrix} )), \tag{13}\]  
where \(x,y\) is the coordinate of the position whose resultant force value is minimum. Based on the improved APF function, the closer the robot is to the target, the smaller the resultant force value is. Before the robot enters the obstacle's influence range, it applies the DWA approach to simulate positions and calculate the resultant force for every simulated position. If the simulated position is in the obstacle range, the resultant force value is less than 0. If the simulated position is outside of the obstacle range, the resultant force of the simulated position that is closer to the target point is less than the positions that are far from the target point. Finally, the robot can obtain a simulated position that is close to the target point but not in the obstacle area, such that the local minimum region can be avoided using the DAPF approach. If the target point is within the obstacle range, the DWA method will be stopped when the distance of the robot from the target point is less than the distance from the obstacle. Figure 3: Robot trajectories simulated by a dynamic window approach (DWA).