# D. Controller Implementation & Evaluation (Week 3)

## Objectives

The objective of this part of the DC motor experiment is to implement the controller designed in part B and evaluate its performance.

## Equipment Required

The following is a list of the required equipment to perform this experiment:

* [ ] Q8-USB or Q2-USB interface board

* [ ] MATLAB and SIMULINK software

* [ ] Servo Base<br>

{% file src="<https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2FaJBAvWYoYIjOPivD4r1d%2Fq_servo_pos_cntrl.slx?alt=media&token=7768ba57-2158-49aa-8068-2c6a206ccb5c>" %}

## Controller Implementation

### 1. Step Response Experiments

1. Open `q_servo_pos_cntrl.slx` file. Do not change anything except the PID gains.

2. Double-click on the Signal Generator and ensure that the following parameters are set to generate a square wave (i.e. step reference):
   * Signal Type = *square*
   * Amplitude = 1
   * Frequency = 0.4 Hz

3. In the Simulink diagram, set the Amplitude gain block to 0.2 and the Constant offset gain block to 0.2. Note that these gain blocks outside the Signal Generator block are introduced to generate the square wave with amplitude limits of 0 V and 0.4 V.

4. Check that the sampling time is set to 0.002 s (located under “Modeling” -> “Model Settings” -> “Solver Details”).

5. ***P Controller Test***: To understand the behavior of a Proportional controller, implement a P controller by typing the values for $$K\_d$$ to 0 and $$K\_i$$ to 0 in the command window. Set $$K\_p$$ as the value obtained in [Step 5 of Part C Control Design](https://gtae.gitbook.io/ae4610/dc-servomotor#a-from-step-5).

6. Turn on the power amplifier.

7. 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).&#x20;

8. Open the position scope.

9. Press **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&#x26;token=02e68127-9611-4c74-b03f-b7cac5c04a34" alt="" data-size="line"> button under Monitor & Tune and then press **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&#x26;token=60cb4298-b97c-4538-8240-2d44c2d721b0" alt="" data-size="line">. Run the experiment for 5 seconds.

10. **Save** your data. No need to Build again unless you change any blocks or configuration settings in the model.

11. ***PD Controller Test***: By introducing a derivative gain ($$K\_d$$), notice how the system characteristics change. Set $$K\_p$$ and $$K\_d$$ to the respective values found in [Step 6 of Part C Control Design](https://gtae.gitbook.io/ae4610/dc-servomotor#b-from-step-6).  $$K\_i$$ will remain as 0. Connect and Start. Observe the behavior and **save** the data.

12. ***Sampling Time Test***: Change the sampling time to 0.04 sec. To set the sampling time, you need to go to the block diagram file, and choose “Modeling” -> “Model Settings” -> “Solver Details”. Set the fixed step to 0.04 sec (it should have been 0.002 previously). Build, connect and Run PD Controller, observe the behaviour and **save** the data with an appropriate filename (e.g. -  *PD\_sampling\_0.04).*

### 2. Ramp Response Experiments

1. Double-click on the Signal Generator and set the following parameters to generate a triangular wave (i.e. ramp reference):
   * Signal Type = *triangle*
   * Amplitude = 1
   * Frequency = 0.4 Hz
2. In the Simulink diagram, set the Amplitude gain block to $$\pi/6$$ and the Constant offset gain block to $$\pi/6$$. This will generate a triangular wave with amplitude between 0 to $$60^{\circ}$$.
3. Change the sampling time back to 0.002 sec (“Modeling” -> “Model Settings” -> “Solver Details”).&#x20;
4. ***PD Controller Test***: This test is to determine the ramp response of the system with a PD controller. Set $$K\_p$$ and $$K\_d$$ to the respective values found in [Step 6 of Part C Control Design](https://gtae.gitbook.io/ae4610/dc-servomotor#b-from-step-6).  $$K\_i$$ will remain as 0. Connect and Start. Observe the behavior and **save** the data.
5. ***PID Controller Test***: In the respective controller gain blocks, change the current values of $$K\_p$$, $$K\_d$$ and $$K\_i$$ to the PID values found in [Step 9 of Part C Control Design](https://gtae.gitbook.io/ae4610/dc-servomotor#c-from-step-9). **Save** the data.
6. Repeat the PID controller test with double the gain value for $$K\_i$$ while keeping the same values of $$K\_p$$ and $$K\_d$$,  and **save** the data.

Results and Questions for Report

**Note**: Some results require simulation response. This would require **running a simulation** using your **SIMULINK model** from Part C Control Design using the **model validation K and tau** values. The command input will be identical to either the square wave signal or the triangle wave signal implemented during the experiment. The attributes of the simulation will be mentioned in the corresponding section.

### (A) Step Response

Any simulation results in this subsection will have the following attributes:

* *Command input*: Square wave
  * *Amplitude*: Maximum of 0.4 and minimum of 0
  * *Frequency*: 0.4 Hz
* *Sampling time*: 0.002 s (Go to "Modeling" -> "Model Settings" -> "Solver details" -> "Fixed-step size")

You may generate the command input either using the Signal Generator block or by using the corresponding command input data saved in the Step Response experiments.

#### i) P Controller

1. Plot angle or rotary position, i.e., commanded, experimental from Step 1.10, and simulation responses on one figure. Use the same $$K\_p$$ gain value evaluated in Step 1.5 for the simulation response.
2. What is the effect of proportional controller gain on closed-loop system behaviour?

#### ii) PD Controller

1. Plot angle or rotary position, i.e., commanded, experimental from Step 1.11, and simulation responses on one figure. Use the same $$K\_p$$ and $$K\_d$$  gain values evaluated in Step 1.11 for the simulation response.
2. What is the effect of derivative controller gain on closed-loop system behaviour?
3. Compare the PD simulation (that shows zero steady-state error) and experimental (that shows a steady-state error) results to also discuss regarding the dead zone in the DC motor and how it affects the steady-state error.&#x20;

#### iii) Sampling Time

1. Plot angle or rotary position (commanded and experimental) and control input Vm from Step 1.12.
2. What is the effect of sampling time on closed-loop system behaviour?

### (B) Ramp Response

Any simulation results in this subsection will have the following attributes:

* *Command input*: Triangle wave
  * *Amplitude*: Maximum of $$\pi/3$$ and minimum of 0
  * *Frequency*: 0.4 Hz
* *Sampling time*: 0.002 s (Go to "Modeling" -> "Model Settings" -> "Solver details" -> "Fixed-step size")

You may generate the command input either using the Repeating Sequence block or by using the corresponding command input data saved in the Ramp Response experiments.

#### i) PD Controller

1. Plot angle or rotary position, i.e., commanded, experimental from Step 2.3, and simulation responses on one figure. Use the same $$K\_p$$ and $$K\_d$$  gain values evaluated in Step 2.4 for the simulation response.

#### iii) PID Controller

1. Plot angle or rotary position, i.e., commanded, experimental from Step 2.5 (or 2.4 if applicable), and simulation responses on one figure. Use the tuned $$K\_p$$, $$K\_d$$  and  $$K\_i$$ gain values evaluated in Step 2.6 for the simulation response.
2. Mention the final PID gains after tuning.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gtae.gitbook.io/ae4610/lab-1-rotary-servo-base/dc-servomotor-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
