## 4 Consensus Algorithm for Optimal Obstacle Avoidance
When \(\mathbf{w}_{p}\mathbf{w}_{c}\mathbf{X}^{T}(\mathbf{L}\otimes\mathbf{I}_{m}\ )X+g(\mathbf{X})>0\) for \(\hat{\mathbf{X}}\
eq\mathbf{0}\), condition (16), i.e., \(\vspace{0.2 cm}V(\hat{\mathbf{X}})>0\) for \(\hat{\mathbf{X}}\
eq\mathbf{0}\), can be met. Subsequently, \(\mathbf{h}(\hat{\mathbf{X}})\) in \(\mathbf{J}_{3}\) is constructed by solving Equation (37):  
\[\mathbf{h}(\hat{\mathbf{X}})=\frac{\mathbf{w}_{p}}{\mathbf{w}_{c}}g^{T}(\hat{\mathbf{X}})(\mathbf{L} \otimes\mathbf{I}_{m})\hat{\mathbf{X}}+\frac{1}{4\mathbf{w}_{c}^{2}}g^{\prime T}(\hat{ \mathbf{X}})g^{\prime}(\hat{\mathbf{X}}) \tag{42}\]  
which becomes (25). The selection of appropriate values for the weighting parameters can guarantee \(\mathbf{h}(\hat{\mathbf{X}})>0\). When \(\mathbf{w}_{c}\) is valuated, a sufficiently small \(\mathbf{w}_{p}\) can always be determined for the positive-definite term \(\frac{1}{4\mathbf{w}_{c}^{2}}g^{\prime T}(\hat{\mathbf{X}})g^{\prime}(\hat{\mathbf{X}})\) to control the sign-indefinite term \(\frac{\mathbf{w}_{p}}{\mathbf{w}_{c}}g^{\prime T}(\hat{\mathbf{X}})(\mathbf{L}\otimes\mathbf{I}_ {m})\hat{\mathbf{X}}\). Let  
\[ \begin{array}{ll}\vspace{0.2 cm}V^{T}(\hat{\mathbf{X}})f(\hat{\mathbf{X}},\phi(\hat{ \mathbf{X}}))&=-[\hat{\mathbf{X}}^{T}R_{2}\hat{\mathbf{X}}+\mathbf{h}(\hat{\mathbf{X}})\\ &+(\hat{\mathbf{X}}^{T}P+\frac{1}{2}g^{\prime T}(\hat{\mathbf{X}}))\times\mathbf{R}_{1}^{ -1}(P\hat{\mathbf{X}}+\frac{1}{2}g^{\prime T}(\hat{\mathbf{X}}))]\end{array}  \tag{43}\]  
using Equations (37) and (38), with Equation (35). If \(\hat{\mathbf{X}}^{T}\mathbf{R}_{1}\hat{\mathbf{X}}\geq 0\), \(\mathbf{h}(\hat{\mathbf{X}})\geq 0\) and \((\hat{\mathbf{X}}^{T}\mathbf{P}+\frac{1}{2}g^{\prime T}(\hat{\mathbf{X}}))\mathbf{R}_{1}^{-1}( P\hat{\mathbf{X}}+\frac{1}{2}g^{\prime T}(\hat{\mathbf{X}}))>0\) when \(\hat{\mathbf{X}}\
eq 0\). Thus, condition (17) can be satisfied. Conditions (14) and (15) still need to be verified. According to Equations (31) and (34), when \(\hat{\mathbf{X}}=\mathbf{0}\), \(g(\hat{\mathbf{X}})=\mathbf{0}\), and \(g^{\prime}(\hat{\mathbf{X}})=\mathbf{0}\), conditions (14) and (15) are satisfied. According to Equations (24), (28) and (32), if all AUVs assemble in the reaction area, the avoidance force of each AUV will not be zero and all AUVs will leave the reaction area until a new consensus point is reached. If the consensus point \(\hat{\mathbf{X}}=\mathbf{0}\) is beyond the reaction area of the obstacle, it can easily be observed that \(g(\hat{\mathbf{X}})=0\) and \(g^{\prime}(\hat{\mathbf{X}})=\mathbf{0}\); thus, conditions (14) and (15) are satisfied. The optimal control law in Equation (24) can be obtained using Equation (40) and substituting \(\hat{\mathbf{X}}=\mathbf{X}-\mathbf{X}_{cs}\) into (34). Note that, owing to Equation (5), the part containing the ultimate consensus state \(\mathbf{X}_{cs}\) becomes zero. Thus, the control law (24) depends on \(\mathbf{X}\) and not \(\mathbf{X}_{cs}\). This satisfies the expectations because \(\mathbf{X}_{cs}\) is not a priori. At present, conditions (14) to (19) have been satisfied. Thus, according to Lemma 1, the control law (24) is the optimal control law for problem (7) in the sense of Equations (21) and (22), and the closed-loop system is asymptotically stable. Thus, \(\mathbf{X}=\mathbf{X}_{cs}\) and the consensus is achieved. Moreover, it can easily be determined from Equation (31) that \(\vspace{0.2 cm}V(\hat{\mathbf{X}})\to\infty\) as \(\hat{\mathbf{X}}=0\). The closed-loop system is globally asymptotically stable. Note that the collision area \(\Lambda_{j}\) is also excluded in the globally asymptotic stability area because no AUV exists to begin to avoid the obstacle. Corollary 2: _Owing to the proof of Theorem 1, noting that the optimal consensus algorithm is studied by the method of inverse optimal control, as the function \(\mathbf{h}(\hat{\mathbf{X}})\) in \(\mathbf{J}_{3}\) is not specified a priori, it is constructed using the optimality condition in Equation (38).