## 3 Quadcopter Control
### Attitude Control
Model predictive control is considered as a multivariable controlling algorithm incorporating the following components:  
* A dynamics model of the system under control. * A cost function \(J\). * An optimization mechanism. The optimal manipulated variable (\(u_{MPC}\)) is computed by minimizing the cost function \(J\) using the optimization algorithm. A typical cost function in the MPC algorithm is made up of four terms, each of which focuses on a different element of controller performance (\(k\) represents the current control interval):  
\[J(\mathbf{d}_{k})=J_{RT}(\mathbf{d}_{k})+J_{u}(\mathbf{d}_{k})+J_{\Delta u}(\mathbf{d}_{k}) \tag{33}\]  
\[\mathbf{d}_{k}=[u_{MPC}(k|k)\ u_{MPC}(k+1|k)\ \dots\ u_{MPC}(k+p-1|k)] \tag{34}\]  
where \(\mathbf{d}_{k}\) signifies optimal control inputs that are obtained by solving a quadratic programming (QP) problem, as indicated in Equation (34). In Equation (33), \(J_{RT}(\mathbf{d}_{k})\) is reference tracking cost. Here, \(J_{u}(\mathbf{d}_{k})\) and \(J_{\Delta u}(\mathbf{d}_{k})\) are representations of manipulated variable tracking and manipulated variable move suppression, respectively. The last cost term in Equation (33), \(J_{\Delta u}(\mathbf{d}_{k})\), decreases the control effort, thereby reducing the energy consumption of the actuators (e.g., the dc motors of the quadrotor). The MPC cost function can be formulated as follow:  
\[J(\mathbf{d}_{k})=\sum_{i=0}^{p-1}[\mathbf{e}_{RT}^{T}(k+i)\mathbf{Q}\mathbf{e}_{RT}(k+i)]+[ \mathbf{e}_{u}^{T}(k+i)\mathbf{R}\mathbf{e}_{u}(k+i)] \tag{35}\] \[+[\Delta\mathbf{u}^{T}(k+i)\mathbf{R}_{\Delta u}\Delta\mathbf{u}(k+i)]\]  
In Equation (35), \(\mathbf{Q}\) is a (\(n_{RT}\times n_{RT}\)) weight matrix (\(n_{RT}\) is the number of plant output variables). Here, \(\mathbf{R}\), and \(\mathbf{R}_{\Delta u}\) (\(n_{u}\times n_{u}\)) are positive-semi-definite weight matrices (\(n_{u}\) represents the number of manipulated variables). In the aforementioned cost function, \(p\) is the prediction horizon, which can be adjusted according to the controller performance and  
Figure 3: Prediction horizon and predicted control inputs in MPC. the processing power of the hardware. In Equation (35), \(\mathbf{e_{RT}}\), \(\mathbf{e_{u}}\), and \(\Delta\mathbf{u}\) can be computed, using Equations (36)-(38). \[\mathbf{e_{RT}}(i+k) =\mathbf{r}(k+i+1|k)-\mathbf{y}(k+i+1|k) \tag{36}\] \[\mathbf{e_{u}}(i+k) =\mathbf{u_{des}}(k+i|k)-\mathbf{u_{MPC}}(k+i|k)\] (37) \[\Delta\mathbf{u}(k+i) =\mathbf{u_{MPC}}(k+i|k)-\mathbf{u_{MPC}}(k+i-1|k) \tag{38}\]  
The reference value (or reference values) given to the controller at the \(i\)th prediction horizon step is specified as \(\mathbf{r}(k+i|k)\). Similarly, the value (or values) of \(n_{RT}\) outputs variables of the plant, sampled at the \(i\)th prediction horizon step, is defined as \(\mathbf{y}(k+i|k)\). In the equation, \(\mathbf{u_{des}}(k+i|k)\) reflects the value (or values) of \(n_{u}\) desired control inputs corresponding to \(u_{MPC}(k+i|k)\). In the proposed MPC control architecture, in this paper, there is one manipulated variable, \(u_{MPC}(k+i|k)\). In addition, in this paper, \(y(k+i|k)\) is the altitude (z position) of the robot, while \(r(k+i|k)\) is the desired altitude for the robot. In order to reduce the controller effort and alleviate the effects of arising fluctuations in the weight of the aerial robot, this study proposed to use a gravity compensator after the MPC controller. The final altitude control input \(u_{1}\) is defined as:  
\[u_{1}=u_{MPC}(k|k)-g(nominal\ mass\ of\ the\ robot+a_{1}) \tag{39}\]  
In Equation (39), \(a_{1}\) is the scaling factor of the compensator that is actively estimated by the RL policy. In order to evaluate the performance of the proposed control architecture in controlling an aerial robot, a dynamics model of a commercial aerial robot named Parrot was chosen and implemented in the simulator environment as the aerial robot under control.