## 4 Collision Avoidance Algorithm
### Motion Adjustment via SBUIS Control Signal Modification  
The algorithm modifies the drone's motion control signals in real time to avoid detected obstacles. The user's command is interpreted as a virtual motion vector. When an obstacle is detected, the system generates a repulsive force vector according to the sensor data and adjusts the control signal accordingly. Repulsive Force Calculation: After obstacle detection, the system computes repulsive forces from each angular segment where a nearby obstacle is identified. Each segment corresponds to a specific direction around the drone, and the closest obstacle distance in that direction is denoted as \(D_{n}\), where \(n\) is the index of the angular segment. Using the Gaussian-based model introduced in Section 4.2, a virtual repulsive force \(\mathbf{f_{n}}\) is generated for each angular segment in which an obstacle is detected. This repulsive force vector points directly away from the obstacle's direction, and its magnitude is determined by Equation (5) with the corresponding distance \(D_{n}\). The closer the obstacle (i.e., the smaller \(D_{n}\)), the stronger the repulsive force. Once all individual repulsive forces \(\mathbf{f_{n}}\) are computed for the relevant angular segments, the system calculates the total repulsive force \(\mathbf{F_{t}}\) as the vector mean (average) of these forces. The updated formula is  
\[\mathbf{F_{t}}=\frac{1}{N}\sum_{n=1}^{N}\mathbf{f_{n}} \tag{6}\]  
where \(\mathbf{f_{n}}\) is the repulsive force vector generated from the \(n\)-th angular segment, \(N\) is the number of segments with valid obstacle detection (i.e., those within the safety threshold), and \(\mathbf{F_{t}}\) is the average repulsive force vector used to adjust the drone's control command. Control Signal Modification:  
The final modified control signal \(\mathbf{U_{mod}}\) is computed as the vector sum of the original user command \(\mathbf{U_{c}}\) and the total repulsive force \(\mathbf{F_{t}}\):  
\[\mathbf{U_{mod}}=\mathbf{U_{c}}+\mathbf{F_{t}} \tag{7}\]  
where \(\mathbf{U_{mod}}\) is the modified control signal, \(\mathbf{U_{c}}\) is the current control signal from the user, and \(\mathbf{F_{t}}\) is the virtual repulsive force generated due to the detected obstacle, as illustrated graphically in Figure 16.  
The drone's control signal is continuously adjusted based on the computed repulsive force \(\mathbf{F_{t}}\). If there are no obstacles that generate a significant repulsive force, or no obstacles within the threshold (\(\mathbf{F_{t}}=0\)), the drone follows the original user command without modification. When obstacles are detected, the magnitude and direction of \(\mathbf{F_{t}}\) are used to adjust the drone's flight direction and speed. The proposed algorithm was implemented as a program and embedded in the microcontroller. Its pseudo-code is given in Table 4.  
To demonstrate how user command is modified in response to obstacle detection, Figures 17 and 18 present a representative experimental case. Figure 17 shows the physical setup, where the drone is placed on a movable cart and slowly pushed toward an obstacle located in front. Although the drone is not in flight, the sensor module actively detects the surrounding environment in the same manner as during actual flight. As the drone approaches the object, the onboard sensors detect decreasing distance values in the forward direction.