# B. Control Design

## Objective

The objective of this experiment is to design a position control system for the Quanser Aero system in the 2 DOF configuration. The angular position controller should meet the following specifications:&#x20;

## Design Specifications

1. **Steady-state error to a step command input:** \
   (a) $$e\_{ss, pitch}$$ = 0 deg\
   (b) $$e\_{ss, yaw}$$ = 0 deg&#x20;
2. **Peak time of response to a step command input:** \
   (a) $$t\_{p, pitch}$$≤ 2s \
   (b) $$t\_{p, yaw}$$≤ 2s&#x20;
3. **Percent Overshoot of response to a step command input:** \
   (a) $$PO\_{pitch}$$≤ 7.5% \
   (b) $$PO\_{yaw}$$ ≤ 7.5%
4. **No actuator saturation:** \
   (a) $$|V\_\theta|$$≤ 24V \
   (b) $$|V\_\psi|$$≤ 24V

### Refer to the lecture note on control design.

{% file src="<https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2F3L4owxQikDBBg33LRrmG%2FLab2%20Lecture_2D%20AERO%20System%20ID%20and%20control.pdf?alt=media&token=ba2d49e9-c712-40c4-a630-71d482df1d58>" %}

### Download Matlab Script

Download the setup aero file below and fill in the system parameters, control parameters and other necessary values to store in the MATLAB workspace. Use these variables in building Simulink so it is easier for you to put values. Make sure to check your values with TAs before running Simulink.

{% file src="<https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2FxEk4guiPyk0safyFyinC%2Fsetup_aero_ctrl_design.zip?alt=media&token=16afcca4-de43-437b-993b-dacb4e521630>" %}

## Controller Design

We will start our controller design by considering first the **decoupled system**. In this case, the Multiple-Input Multiple-Output (MIMO) system is represented as two separate Single-Input Single-Output (SISO) systems.

The pitch dynamics of the 2D Aero system is a Type 0 system, i.e., no pole at the origin. As such, we will select the PID controller structure for the pitch control design, which will meet the specification of zero steady-state error to a step command input. \
The yaw dynamics of the 2D Aero system is a Type 1 system, i.e., there is one pole at the origin. As such, we will select the PD controller structure for the yaw control design, which will meet the specification of zero steady-state error to a step command input.

1. Choose appropriate values for $$PO$$ and $$t\_p$$ in both pitch and yaw axes satisfying the design specifications.
2. For these selected values of $$PO$$ and $$t\_p$$ within the design specs, compute the <mark style="background-color:orange;">desired values</mark> of damping ratio $$\zeta$$ and natural frequency $$\omega\_n$$ using the following equations:\
   &#x20;                                                         $$PO = \left(e^{ \frac{-\zeta \pi}{\sqrt{1 - \zeta^2}}}\right)\*100%$$\
   \
   &#x20;                                                                          $$t\_p = \displaystyle \frac{\pi}{\omega\_d}$$\
   \
   &#x20;                                                                $$\omega\_d = \omega\_n \sqrt{1 - \zeta^2}$$
3. Using the aforementioned desired values of $$\zeta$$ and $$\omega\_n$$ and the system parameters calculated in part A, compute the proportional gain $$K\_p$$ and the derivative gain $$K\_d$$  individually for pitch and yaw controllers as follows:\
   **Note:** Let subscript $$\text{op}$$ represent open-loop (actual system parameters), and subscript $$\text{cp}$$ represent closed-loop (desired parameters).\
   \
   **Pitch:**\
   &#x20;                                                               $$K\_p = \displaystyle \frac{\omega\_{n\_\text{cl}}^2 - \omega\_{n\_\text{op}}^2}{\overline{K}*{\theta \theta}}$$\
   \
   &#x20;                                                        $$K\_d = \displaystyle \frac{2 \zeta*{\text{cl}} \omega\_{n\_\text{cl}} - 2 \zeta\_{\text{op}} \omega\_{n\_\text{op}}}{\overline{K}*{\theta \theta}}$$\
   **Yaw:**\
   &#x20;                                                                                  $$K\_p = \displaystyle \frac{\omega*{n\_\text{cl}}^2}{\overline{K}*{\psi \psi}}$$\
   \
   &#x20;                                                            $$K\_d = \displaystyle \frac{2 \zeta*{\text{cl}} \omega\_{n\_\text{cl}} - \displaystyle \frac{1}{\tau\_{\text{op}}}}{\overline{K}\_{\psi \psi}}$$\
   **Note:** In the above calculations, use the normalized thrust gains obtained using the <mark style="background-color:orange;">steady-state method</mark>.
