# Design and Implementation of Simulation System for Multi-UAV Mission
## 3 System Design
### Software Design  
(1) Collaborative planning module  
The collaborative planning module is developed based on MATLAB under the GUI framework, and mainly includes target assignment, formation control, path planning, conflict detection, and other functions. The module is able to establish multi-UAV typical application scenarios such as search, penetration and tracking, and complete path planning and waypoint binding based on mission planning algorithms. In addition to MATLAB, the module also supports programming languages such as Python and C++. (2) Ground station module  
The ground station has mission start/termination, command generation/sending, status monitoring/display, emergency disposal/control, etc. functions. As the sending center of mission commands, the ground station has mission calculation functions, including parameter setting, resource allocation, command generation, and process planning. The ground station is also the data collection center for multi-UAV missions, collecting heartbeat packets sent by all UAVs over the data transmission link and decoding them to obtain flight parameters for real-time display. All flight data, mission instructions, and other data are backed up in the background, generating flight logs for later review and replay of the entire mission process. The ground station software interface is written in Qt, as shown in Figure 3.  
(3) On-board logic task module  
The on-board logic task module program is the core for multi-UAV mission decision and cooperative control and is deployed on the Ubuntu host. A variety of functions such as mission calculations, image recognition, and control command resolution is realized by configuring the development environment of the ROS (robot operating system), MAVROS (MAVLINK function package in ROS), OpenCV (image processing library), Python, and  
Figure 3: Ground station interface. C/C++ on the host computer. The on-board program architecture design is shown in Figure 4.  
The onboard program development makes full use of the highly flexible software architecture of ROS and designs the entire program as a task control node (Control Node) and an image processing node (Image Node), which uses multiple threads to process multiple data internally and achieves the required functions through the communication mechanism between the nodes and the data interaction between the threads. For the task control node, the functions of the four threads are as follows:  
Thread 1: subscribing to flight parameters and image data. The mission control node uses the topic communication and service communication mechanisms of ROS to obtain the relevant data from the flight control node and the image processing node, respectively, according to the specified frequency. Among them, the absolute coordinates, relative coordinates, attitude, speed, acceleration, flight mode, starting point, altitude, and power of the aircraft are subscribed by the flight control node; the target identification flag and the relative position information of the target are subscribed by the image processing node. Thread 2: sending heartbeat packets in real time. Hearbeat packets are like the beating of the UAV's \"heart\" and are sent continuously at a specific frequency as long as the on-board program is running. The packets contain the ID number, type, task performed, and flight parameters, etc. The heartbeat packets are sent to the ground station via the serial port by calling the serial send function. Thread 3: receiving mission orders in real time. Mission instructions are sent to each UAV through the ground station. The ground station sends different instructions depending on the mission phase, and the on-board computer invokes the corresponding cooperative control actions upon completion of the analysis. Thread 4: control commands resolving in real time.