Lab1 - Introduction To Analog Control Laboratory - 09-04-2018
Lab1 - Introduction To Analog Control Laboratory - 09-04-2018
MT311
Faculty of Engineering
Mechatronics Department
Lab1:
Introduction to Analog Control Laboratory
Eng Mohamed Doba
09 – 04 - 2018
Topics Covered In This Course:
Introduction:
- Course Plan.
- Overview of Matlab/Simulink.
System modeling in Matlab/Simulink.
System analysis in Matlab/Simulink.
Matlab/Simulink Control design using Root Locus method.
Matlab/Simulink Control design using Frequency response method.
Matlab/Simulink Control design using PID.
Real time hardware interface/control using Matlab/Simulink.
Matlab/Simulink Control design using auto-tuning and system identification (for systems not
having mathematical models).
Some of the Systems used in this course:
Term Project:
Pick a system of your choice, and do the following:
System Modeling (mathematical or experimental) using Matlab.
System analysis using Matlab.
Control system designing (by using any method covered in the course).
Quizzes
Overview of Matlab and Simulink.
First: Overview of Matlab
Overview of Matlab
Variable Assignment. Polynomials.
Element-wise operator.
Others.
Help.
Right and left division.
Matlab Cheat sheet.
Scalar, vector and matrix functions.
Complex numbers.
M-Files
Scripts.
Functions.
Plotting
Conditionals and loops.
Timing.
Animation.
Polynomials.
Overview of Matlab - Assignment
Single Variable assignment.
A row vector – values are separated by spaces or comma (,).
A column vector – values are separated by semi–colon (;).
Matrices: Combination of row and column are created using the combination of the
previous rules, for each new row item put(spaces or comma (,)) and for each now column
put (semi–colon (;)).
a = linspace(0,(2*pi),100);
colon notation: If we want to construct a vector of, elements between 0 and 2 with a step
size of 0.1
b = 0:0.1:2;
Overview of Matlab – Matrix manipulation
1 2 3
6 5 4
7 8 9
Overview of Matlab - Matrix manipulation
element–wise operator (.)
element–wise operator:
Performing operations to every entry in a matrix.
1 2 3 1 1 1 14 14 14
4 5 6 2 2 2 = 32 32 32
A*B 7 8 9 3 3 3 50 50 50
ans = ans =
A= B= B= A=
1 2 3 2 3 2 1 2 3
2 2 1 1 1 1 4 5 6
7 8 9
>> sin(A) >> max(B) >> max(B, [],2)
ans = ans = ans = >> size(A)
0.8415 0.9093 3 ans =
0.9093 0.9093 3 2 1 3 3
Overview of Matlab – Complex numbers
[i] is one of the special variables used to represent complex >> c = 1+i
Number. c =
1.0000 + 1.0000i
To find the value of complex number use [abs].
To find the value of complex number use [angle].
>> abs(c)
ans =
1.4142
>> angle(c)*(180/pi)
ans =
45
Overview of Matlab - Matrix manipulation
-j5
Example-1:
Solve for V1 and V2 ?
V1 V2
>> solution j10
2-90o 10 1.50o
solution =
14.0000+ 8.0000i
28.0000+ 1.0000i
(0.1 + j0.2)V1 – j0.2V2 = -j2
- j0.2V1 + j0.1V2 = 1.5
M-files
Script Function
Collections of commands User defined commands
R = 10 C
Solution:
120
Z
+
Xc
100 Xl
V
L
80 –
60
40
20
1
Z R j L
0
0 200 400 600 800 1000 1200 1400 1600 1800 2000
C
Overview of Matlab – Conditionals and loops:
You can loop over sections of code and conditionally execute sections using the keywords:
[for, while, if, switch].
for n = 0:0.25:7
t = 0:0.25:n;
y = sin(t);
plot(t,y)
title('Sine Wave as a Function of Time')
xlabel('Time (secs)')
ylabel('Amplitude')
axis([0 7 -1 1])
pause(0.1)
end
Overview of Matlab - Animation:
Example-3:
Animation of sine function ?
Overview of Matlab - Polynomials:
Polynomials as Vectors
p = [1 3 -15 -2 9];
Function is a ‘black box’ that communicates with workspace through input and output
variables.
Every function must begin with a header:
function output = function_name (inputs)
function dx = mydiff(t, x)
T = 5;
dx = - 1 / T * x;
end
To find the solution of the differential equation and plot the solution (i(t)):
span_t = [0 25];
x0 = 1;
[t, x ] = ode23(@mydiff, span_t , x0);
plot(t, x)
Overview of Matlab - Others
Some special variables[inf, nan, pi]. >> 1/0
Utility functions to deal with inf: ans =
ex. [isinf, finite] Inf
>> x = log(0);
>> isinf(x)
>> x = 0/0
ans =
x =
1
NaN
ans = 3.1416
1
Overview of Matlab - Help
There are several general classes of blocks within the Simulink library:
Sources: used to generate various signals.
Sinks: used to output or display signals.
Continuous: continuous-time system elements (transfer functions, state-space
models, PID controllers, etc.)
Math Operations: contains many common math operations (gain, sum, product,
absolute value, etc.)
Overview of Simulink – Simple example:
Only two blocks: source and sink.
Overview of Simulink – Animation in Simulink:
¨ 𝑔
𝜃=− ∗ sin (𝜃)
𝑙
Simscape Toolbox:
can simulated the dynamic of the system
and give animation without equation.
Overview of Simulink - Help:
References:
https://www.mathworks.com/help/index.html
http://ctms.engin.umich.edu/CTMS/index.php
Any Questions ?!