# Model Reference Adaptive Control of Aircraft Undergoing Wing Rock

This example shows how to control roll and roll rate of a delta wing aircraft undergoing wing rock. For this example, the system model is unknown. Therefore, you use model reference adaptive control (MRAC) to make the controlled system match an ideal reference model. The aircraft is modeled in Simulink® and the MRAC controller is implemented using the Model Reference Adaptive Control block provided by Simulink Control Design™ software.

### Wing-Rock Control System

Wing rock is a phenomenon observed in delta wing aircraft flying at low speeds and high angles of attack. The aircraft experiences undesired roll oscillations that make the aircraft more difficult for the pilot to control. The goal of the MRAC controller is to cancel the undesired roll oscillation. You can then design a baseline controller to achieve a desired reference behavior.

The following equations define the dynamics for the wing-rock model.

`$\begin{array}{l}\underset{}{\overset{˙}{\theta }}=p\\ \underset{}{\overset{˙}{p}}=\Delta \left(x\right)+{L}_{\delta }{\delta }_{a}\\ \Delta \left(x\right)={w}_{0}^{*}+{w}_{1}^{*}\theta +{w}_{2}^{*}p+{w}_{3}^{*}|\theta |\theta +{w}_{4}^{*}|p|p+{w}_{5}^{*}{\theta }^{3}\end{array}$`

Here:

• $\mathit{x}=\left(\theta \text{\hspace{0.17em}},\mathit{p}\right)$ is the system state vector, where $\theta$ is the roll angle and $\mathit{p}$ is the roll rate.

• ${\delta }_{\mathit{a}}$ is the aileron angle control input for the aircraft.

• ${\mathit{L}}_{\delta \text{\hspace{0.17em}}}$ is the control effective matrix for which you know at least the sign.

• $\Delta \left(\mathit{x}\right)$ is the wing-rock disturbance.

• ${\mathit{w}}_{\mathit{i}}^{*}$ are unknown ideal weights.

For this uncertain nonlinear system, your goal is to design a controller that enables the system to track the following second-order reference model.

`${\underset{}{\overset{¨}{x}}}_{m}=-4{x}_{m}-2{\underset{}{\overset{˙}{x}}}_{m}+4r\left(t\right)$`

Here:

• ${\mathit{x}}_{\mathit{m}}$ is the reference model state vector.

• $\mathit{r}\left(\mathit{t}\right)$ is the roll reference signal provided by the pilot.

### Nominal and Reference Models

Specify the following simplified second-order nominal model for the roll dynamics.

```A = [0 1; 0 0]; % Second integrator model B = [0;1]; % Nominal control effective matrix```

Define the reference model as the stable second-order system defined previously. The controller adapts its uncertainty model to achieve the same second-order behavior as this model.

```Am = [0 1; -4 -2]; % Second intergrator model Bm = [0;4]; % Nominal control effective matrix```

Specify the initial conditions for the nominal and reference models.

```theta_0 = 0; % Initial roll angle (rad) p0 = 0; % Initial roll rate (rad/s) xm = [0;0]; % Initial condition of the reference plant model ```

### Model Reference Adaptive Control Structure

The goal of the MRAC controller is to achieve asymptotic convergence of the tracking error $\mathit{e}\left(\mathit{t}\right)=\mathit{x}\left(\mathit{t}\right)-{\mathit{x}}_{\mathit{m}}\left(\mathit{t}\right)$.

`$\underset{t\to \infty }{\mathrm{lim}}\left(x\left(t\right)-{x}_{m}\left(t\right)\right)\to 0$`

The MRAC controller has the following structure.

`$u\left(t\right)=-{k}_{x}x\left(t\right)+{k}_{r}r\left(t\right)-{u}_{ad}$`

Here:

• ${k}_{x}$ contains feedback control gains.

• ${k}_{r}$ contains feedforward control gains.

• ${u}_{ad}$ is an adaptive control term that cancels the model uncertainty.

The Model Reference Adaptive Control block adjusts the adaptive control term to achieve the desired reference model tracking. Optionally, you can also adapt the feedback and feedforward control gains. Though, for this example, the control gains are static.

The static feedback and feedforward control gains for the wing-rock system are computed to satisfy the following model-matching condition.

`$\begin{array}{l}{A}_{m}=A-B{k}_{x}\\ {B}_{m}=B{k}_{r}\end{array}$`

Specify the computed controller gains.

```Kx = [-4 -2]; % Feedback gain Kr = 4; % Feedforward gain```

### Uncertainty Estimation Parameters

The MRAC controller estimates the model uncertainty online and generates an adaptive control action ${\mathit{u}}_{\mathrm{ad}}$ that cancels the uncertainty to recover the nominal system for the baseline controller. The adaptive control term models the system uncertainty using the following model.

`${u}_{ad}={w}^{T}\varphi \left(x\right)$`

Here:

• $w$ contains the network weights that are adjusted by the controller.

• $\varphi \left(\mathit{x}\right)$ is the uncertainty model feature vector.