4. Add an integral term, $$K\_i$$, to the pitch controller. Choose $$K\_i$$ to be a value in the range $$1%-10%$$ of $$K\_p$$.\
   **Caution**: Integral feedback, while improving steady-state response, introduces lag. Large values of integral gain, while reducing damping, can lead to loss of stability of the closed loop system.
5. Initially, set the feedforward gains ($$K\_{\theta-to-\psi}$$ and  $$K\_{\psi-to-\theta}$$) to 0, i.e., `ff_py = 0` and `ff_yp = 0` in the MATLAB code. Eventually, you will choose appropriate values for the feedforward gains such that the coupling effect is minimized. \
   \
   For example, choose $$K\_{\theta-to-\psi}$$ in Figure 1, to cancel the torque from the pitch rotor, i.e. , \
   &#x20;                                                          $$K\_{\theta-to-\psi} = \displaystyle - \frac{\overline{K}*{\psi\theta}}{\overline{K}*{\psi\psi}} \qquad \qquad (1)$$\
   Likewise, choose $$K\_{\psi-to-\theta}$$ to cancel the torque from the yaw rotor, i.e. ,\
   &#x20;                                                           $$K\_{\psi-to-\theta} = \displaystyle - \frac{\overline{K}*{\theta\psi}}{\overline{K}*{\theta\theta}} \qquad \qquad (2)$$\
   \
   Feedforward controller minimizes the coupling effects. Use Figure 1 as a reference for how to add the two feedforward paths.<br>

<figure><img src="https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2FuPbcYFZWglArS8neyR10%2FScreenshot%202023-02-13%20110454.png?alt=media&#x26;token=0a271029-8fc3-43f3-9ea6-409d31de970a" alt=""><figcaption><p>Figure 1: Feedforward controller architecture</p></figcaption></figure>

## Simulation Modelling and Evaluation

1. Create a SIMULINK model of the system. \
   (a) Create subsystem blocks representing the plant. Figure 2 shows separate pitch and yaw plants. **Note: Plants account for coupling (see Figures 3(a) and 3(b)).**\
   \
   (b) Create subsystem blocks representing the **decoupled** pitch and yaw controllers. Figure 2 shows the input/output structure of these blocks. \
   \
   (c) Using the completed subsystem blocks, finish the diagram of the closed-loop system. Make sure to include pitch and yaw inputs, saturation blocks, and appropriate outputs. Use scopes and *To Workspace* blocks so that reference, output, and response signals can be tracked. (Make sure to maintain consistency between deg and rad in SIMULINK)\
   \
   (d) Set the sampling time to Fixed-step of step-size 0.002s in Modeling -> Model Settings.&#x20;

<figure><img src="https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2FQZYfxBnCiamDyWnv6Gfu%2Fsim_diagram.png?alt=media&#x26;token=2588a07d-5a3a-4162-8e8b-c66e1b6f56d9" alt=""><figcaption><p>Figure 2: Controller, saturation, and Plant blocks from the SIMULINK diagram.</p></figcaption></figure>

