Wednesday, July 2, 2025

 The following sample is an addition to the Hungarian algorithm described in the previous article to allow a drone to calculate its flight path from the current to the next position using the shortest possible route. It uses the dubins package from PyPI — a lightweight and widely used implementation for shortest-path planning under curvature constraints. 

#! /usr/bin/python 

# pip install dubins matplotlib numpy 

import dubins 
import numpy as np 
import matplotlib.pyplot as plt 
 
def compute_dubins_path( 
    start_pos: tuple[float, float, float], 
    end_pos: tuple[float, float, float], 
    turning_radius: float = 10.0, 
    step_size: float = 1.0 
): 
    """ 
    Compute the shortest Dubins path between two configurations. 
 
    Parameters: 
        start_pos: (x, y, heading in radians) 
        end_pos: (x, y, heading in radians) 
        turning_radius: Minimum turning radius of the drone 
        step_size: Distance between sampled points along the path 
 
    Returns: 
        List of (x, y, heading) tuples along the path 
    """ 
    path = dubins.shortest_path(start_pos, end_pos, turning_radius) 
    configurations, _ = path.sample_many(step_size) 
    return configurations 
 
# Example usage 
if __name__ == "__main__": 
    # Initial and final positions: (x, y, heading in radians) 
    q0 = (0.0, 0.0, np.deg2rad(0))       # Start at origin, facing east 
    q1 = (50.0, 30.0, np.deg2rad(90))    # End at (50,30), facing north 
 
    path_points = compute_dubins_path(q0, q1, turning_radius=15.0, step_size=0.5) 
 
    # Plotting the path 
    x_vals, y_vals = zip(*[(x, y) for x, y, _ in path_points]) 
    plt.figure(figsize=(8, 6)) 
    plt.plot(x_vals, y_vals, label="Dubins Path", linewidth=2) 
    plt.scatter(*q0[:2], color='green', label="Start") 
    plt.scatter(*q1[:2], color='red', label="End") 
    plt.axis("equal") 
    plt.title("Dubins Path for Drone Flight") 
    plt.xlabel("X") 
    plt.ylabel("Y") 
    plt.legend() 
    plt.grid(True) 
    plt.show() 


#Codingexercise: https://1drv.ms/w/c/d609fb70e39b65c8/EYzGgu5Fc4dEoCUHWQYxMbUBSfvC36iKh8ESBaLtozvdqA?e=uXE4Jm

Tuesday, July 1, 2025

 As an example of drone formation transformation discussed in the previous article, the following code demonstrates the application of Hungarian Algorithm to determine the position allocation in formation transformation.  

#! /usr/bin/python 

# pip install hungarian-algorithm 
 

from hungarian_algorithm import algorithm 
import numpy as np 
 
# Source: drones in a 3×3 grid on Z=0 plane 
source_positions = [ 
    (x, y, 0) 
    for y in range(3) 
    for x in range(3) 
] 
 
# Target: drones in a single horizontal line (linear flight path), spaced 10 units apart 
target_positions = [ 
    (i * 10, 0, 0) for i in range(9) 
] 
 
# Compute cost matrix (Euclidean distance) 
cost_matrix = [ 
    [ 
        np.linalg.norm(np.array(src) - np.array(dst)) 
        for dst in target_positions 
    ] 
    for src in source_positions 
] 
 
# Run Hungarian Algorithm to get minimum-cost assignment 
assignment = algorithm.find_matching(cost_matrix, matching_type='min') 
 
# Report matched pairs 
for src_idx, dst_idx in enumerate(assignment): 
    print(f"Drone {src_idx} → Target Position {dst_idx}: {target_positions[dst_idx]}") 


The above does not take velocity and heading into consideration but that can be adjusted as per trajectory.


#Codingexercise: https://1drv.ms/w/c/d609fb70e39b65c8/EYzGgu5Fc4dEoCUHWQYxMbUBSfvC36iKh8ESBaLtozvdqA?e=VfWGog

Monday, June 30, 2025

 Most drones don’t have radars. They merely have positions that they change based on fully autonomous decisions or provided by a controller. In the former case, the waypoints and trajectory determine the flight path, and each drone independently tries to minimize the errors in deviations from the flight path while aligning its path using least squares method. The selection of waypoints and the velocity and ETA at each waypoint is determined for each unit in a UAV swarm with ability to make up delays or adjust ETAs using conditional probability between past and next waypoint while choosing a path of least resistance or conflict between the two. Usually, a formation, say matrix, already spreads out the units and its center of mass is used to calculate the progress on the flight path for the formation. This article discusses a novel approach to minimize the conflicts and adhere to the path of least resistance.

For example, to transform between an “Abreast” and a “Diamond” formation, any technique must demonstrate efficiency in minimizing transformation distance and maintaining formation coherence. Similarly, to transform between matrix formation to flying linearly under a bridge between its piers, any technique must demonstrate a consensus based pre-determined order.

The approach included here defines a drone’s formation state with six parameters: time, 3D positions, yaw angle (heading), and velocity. For a formation to be considered coherent, all drones must share the same heading and speed while maintaining relative positions—essential for realistic aerial maneuvers.

The transformation itself consists of two steps: location assignment and path programming. First, to determine which drone should move to which position in the new formation, the Hungarian algorithm, a centralized optimization method is used or in its absence the information about the greatest common denominator for volume between two waypoints determines the number of multiple simultaneous paths to choose and the matrix model is used to assign the positions for the drones to the nearest path. If there is only one path and no centralized controller, the units use Paxos algorithm for coming to a consensus on the linear order. This first step evaluates the cost of moving each drone to each new position by considering spatial displacement, heading change, and velocity difference. This ensures the assignment minimizes overall disruption and maneuvering effort.

Second, each drone calculates its own flight path to the newly assigned position using a Dubins path model, which generates the shortest possible route under a minimum turning radius constraint—a requirement for fixed-wing drones that can’t make sharp turns or hover. Positions alone do not guarantee compliance and the velocity adjustments for each unit must also be layered over the transition. The adjustment of velocities follows a Bayesian conditional probability along the associated path for the unit. This involves computing acceleration and deceleration phases to fine-tune the duration and dynamics of the transition with error corrections against deviations.

Overall, this provides a cohesive framework for in-flight drone formation reconfiguration that balances centralized planning with distributed execution. By coding the physical constraints and states for each unit and classifying the adherence, outliers can be handled by rotating them with other units for a smooth overall progression for the formation and overcoming environmental factors such as turbulence with error corrections.

#Codingexercise: https://1drv.ms/w/c/d609fb70e39b65c8/Echlm-Nw-wkggNaVNQEAAAAB63QJqDjFIKM2Vwrg34NWVQ?e=yTCv5p