Using the Model Reference Adaptive Control block, you can select one of the following feature vector definitions.

1. System states, where $\varphi \left(\mathit{x}\right)=\mathit{x}\left(\mathit{t}\right)$ — This approach is the simplest option, which can be a good starting point if you do not know the complexity of the system uncertainty. If you find that using the states as features does not adequately represent the nonlinear uncertainty, select one of the other approaches.

2. Radial basis functions (RBFs) with Gaussian kernels, where $\varphi \left(\mathit{x}\right)={\left[{\mathrm{exp}\left(-\frac{{\left(\mathit{x}-{\mathit{c}}_{\mathit{i}}\right)}^{2\text{\hspace{0.17em}}}}{\sigma {\text{\hspace{0.17em}}}_{\mathit{i}}}\right)}^{}\right]}_{\mathit{i}=1}^{\mathit{N}}$ . You can configure the kernels by defining the feature centers ${\mathit{c}}_{\mathit{i}}$ and bandwidths ${\sigma }_{\mathit{i}}$.

3. Single hidden layer (SHL) neural network with a specified number of neurons in the hidden layer.

4. Custom features provided by an optional input port.

For this example, you configure the controller to use all three methods and compare the results.

Define the model estimation learning rate `gamma_w` and tracking error weight `Q`. These parameters are used for all three controller configurations.

```gamma_w = 100; % Learning rate Q = 1; % Tracking error weight```

Specify the parameters for the radial basis function kernels. Generally, you configure the RBF centers to span the possible state space of the system and the bandwidth to provide sufficient overlap between the kernels.

```N = 10; % Number of RBF kernels cen_max = 2; % Upper limit for kernel centers cen_min = -2; % Lower limit for kernel centers bandwidth = 25; % Kernel bandwidth```

### Simulate Controller Using State Feature Vector

Open a Simulink model of the wing-rock control system configured to use the system states as the uncertainty model feature vector.

```mdl = "wingrockStates"; open_system(mdl)``` In this model:

• The Wing-Rock Model block implements the nominal model of the roll dynamics.

• The External Disturbance block generates a wing-rock disturbance of the roll dynamics.

• The Reference Command block generates the pilot reference signal.

• The Model Reference Adaptive Control block outputs the control action ${\mathit{u}}_{\mathrm{ad}}$, which is an estimate of the wing-rock disturbance.

Set the simulation duration and simulate the model.

```Tf = 40; % Simulation duration (s) sim(mdl);```

Compare the resulting aircraft roll to the reference command.

`open_system(mdl + "/Roll")` The controller does not achieve a smooth second-order transient response.

Compare the disturbance model estimated by the MRAC controller with the true disturbance signal.

`open_system(mdl + "/Disturbance")` When using the states as the disturbance model features, the linear disturbance model estimated by the controller does not accurately represent the true nonlinear disturbance.

### Simulate Controller Using RBF Feature Vector

Open a Simulink model of the wing-rock control system configured to use the nonlinear RBFs as the uncertainty model feature vector. This model is identical to the previous model except that the controller parameters have been updated.

```mdl = "wingrockSHL"; open_system(mdl)```

Simulate the model.

`sim(mdl);`

View the resulting controller performance.

`open_system(mdl + "/Roll")` The controller achieves a smoother second-order response for changes in the reference command.

Compare the disturbance estimated using the radial basis functions to the true disturbance.

`open_system(mdl + "/Disturbance")` The nonlinear feature vector allows the controller to more accurately estimate the true nonlinear disturbance.

### Simulate Controller Using SHL Neural Network Feature Vector

Open a Simulink model of the wing-rock control system configured to use the SHL neural network output as the uncertainty model feature vector. This model is identical to the previous model except that the controller parameters have been updated.

```mdl = "wingrockSHL"; open_system(mdl)```

Simulate the model.

`sim(mdl);`

View the resulting controller performance.

`open_system(mdl + "/Roll")` The controller achieves a smooth second-order response for changes in the reference command.

Compare the disturbance estimated using the SHL neural network to the true disturbance.

`open_system(mdl + "/Disturbance")` The nonlinear feature vector computed by the neural network approximator is closer to the true disturbance than the RBF feature vector. Configuring the neural network parameters is also simpler.

### Simulate Controller Using Custom Feature Vector

Open a Simulink model of the wing-rock control system configured to use an externally generated custom uncertainty model feature vector. You can use this option when you know the structure of the disturbance and uncertainty model. For this example, the feature vector generated by the Features block matches the feature vector used in the External Disturbance block.

```mdl = "wingrockCustom"; open_system(mdl)``` Simulate the model.

`sim(mdl);`

View the resulting controller performance.

`open_system(mdl + "/Roll")` The controller achieves a smoother second-order response for changes in the reference command.

Compare the disturbance estimated using the custom feature vector to the true disturbance.

`open_system(mdl + "/Disturbance")` As expected, using a custom feature vector based on prior knowledge of the disturbance behavior produces a more accurate model of the true disturbance.