# Designing a Reliable UAV Architecture Operating in a Real Environment
## 3 Modeling of UAV Architecture
### The Modeling of an Emergency Situation  
In this section, a practical example of modeling an emergency situation in the flight of an unmanned platform will be presented, which concerns the response to a potential air collision of two platforms. Figure 1 shows an exemplary Use Case model that describes the flight of the UAV in the WAYPONT mode (flight along an a priori pre-set route consisting of many points). The basic Use Case must include handling an emergency situation in flight, which concerns the occurrence of a potential collision of air platforms that inform themselves about their positions using the ADSB system. The same applies to the avoidance of collisions with a terrain obstacle. Figure 2 shows a general diagram of a State Machine for a Use Case that includes testing for the possibility of collision between air platforms during flight. The state machine model is shown, which describes the system's operation during the flight in the WAYPONT mode (automatic flight after the _a priori_ setpoints). All state changes occur within a single thread, which allows the use of a Mission Computer with lower performance (and thus smaller dimensions of the device). However, critical functions do not run in parallel, so the method of implementation described by the model is unacceptable for larger platforms. Figure 3 shows the State Machine model, which describes the operation of the system in flight in the same mode. The handling of the flight to the following points is separate from checking for the occurrence of emergency situations. In this model, there are two parallel threads, each affecting how the other works. The critical functions for testing emergencies are performed serially in a separate thread. This implementation method is acceptable for larger platforms and does not consume a significant amount of computer resources (in this case, the Mission Computer). Figure 2: State machine diagram for a collision avoidance of UAV. Model for one core unit processor. Actions within the states are presented. Figure 3 shows a fragment of the State Machine model with selected actions in selected states. From a formal point of view, each state must have an action with the stereotype _do:_ that describes the processing that is performed in that state. This processing can be modeled as an activity or sequence diagram. In our case, the functions _doc:testCollision()_ and _do:findWPT()_ are given numerical algorithms that are used to implement them. Collision testing is performed according to the Equations (1) and (2) (see Section 4). It is worth noting that the determination of the collision situation takes a short time so that individual tests can be performed sequentially without risk. Determining a new flight direction is based on the Equations (3) and (4). The basic scenario carried out by the UAV, which performs a flight in the route mode, consists in going through the following states in sequence:  
\(FWM1\to FWM2\to FWM3\to FWM2\to SUP\to FWM1\) (selection of the next waypoint, flight to a point, the configuration of the recognition sensor, checking for an emergency, and going to the selection of the next waypoint). An alternative processing scenario will occur when a parallel process described in the [exceptional situation] state will execute the \(testCollision()\) function, which will determine the UAV in a potential collision with the UAV. At this point, an alternative scenario is realized:  
\(FWM1\to FWM2\to SUP\to FWM4\to FWM2\to SUP\to FWM1\) (following waypoint selection, flight to point, emergency test, emergency collision avoidance (_do:findWPT()_ function, which determines the point to which the UAV must fly to avoid a collision), a continuation of the flight to a point, a test of the occurrence of an emergency, and selection of the next waypoint). As part of handling emergency situations, potential collisions between aerial platforms and a collision with a terrain obstacle are tested. The reader may notice two entries from the state ExS2 to the state ExS1. It is not accidental.