> For the complete documentation index, see [llms.txt](https://gtae.gitbook.io/ae4610/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gtae.gitbook.io/ae4610/archive/2-dof-aero/c.-controller-implementation.md).

# C. Controller Implementation

## Background

In this section, the controller design from section B is implemented on the physical Quanser Aero hardware. We desire to reproduce the simulation results from the controller design section. The performance specifications are identical. Download Part C Aero.zip file and unzip to your folder containing the Control Design setup MATLAB script.

{% file src="/files/E99n9I7tIUtSJDhCIX84" %}

## Experiments

### 1. Pitch Controller (1DOF)

1. Unlock pitch axis and lock yaw axis.
2. Open **q\_aero\_2dof\_PID.slx**.
3. Set pitch controller PID gains to the values obtained in Step 7 of the [Decoupled Dynamics with Decoupled Controller](/ae4610/archive/2-dof-aero/b.-control-design.md#decoupled-dynamics-with-decoupled-controller) section under [Simulation Modeling and Evaluation](/ae4610/archive/2-dof-aero/b.-control-design.md#simulation-modelling-and-evaluation) in [Part B: Controller Design](/ae4610/archive/2-dof-aero/b.-control-design.md). If variables are in the workspace, you may directly put gain values into the variables.
4. Set yaw controller PD gains and feedforward controller gains to 0.
5. Apply a pitch-only command ( $$\theta\_d = 10 \degree$$, $$\psi\_d = 0 \degree$$).
6. Run SIMULINK: To build the model, click down arrow on **Monitor & Tune** under Hardware tab and then **Build** **for monitoring** ![](https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2FCq5iMDIRj3JN7fcFsx2w%2Fimage.png?alt=media\&token=6ffaf234-92d6-4de2-be27-7a37a4fe9dcc).  This generates the controller code. Click **Connect** <img src="https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2F1VD5IqnbVgR6hbi4YOei%2Fimage.png?alt=media&amp;token=02e68127-9611-4c74-b03f-b7cac5c04a34" alt="" data-size="line"> button under Monitor & Tune and then click **Start** <img src="https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2F5kUOzUmpIz5Mob4x7xd1%2Fimage.png?alt=media&amp;token=60cb4298-b97c-4538-8240-2d44c2d721b0" alt="" data-size="line">.
7. GET DATA OUT!!! and **save** it as `pitch_only.mat`.

### 2. Yaw Controller (1DOF)

1. Unlock yaw axis and lock pitch axis.
2. Implement yaw PD controller using the gains tested in Step 3 of the [Decoupled Dynamics with Decoupled Controller](/ae4610/archive/2-dof-aero/b.-control-design.md#decoupled-dynamics-with-decoupled-controller) section under [Simulation Modeling and Evaluation](/ae4610/archive/2-dof-aero/b.-control-design.md#simulation-modelling-and-evaluation) in [Part B: Controller Design](/ae4610/archive/2-dof-aero/b.-control-design.md).
3. Set pitch controller PID gains and feedforward controller gains to 0.
4. Apply a pitch-only command ( $$\theta\_d = 0 \degree$$, $$\psi\_d = 30 \degree$$).
5. Run SIMULINK.
6. GET DATA OUT!!! and **save** it as `yaw_only.mat`.

### 3. Pitch and Yaw Controllers without Feedforward Control (2DOF)

1. Unlock both pitch and yaw axes to enable the full 2 DOF motion.
2. Implement the PID and PID gains in pitch and yaw controllers respectively. Set feedforward gains to zero.
3. Apply simultaneous pitch and yaw commands ( $$\theta\_d = 10 \degree$$, $$\psi\_d = 30 \degree$$).
4. Run SIMULINK.
5. GET DATA OUT!!! and **save** it as `pitch_yaw.mat`.&#x20;

### 4. Pitch and Yaw Controllers with Feedforward Control (2DOF)

1. Set the feedforward gains to the values in Step 1 of the [Coupled Dynamics with Feedforward Controller](/ae4610/archive/2-dof-aero/b.-control-design.md#coupled-dynamics-with-feedforward-controller) section under [Simulation Modeling and Evaluation](/ae4610/archive/2-dof-aero/b.-control-design.md#simulation-modelling-and-evaluation) in [Part B: Controller Design](/ae4610/archive/2-dof-aero/b.-control-design.md).&#x20;
2. Repeat the pitch+yaw experiment with simultaneous pitch and yaw commands ( $$\theta\_d = 10 \degree$$, $$\psi\_d = 30 \degree$$).
3. **Save** data as `ff_pitch_yaw.mat`.
4. Close SIMULINK. DO NOT SAVE THE CHANGES!

{% hint style="info" %}
For all the experiments, the data is saved in the following order:

1. Time (s)
2. Voltage input to pitch rotor motor $$V\_p$$ or $$V\_\theta$$ (V)
3. Voltage input to yaw rotor motor $$V\_y$$ or $$V\_\psi$$ (V)
4. Pitch command angle $$\theta\_c$$ (deg)
5. Yaw command angle $$\psi\_c$$ (deg)
6. Pitch angle response $$\theta$$ (deg)
7. Yaw angle response $$\psi$$ (deg)
8. Pitch speed $$\dot{\theta}$$ (rad/s)
9. Yaw speed $$\dot{\psi}$$ (rad/s)
   {% endhint %}

## Results for Report

**Note:** Some results require simulation response. This would require **running a simulation** using your **SIMULINK model** from [Part B Control Design](/ae4610/archive/2-dof-aero/b.-control-design.md#simulation-modelling-and-evaluation) using the parameter values determined in [Part A System Identification](/ae4610/archive/2-dof-aero/2-dof-helicopter.md#analysis). The command input will be identical to the step input implemented during the experiment.

### (A) Decoupled Pitch Controller&#x20;

1. Plot and compare the experimental results obtained for the [decoupled pitch-only case](#1.-pitch-controller-1dof) with the corresponding [decoupled dynamics with decoupled controller simulation results from Part B Control Design](/ae4610/archive/2-dof-aero/b.-control-design.md#decoupled-dynamics-with-decoupled-controller):
   * Pitch command, pitch experimental response and pitch simulation response (one figure)
   * Voltage input to pitch rotor motor experiment and simulation results (one figure)
2. Explain any differences between the experimental and simulation results.

### (B) Decoupled Yaw Controller&#x20;

1. Plot and compare the experimental results obtained for the [decoupled yaw-only case](#2.-yaw-controller-1dof) with the corresponding [decoupled dynamics with decoupled controller simulation results from Part B Control Design](/ae4610/archive/2-dof-aero/b.-control-design.md#decoupled-dynamics-with-decoupled-controller):
   * Yaw command, yaw experimental response and yaw simulation response (one figure)
   * Voltage input to yaw rotor motor experiment and simulation results (one figure)
2. Explain any differences between the experimental and simulation results.

### (C) Combined Pitch and Yaw Controllers without Feedforward Control &#x20;

1. Plot and compare the experimental results obtained for the [combined pitch and yaw case](#3.-pitch-and-yaw-controllers-without-feedforward-control-2dof) with the corresponding [coupled dynamics without feedforward controller simulation results from Part B Control Design](/ae4610/archive/2-dof-aero/b.-control-design.md#coupled-dynamics-with-decoupled-controller):
   * Pitch command, pitch experimental response and pitch simulation response (one figure)
   * Yaw command, yaw experimental response and yaw simulation response (one figure)
   * Pitch rotor motor voltage experiment and simulation results (one figure)
   * Yaw rotor motor voltage experiment and simulation results (one figure)
2. Explain any differences between the experimental and simulation results.

### (D) Combined Pitch and Yaw Controllers with Feedforward Control &#x20;

1. Plot and compare the experimental results obtained for the [combined pitch and yaw case (including feedforward control)](#4.-pitch-and-yaw-controllers-with-feedforward-control-2dof) with the corresponding [coupled dynamics with feedforward controller simulation results from Part B Control Design](/ae4610/archive/2-dof-aero/b.-control-design.md#coupled-dynamics-with-feedforward-controller):
   * Pitch command, pitch experimental response and pitch simulation response (one figure)
   * Yaw command, yaw experimental response and yaw simulation response (one figure)
   * Pitch rotor motor voltage experiment and simulation results (one figure)
   * Yaw rotor motor voltage experiment and simulation results (one figure)
2. Explain any differences between the experimental and simulation results.

## Questions for Report

1. How does introducing feedforward gains affect the response of system? (i.e. compare pitch and yaw response without feedforward control with the responses with feedforward).
2. Did your controller successfully meet the specifications while running on the Quanser Aero hardware? If not, why?
