3.1. Method to Assign Tasks to Multiple UAVs in Formation Based on the Hungarian Algorithm
To enable multiple UAVs to realize the formation flight, trajectory planning according to mission objectives is the first thing to do, which is usually difficult in calculation, time-consuming in planning, and not efficient to meet actual demands. Therefore, it is important to explore a path planning algorithm with simple calculation and high efficiency for multiple UAVs.
Task assignment is of significance for multi-UAV trajectory planning, while for solving assignment problems, the Hungarian algorithm happens to be a very effective method with fast calculation and high efficiency. Therefore, this paper applies the Hungarian algorithm for the task allocation (assignment) of multiple UAVs to achieve the objective of obtaining the shortest total flight distance of all UAVs, as shown in
Figure 2.
Trajectory planning for UAVs formation can be carried out based on the theorem of the optimal solution of the Hungarian algorithm. The specific steps are presented as follows:
- Step 1:
Input the initial position matrix of UAVs and the target position matrix .
- Step 2:
Calculate the distance between the initial position of UAVs and n target waypoints to form an distance matrix . The element represents the distance between the UAVs numbered and the target waypoint.
- Step 3:
Apply row transformation to the distance matrix , where the smallest element of each row is subtracted from the elements of that row in matrix .
- Step 4:
Apply column transformation to the distance matrix , where the smallest element of each column is subtracted from the elements of that column in matrix .
- Step 5:
The trial assignment:
- (1)
Find the row and column with the least number of zero elements without lines, that is, traverse all the zero elements without lines to check how many zeros are in rows and columns where the elements are located, and finally select the zero elements in the row and column with the least number of zero elements;
- (2)
Find the zero elements without a line in that row and column, which is an independent zero element. Draw a line for the row and column in which those zero elements are located;
- (3)
Leave elements covered by lines alone for the moment and repeat steps (2) and (3) until there are no lines to draw;
- (4)
Succeed when finding independent zero elements according to the number of zero elements found in (3) and execute the next step when the number of independent zero elements is less than .
- Step 6:
Draw a line to cover the zeros:
- (1)
Tick rows without an independent zero element;
- (2)
Tick the corresponding columns with one or more zero elements in the ticked rows;
- (3)
Tick the corresponding rows with one or more independent zero elements in all ticked columns;
- (4)
Repeat (3) and (4) until no more ticks can be made.
- Step 7:
Update the matrix:
- (1)
Find the smallest number among those without lines;
- (2)
Subtract the smallest number from those without lines;
- (3)
Add the smallest number to the numbers with two lines, ensuring that the position of zero elements remains unchanged.
- Step 8:
Repeat steps 5–7 until success.
The resulting matrix obtained after the above steps is the solution matrix. Replace all the independent zero elements in this matrix with 1 and all the elements except the independent zero elements with 0. Such a 0–1 matrix is the optimal solution to the multi-UAV allocation problem.
Pseudo-code of the task allocation Algorithm 1 is:
Algorithm 1: UAV task assignment algorithm |
|
3.2. The Multi-UAV Trajectory Planning Method Based on the Four-Dimensional Spatiotemporal Hierarchical Decomposition
According to the task assignment result, a trajectory can be designed for each UAV from the current point to the target point, as shown in
Figure 3. A collision situation would occur if the mission is executed through the trajectory. To safely complete the formation flight mission, all UAVs need to take the same time to traverse the trajectory and not collide with each other, which satisfies the time coordination and safety of the formation. Therefore, the planning of the final flight trajectory also needs to meet the time constraints and safety constraints of the UAVs’ formation based on the task assignment.
- (1)
Time constraints
Time constraints require all UAVs to arrive at the corresponding target point simultaneously. In the time constraint of this paper, all UAVs are required to reach the navigation point within the time constraint. In a formation mission, it is assumed in this paper that the speed of all UAVs is maintained at a certain level, and the approximate time of arrival at the target point is calculated based on the range of the UAVs to realize the cooperativeness in time for all UAVs during formation flying since each trajectory consists of a series of waypoints which do not contain accurate time information. The approximate time is employed as the benchmark to establish a time-constrained model for UAVs formation.
denotes waypoints of UAV , the total number of all waypoints of UAV ’s trajectory, the waypoint of the trajectory , the position coordinates of the trajectory, and the flight time to reach the waypoint.
Based on the above representation of a trajectory, cooperative time constraints on waypoints for a multi-UAV formation can be expressed as:
- (2)
Safety constraints
Safety constraints require the distance between UAVs to be greater than or equal to the safety distance until they arrive at the target point to avoid collisions. Due to the large granularity of scattered waypoints, not only safety constraints at waypoints but also the safety of the entire trajectory within the same period should be determined. Specifically, and are set to represent the trajectories at the first and second waypoints of UAVs and , respectively, and the coordinates of point are set to be , point , point , and point . Safety constraints between the two UAVs are displayed in the following steps:
- Step 1:
Set the safety distance between two UAVs to meters according to UAVs’ control accuracy and relevant external equipment;
- Step 2:
Determine whether the shortest distance between the line segments connecting the adjacent waypoints corresponding to UAVs is less than the safe distance in a way shown as follows:
Set the line
to be a point on the line
. The coordinates
of the point
can be expressed as:
When the parameter k satisfies the condition where , is a point on the line ; when the parameter , is a point on the extended line of ; when the parameter , is a point on the extended line of .
Set the line
to be a point on the line
and the coordinates
of the point
can be expressed as:
When the parameter y satisfies the condition where , is a point on the line ; when the parameter , is a point on the extended line of ; when the parameter , is a point on the extended line of .
The distance between the point
and the point
is:
The shortest distance between the line and the line is the minimum value of .
Deduce the partial derivatives of for , respectively, and set the partial derivatives as 0. falls on line and falls on line , and is the shortest distance when the parameters obtained finally satisfy the condition where and . Otherwise, it will be impossible to find a point on the line and a point on the line to minimize the distance . At this point, deduce the shortest distance from to the line , and from to the line ; the shortest distance from to the line , and from to the line .
Above is the method to determine whether two trajectories collide or not, and the process of determination is presented in
Figure 4.
A four-dimensional spatiotemporal hierarchical decomposition algorithm combined with automatic obstacle avoidance trajectory planning is proposed in this paper to meet the time constraints and safety constraints for UAVs’ formation. When the distance between UAVs is too close, the procedure of automatic obstacle avoidance takes effect and plans a route for the UAVs to avoid obstacles. Thenceforth, the UAVs will continue to perform their original tasks. Targeting the specific tasks for formations, collision detection on trajectories of all UAVs is conducted in a combination of time constraints to automatically contrive routes for obstacle avoidance in the future. The specific implementation steps are as follows:
- Step 1:
Set the safety distance as and the time required for UAVs to fly the safety distance as ;
- Step 2:
Step 2: Determine whether the shortest distances between the trajectory connecting the initial and target points of the first UAV and that of the remaining UAVs are greater than or equal to the safe distance s according to the initial point matrix and the target point matrix of a formation. Practice Step 3 if the shortest distance is smaller than the safe distance, and perform Step 4 if it is greater than the safe distance;
- Step 3:
Select the smaller serial numbers of UAVs, put them into the array , and conduct Step 4;
- Step 4:
Determine the distances between the trajectory connecting the initial and target points of the UAV and that of the remaining UAVs and repeat Step 3 until all the distances in a formation mission have been determined.
- Step 5:
Sort the array in ascending order and copy the array to the array ;
- Step 6:
Put all UAVs’ serial numbers in the formation mission other than those in the array into the array in ascending order;
- Step 7:
Traverse the array , copy the position information of all UAVs’ initial and target points in the array, and at the same time increase the two points’ heights by meters, respectively. Insert the two points with increased heights into the middle of the original points (for example, the initial and target points are at and , and there will four waypoints at , , after the two new points are inserted. Count denotes the number of times to carry out step 5, which will increase by 1 each time and whose initial value is 0. Practice Step 8;
- Step 8:
Clear the array and traverse the array to redetermine whether the distances between trajectories of all UAVs are greater than the safe distance s. Perform Step 9 after repeating steps 2 to 5;
- Step 9:
Traverse the array and modify the altitude information of newly added UAV waypoints in the array into , , , . Count means the number of times to practice Step 5, which will increase by 1 each time and whose initial value is 0. Repeat steps 8 to 9 until the distances between UAVs in the array are greater than the safe distance;
- Step 10:
Traverse the array G and insert two new waypoints corresponding to the nth segment of trajectories of all UAVs in the array . In this case, the original and become four waypoints of , , , ;
- Step 11:
Clear arrays , , and , and move the positions of the initial and target points to the next section of the trajectory (for instance, set the first and the second waypoints of all UAVs as the initial and target points at the very beginning, and then take the second and the third waypoints as the initial and target points). Repeat steps 1 to 10 until the distances between trajectories of all UAVs have been checked. At this point, the algorithm ends, and multi-UAV trajectory obstacle avoidance is completed.
The schematic diagram of obstacle avoidance based on hierarchical decomposition is shown in
Figure 5, where trajectories of UAV1 and UAV2 are
and
, respectively. There is a crossover between
and
, so automatic obstacle avoidance is required. According to the algorithm, UAV1 automatically inserts waypoints
and
, and UAV2 automatically inserts waypoints
and
, that is, the trajectory of UAV1 becomes
; the trajectory of UAV2 trajectory becomes
. UAV1 has performed a hierarchically decomposed flight and automatically avoided obstacles.
Pseudo-code of the hierarchical decomposition and automatic obstacle avoidance Algorithm 2:
Algorithm 2: High layered realization of UAV obstacle avoidance |
|