# Affine Formation Maneuver Control for Multi-Agent Based on Optimal Flight System
## 4 Formation Control with Virtual Leader  
### Algorithm Description  
If we assume that only a subset of agents in the formation can receive global information, then a widely used distributed controller protocol with a three-component controller protocol can be defined as follows:  
\[\mathbf{u}_{i}=\underbrace{\mathbf{f}_{i}^{p}+\mathbf{f}_{i}^{p}}_{\mathbf{u}_{local}}+\mathbf{f}_{i} ^{t} \tag{19}\]  
where the first component \(\mathbf{f}_{i}^{p}\) and the second one \(\mathbf{f}_{i}^{n}\) are the same as (15) in local formation control for input and \(\mathbf{f}_{i}\) is the navigational feedback which would drive the agent to track the global path. Therefore, the distributed control protocol for an agent based on virtual leader and APF is designed as follows:  
\[\mathbf{u}_{i}=\underbrace{-\sum_{j=1,j\
eq i}^{N}\
abla_{i}(U_{ij}+U_{io}+U_{io} )}_{f_{i}^{p}}+\underbrace{C_{1}\sum_{j=1,j\
eq i}^{N}(\mathbf{v}_{i}-\mathbf{v}_{j})+ (\mathbf{v}_{i}-\mathbf{v}_{oi})}_{f_{i}^{p}}+\underbrace{f(\mathbf{u}_{d},\mathbf{v}_{d},\mathbf{ p}_{d})}_{f_{i}^{t}} \tag{20}\]  
\[f(\mathbf{u}_{d},\mathbf{v}_{d},\mathbf{p}_{d})=\mathbf{u}_{d}-C_{2}(\mathbf{p}_{i}-\mathbf{p}_{d})-C_ {3}(\mathbf{v}_{i}-\mathbf{v}_{d}) \tag{21}\]  
where \(f(\mathbf{u}_{d},\mathbf{v}_{d},\mathbf{p}_{d})\) represents the global path, in which \(\mathbf{u}_{d}\) and \(\mathbf{v}_{d}\) are desired velocity and obtained from desired path \(\mathbf{p}_{d}\). The global path \(\mathbf{p}_{d}\) is designed by the affine-based control algorithm and the corresponding configurations must be pre-defined. From Equation (8), the constant is defined as follows:  
\[p^{*}(t)=[I_{n}\otimes A(t)]r+I_{n}b(t) \tag{22}\]  
where \(A(t)\in\mathbb{R}^{d\times d}\) and \(b(t)\in\mathbb{R}^{d}\) are continuous of \(t\). The desired position \(p^{*}(t)\) of agent \(i\in V\) in the target formation is \(p_{i}^{*}(t)=A(t)r_{i}+b(t)\), where \(r\) is the constant configuration and \((G,r)\) the nominal formation for a typical geometric pattern, such as the standard geometric graph, as illustrated in Figure 2. Thus, the desired control input \(\mathbf{u}_{d}\) would be:  
\[\mathbf{u}_{d}=-1/\gamma_{i}\sum_{j\in N_{i}}\Omega_{ij}(\mathbf{\dot{p}}_{id}-\mathbf{ \dot{p}}_{jid}) \tag{23}\]  
where \(\gamma_{i}=\sum_{j\in N_{i}}\omega_{ij}\), motion consensus is only considered in the paper; thus, we have \(\mathbf{v}_{1d}=\cdots=\mathbf{v}_{Nd}=\mathbf{v}_{d}\), \(\mathbf{p}_{1d}=\cdots=\mathbf{p}_{Nd}=\mathbf{p}_{d}\). Formulations (22) and (23) describe the pre-defined configuration and the formation moves to the desired position \(\mathbf{p}_{i}(t)\rightarrow\mathbf{p}^{*}(t)(t\rightarrow\infty)\). This strategy primarily focuses on ensuring that various pre-defined configurations can be achieved even in the presence of obstacles. Additionally, the locally planned trajectory can be adjusted to avoid collisions if necessary and the sudden change of velocity. The following Algorithm 2 summarizes the desired input control. This paper creatively integrates the local control and affine-based global control into a unique optimal control framework. Hence, the approach involves using an affine-based method to generate multiple geometric patterns for all agents, followed by online calculation of local trajectories to update the trajectory and avoid collisions. The aim of this model would achieve collective maneuvers simultaneously and efficiently. Moreover, the use of virtual leader forces has been considered as an adjustment metric to prevent the collision from agents and obstacles, which would enhance the realistic functional and generality of UAV formation flight. This method can also solve the problem of much communication and feedback between leaders and followers to some extent, as Figure 5 shows. The following assumptions are made in this paper:  
1. The obstacle avoidance maneuvers are primarily in the horizontal plane. 2. To simplify the calculations of obstacle forces, the obstacles are enclosed within a circle. 3.