<figure><img src="https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2FqQC01bPglLWjh7wscY3K%2F3a.png?alt=media&#x26;token=298e5335-3f10-4ec9-b00a-86a0a61e072d" alt=""><figcaption><p>Figure 3(a): Pitch plant Simulink block</p></figcaption></figure>

<figure><img src="https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2FmfQl93P4GzMtgyEwB8fn%2F3b.png?alt=media&#x26;token=e11fd803-8422-4a27-b3ac-40cb196aabae" alt=""><figcaption><p>Figure 3(b): Yaw plant Simulink block</p></figcaption></figure>

### **Decoupled Dynamics with Decoupled Controller**

First consider simulation validation of your controller using **decoupled dynamics and decoupled controller** (i.e., **no feedforward** between pitch and yaw channels).\
\
1\. Set the values of $$\overline{K}*{\theta\psi} = 0$$ in the pitch plant Simulink block and $$\overline{K}*{\psi\theta} = 0$$ in the yaw plant Simulink block. This will remove the coupling effects between pitch and yaw dynamics.\
\
2\. Set the integral gain of the pitch controller $$K\_i = 0$$.\
\
3\. Simulate the closed loop system response with yaw-only command:  $$\theta\_d = 0 \degree$$and  $$\psi\_d = 30 \degree$$. **Save** the data.\
\
4\. Check whether your controller meets the desired specifications for the yaw command. Since decoupled system dynamics are used in this step, you will likely see a close match between your simulation results and the desired specifications.\
\
5\. Set the integral gain of the pitch controller $$K\_i \approx 1% - 10%$$ of $$K\_p$$ (refer to Step 4 of [Controller Design](#controller-design)).\
\
6\. Simulate the closed loop system response with pitch-only command:  $$\theta\_d = 10 \degree$$and  $$\psi\_d = 0 \degree$$. **Save** the data.\
\
7\. Check if your pitch controller meets all the desired specifications. If it fails to meet the $$PO$$ and $$t\_p$$ specifications, **relax** the specifications and/or **tune** the pitch PID controller gains to try to meet the specifications. **Save** the tuned results.<br>

### Coupled Dynamics without Feedforward Controller

Next, consider the simulation evaluation of the feedback controller for the system with **coupled dynamics.**\
\
1\. Set the values of $$\overline{K}*{\theta\psi}$$ in the pitch plant Simulink block and $$\overline{K}*{\psi\theta}$$ in the yaw plant Simulink block to the [estimated values from Part A: System Identification](https://gtae.gitbook.io/ae4610/archive/2-dof-helicopter#analysis). This accounts for the coupled dynamics.\
\
2\. Simulate the closed-loop response of the system with pitch-only command: $$\theta\_d = 10 \degree$$and  $$\psi\_d = 0 \degree$$. **Save** the data.\
\
3\. Simulate the closed-loop response of the system with yaw-only command: $$\theta\_d = 0 \degree$$and  $$\psi\_d = 30 \degree$$. **Save** the data.\
\
4\. Simulate the closed-loop response of the system with simultaneous pitch and yaw commands: $$\theta\_d = 10 \degree$$and  $$\psi\_d = 30 \degree$$. **Save** the data.<br>

### Coupled Dynamics with Feedforward Controller

1. Set the feedforward gains $$K\_{\theta-to-\psi}$$ and  $$K\_{\psi-to-\theta}$$ based on Eqs. 1 and 2 (marked as `ff_py` and `ff_yp` in the MATLAB code). These gains are different from the normalized cross-thrust torque gains that you set to make the coupled dynamics.<br>
2. Simulate the closed-loop response of the system with pitch-only command: $$\theta\_d = 10 \degree$$and  $$\psi\_d = 0 \degree$$. **Save** the data.<br>
3. Simulate the closed-loop response of the system with yaw-only command: $$\theta\_d = 0 \degree$$and  $$\psi\_d = 30 \degree$$. **Save** the data.<br>
4. Simulate the closed-loop response of the system with simultaneous pitch and yaw commands: $$\theta\_d = 10 \degree$$and  $$\psi\_d = 30 \degree$$. **Save** the data.

## Results for Report

### (A) Simulation Modelling

Include a screenshot of the **complete SIMULINK model (block diagram)**. In addition, include the  following subsystem block diagram screenshots:

* Pitch and Yaw plants
* Pitch and Yaw controllers

### (B) Simulation Evaluation

#### i) [Decoupled Dynamics with Decoupled Controller](#decoupled-dynamics-with-decoupled-controller)

1. Mention the chosen design specifications values (Step 1 of [Controller Design](#controller-design)).
2. Mention the final yaw PD gains (Step 3).
3. **Yaw-only command case**: State if the design specifications were met, either including figures with design specs marked (Step 3) OR including a table with the $$PO\_{\psi}$$, $$t\_{p\_\psi}$$, $$e\_{ss\_\psi}$$ and $$\max |V\_\psi|$$values recorded from the response (Step 4).&#x20;
4. Mention the final tuned pitch PID gains (Step 7).
5. **Pitch-only command case**: State if the design specifications were met, either including figures with design specs marked (Step 7) OR including a table with the $$PO\_{\theta}$$, $$t\_{p\_\theta}$$, $$e\_{ss\_\theta}$$ and $$\max |V\_\theta|$$values recorded from the response (Step 7). &#x20;

#### ii) [Coupled Dynamics without Feedforward Controller](#coupled-dynamics-without-feedforward-controller)

1. **Pitch-only command case**: Plot the pitch and yaw data (commanded angles, simulation responses and motor input voltages) for pitch-only command (Step 2) and check if the design specifications were met in pitch.
2. **Yaw-only command case**: Plot the pitch and yaw data (commanded angles, simulation responses and motor input voltages) for yaw-only command (Step 3) and check if the design specifications were met in yaw.
3. **Pitch and yaw combined case**: State if the design specifications were met, either including figures with design specs marked (Step 4) OR including a table with the $$PO\_{\theta}$$, $$t\_{p\_\theta}$$, $$e\_{ss\_\theta}$$, $$\max |V\_\theta|$$, $$PO\_{\psi}$$, $$t\_{p\_\psi}$$, $$e\_{ss\_\psi}$$ and $$\max |V\_\psi|$$values recorded from the responses (Step 4).&#x20;

**Note:** It is possible that specifications are not met due to coupling between pitch and yaw dynamics.

#### ii) [Coupled Dynamics with Feedforward Controller](#coupled-dynamics-with-feedforward-controller)

1. Mention the feedforward gain values.
2. **Pitch-only command case**: Plot the pitch and yaw data (commanded angles, simulation responses and motor input voltages) for pitch-only command (Step 2) and check if the design specifications were met in pitch.
3. **Yaw-only command case**: Plot the pitch and yaw data (commanded angles, simulation responses and motor input voltages) for yaw-only command (Step 3) and check if the design specifications were met in yaw.
4. **Pitch and yaw combined case**: State if the design specifications were met, either including figures with design specs marked (Step 4) OR including a table with the $$PO\_{\theta}$$, $$t\_{p\_\theta}$$, $$e\_{ss\_\theta}$$, $$\max |V\_\theta|$$, $$PO\_{\psi}$$, $$t\_{p\_\psi}$$, $$e\_{ss\_\psi}$$ and $$\max |V\_\psi|$$values recorded from the responses (Step 4).

## Questions for Report

1. How does accounting for the coupling affect the performance of the controller? \
   (a) What happens when you neglect the coupling effect (in simulation)? \
   (b) What is a physical explanation for the coupling effect?
2. Why a PID controller is used for the pitch and a PD controller for the yaw?
3. Estimate gain and phase margins of the closed loop systems individually with your pitch and yaw controllers. **Hint:** Use the `margin` command in MATLAB. Gain and phase margins&#x20;
