# Old Lab 1 Model Validation

## Model Validation Experiment

In this experiment, you will adjust the model parameters you found in the previous experiments to tune the transfer function. Our goal is to match the simulated system response with the parameters you found as closely as possible to the response of the actual system. To create a step input:

1. Double-click on the Signal Generator block and ensure the following parameters are set: \
   • Wave form: square \
   • Amplitude: 1.0 \
   • Frequency: 0.4 \
   • Units: Hertz
2. Set the *`Amplitude (V)`* slider gain to 1.0 V.
3. Set the *`Offset (V)`* block to 1.5 V.
4. Set the Simulation stop time to 5 seconds.
5. Open the load shaft speed scope, `Speed (rad/s)`, and the motor input voltage scope, *`V_m (V)`*.
6. To build the model, click the down arrow on **Monitor & Tune** under the Hardware tab and then click **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.
7. 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&#x26;token=02e68127-9611-4c74-b03f-b7cac5c04a34" alt="" data-size="line"> button under **Monitor & Tune** and then run SIMULINK by clicking **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">.
8. The gears on the Rotary Servo Base Unit should be rotating in the same direction and alternating between low and high speeds and the scopes should be as shown in Figure 15 a) and b). \
   \
   Recall that the yellow trace is the measured load shaft rate and the purple trace is the simulated trace. By default, the steady-state gain and the time constant of the transfer function used in simulation are set to: K = 1 rad/s/V and $$\tau$$ = 0.1s. These model parameters do not accurately represent the system.<br>

   <figure><img src="https://1205030739-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MIedmBPpkGaOOtNl4mm%2Fuploads%2FQQBd0eKNKqCBKxz7TiXo%2F35.png?alt=media&#x26;token=43c6253b-7f8e-432d-a8c8-0834e873c874" alt=""><figcaption><p>Figure 15 Simulation done with default model parameters: K = 1 and <span class="math">\tau</span> = 0.1Save wl data and name it something like modeling_section#_Group#_K1tau01.<br></p></figcaption></figure>
9. **Save** wl data and name it as modeling\_section#\_Group#\_K1tau01.
10. Enter the command K = 1.25 in the MATLAB Command Window.
11. Update the parameters used by the Transfer Function block in the simulation by updating diagram in the q\_servo\_modeling SIMULINK diagram. \
    \ <mark style="background-color:green;">To update the diagram, from the</mark> <mark style="background-color:green;"></mark><mark style="background-color:green;">**Modeling**</mark> <mark style="background-color:green;"></mark><mark style="background-color:green;">tab, click</mark> <mark style="background-color:green;"></mark><mark style="background-color:green;">**Update Model**</mark><mark style="background-color:green;">. Alternatively, press</mark> <mark style="background-color:green;"></mark><mark style="background-color:green;">**Ctrl+D**</mark><mark style="background-color:green;">.</mark>\
    \
    Connect and run the SIMULINK model and observe how the simulation response changes. Remember we have increased K from 1 to 1.25.
12. **Save** wl data and name it as modeling\_section#\_Group#\_K125tau01.
13. Enter the command *`tau = 0.2`* in the MATLAB Command Window.
14. Update the simulation again by updating diagram.\
    \
    Connect and run the SIMULINK model and observe how the simulation response changes. Remember we have increased $$\tau$$ from 0.1 to 0.2.
15. **Save** wl data and name it as modeling\_section#\_Group#\_K125tau02.
16. Calculate the nominal values, $$K$$ and $$\tau$$ , using Eqs. 2.1, 2.26, 2.27, 2.28 and the specifications provided in [Table A.1](#table-a.1-main-rotary-servo-base-unit-specifications) and [Table A.2](#table-a.2-rotary-servo-base-unit-gearhead-specifications) for the **high-gear configuration**.\
    \
    **Note:** Eq. 2.26 must be converted to the Laplace domain to obtain the transfer function, which should be simplified to resemble Eq. 2.1. This would yield the formulae to determine $$K$$ and $$\tau$$. You may also refer to the lecture slides.<br>
17. Enter the nominal values, $$K$$ and $$\tau$$ , that were found in Step 16 in the MATALB Command Window. Update the parameters and examine how well the simulated response matches the measured one.
18. **Save** wl data and name it as modeling\_section#\_Group#\_K#tau#.\
    \
    If the calculations of the nominal values were done properly, then the model should represent the actual system quite well. However, there are always some differences between each servo unit and, as a result, the model can always be tuned to match the system better. <mark style="background-color:yellow;">Try</mark> <mark style="background-color:yellow;"></mark><mark style="background-color:yellow;">**varying the model parameters**</mark> <mark style="background-color:yellow;"></mark><mark style="background-color:yellow;">(different</mark> $$K$$ <mark style="background-color:yellow;">and</mark> $$\tau$$ <mark style="background-color:yellow;">values) until the simulated trace matches the measured response better. Enter these tuned values under the Model Validation section of</mark> [<mark style="background-color:yellow;">Table B.2</mark>](#table-b.2-summary-of-results-for-the-rotary-servo-base-unit-modeling-laboratory.)<mark style="background-color:yellow;">.</mark>\
    \
    **If the model parameters are changed**, **save** the data for the final set of tuned parameters.\
    \
    **Note:** Tuning the model parameters can be done by manually changing the Servo Model Transfer Function block parameters OR by changing the *`K`* and *`tau`* parameters in the MATLAB Command Window and going to Simulation | Update Diagram in the SIMULINK model.
