# Quadrotor Formation Strategies Based on Distributed Consensus and Model Predictive Controls
## 6 Simulation Preparation
### Simulink Environment Setup for the Formation Simulation  
The basic configuration of the simulated quadrotor system under the Matlab/Simulink environment is shown in Figure 6. The system includes a _Control System_ module, a _Gravity Influence_ module, and a six degrees of freedom (6 DOF) model module (_Quad 6 DOF Model_). Both leader and followers adopt the same configuration with the difference in the Control System module and the input/output ports. The _Gravity Influence_ module computes the distribution of the quadrotor's weight on the axes of frame \(\mathbf{B}\). The 6 DOF rigid body EOMs solver inside the _Quad 6 DOF Model_ module is shown in Figure 7. Block _6 DOF (Euler Angles)_ solves the nonlinear 6 DOF EOMs of the rigid body with the given inputs with respect to frame \(\mathbf{B}\). The block is provided by the Simulink/AerospaceThe _Control System_ module basically includes a yaw control submodule, pitch/roll control submodule, and an altitude control submodule. Figure 8 shows the configuration of the leader's _Control System_ module. The follower's _Control System_ module differs from the leader's _Control System_ module in the pitch/roll control submodule. The leader's and follower's pitch/roll control submodule will be introduced later in the section. The yaw control submodule controls the yaw motion of the quadrotor based on the dual-loop proportional plus integral (PI) control. The pitch/roll and altitude controls carry out the formation control strategies depending on the role that it is a leader or a follower. Likewise, the input/output ports differ depending on the role of the quadrotor. Figure 6: Simulated quadrotor system: leader. Figure 7: Simulink/Aerospace Blockset 6 DOF block. Figure 9 shows the configuration of the _Altitude Control_ submodule of the leader and the follower. The _Altitude Control_ submodule carries out the vertical formation strategies described in Section 5.1.2 for the leader and in Section 5.2.2 for the follower. In the leader's _Altitude Control_ submodule, the function _Track Generator_ generates the reference trajectory _Lv_ref_ for the LQT using the method provided in Section 5.1.2 depending on the vertical state of the leader, desired altitude, and climb rate. The vertical state of the leader, labeled as _vN_, is defined by Equation (38). The desired altitude and the climb rate, labeled as _required_alt_ and _required_RC_, are given by the user. Function _LQT_ tracks reference trajectory _Lv_ref_ by solving Equation (19) with the given weighting matrices, vertical state _vN_, and vertical state-space model (38). Function _LQT_ outputs thrust command _dT_, the follower's reference trajectory _F_vertical_ref_, and leader's velocity _L_velocity_w_ on \(\mathbf{\hat{b}}_{3}\) of frame \(\mathbf{B}\). In the follower's _Altitude Control_ submodule, function _FDM Algorithm_ computes the complete reference trajectory _Fv_ref_ consisting of the references for states \(\Delta h\) and \(\Delta w\) in Equation (38) using the finite-difference method (40). Then, function _LQT_ solves the equations in (19) depending on the given weighting matrices, the vertical state of follower _vN_, and vertical state-space model (38). After the computation, function _LQT_ outputs the thrust command _dT_. It is worth mentioning that the thrust command _dT_ in both the leader's and follower's control submodules is the thrust deviation from the thrust at the equilibrium point \(T_{total,0}\). Therefore, actual thrust command _T_t_ in Figure 6 that is input into the 6 DOF model equals the thrust deviation _dT_ plus the equilibrium thrust \(T_{total,0}\). Leader's velocity _L_velocity_w_ is used to compute the leader's velocity in frame \(\mathbf{I}\) in the control strategy in horizontal motion. Figure 8: Configuration of the control system. Figures 10 and 11 show the pitch/roll control submodule for the leader and the follower, respectively.