0% found this document useful (0 votes)
52 views40 pages

Lab1 - Introduction To Analog Control Laboratory - 09-04-2018

The document is a lab introduction for an analog control systems course. It provides an overview of the topics that will be covered in the course, including modeling and analysis of systems in Matlab/Simulink, various control design methods using Matlab/Simulink, and interfacing real hardware. It lists some example systems that will be used like DC motors, spring-damper systems, and vehicles. Students will complete a term project applying the course concepts to a system of their choice. The document also provides an introduction to Matlab, covering basics like variables, matrices, plotting, and functions as well as control-specific topics like modeling and analysis tools.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views40 pages

Lab1 - Introduction To Analog Control Laboratory - 09-04-2018

The document is a lab introduction for an analog control systems course. It provides an overview of the topics that will be covered in the course, including modeling and analysis of systems in Matlab/Simulink, various control design methods using Matlab/Simulink, and interfacing real hardware. It lists some example systems that will be used like DC motors, spring-damper systems, and vehicles. Students will complete a term project applying the course concepts to a system of their choice. The document also provides an introduction to Matlab, covering basics like variables, matrices, plotting, and functions as well as control-specific topics like modeling and analysis tools.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

University of Sana’a Analog Control System

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:

 Dc motor. (Main system)


 Spring – damper system.
 Electric circuits.
 Analogue Electronics.
 Vehicle (cruise control).
 Car Suspension.
 Inverted pendulum.
 Aircraft Pitch.
 Ball and Beam.
 Quad-copter.
The systems that is not covered in the course are going to be the final projects for the students.
Course Requirement:

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).

The project can be delivered as hardware or simulation.

Quizzes
Overview of Matlab and Simulink.
First: Overview of Matlab
Overview of Matlab
 Variable Assignment.  Polynomials.

 Matrix manipulation.  Differential equations.

 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 (;)).

>> v=3 >> A = [1 2 3 4 5] >> B = [10;12;14;16] >> C = [1 2 3 ; 4 5 6 ; 7 8 9]


v= A =
B =
1 2 3 4 5
3 10 C =
>>> A = [1,2,3,4,5] 12
A =
1 2 3 4 5 14 1 2 3
16 4 5 6
7 8 9
Overview of Matlab - Assignment
 Linspace: If we want to construct a vector of, say, 100 elements between 0 and 2*pi.

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

 Arithmetic operations – Add and subtract.

>> A+3 >> A-2


ans =
 1 2 3
ans =
-1 0 1 A=  4 5 6
4 5 6
7 8 9 2 3 4
 
10 11 12 5 6 7
7 8 9

 Arithmetic operations – Multiply and divide.

>> A*2 >> A/3


ans =
 1 2 3
ans =
0.3333 0.6667 1.0000 A=  4 5 6
2 4 6
8 10 12 1.3333 1.6667 2.0000
 
14 16 18 2.3333 2.6667 3.0000
7 8 9
Overview of Matlab – Matrix manipulation

 Access elements in a matrix or a vector.

>> A(2,3) >> A(:,3)


ans = ans =
6 3 1 2 3
6 A=  4 5 6
9  
>> A(1,:) 7 8 9
ans = >> A(2,:)= [6 5 4]
1 2 3 A =

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 

 1x1 2x1 3x1  1 2 3


 4 x 2 5 x 2 6 x 2  8 10 12 
A.*B  
=  
 7 x3 8x3 9 x3 21 24 27 
Overview of Matlab - Matrix manipulation
element–wise operator (.)
element–wise operator and other operators : >> A=[1 2 3;4 5 6;7 8 9]
A=
1 2 3
4 5 6
7 8 9

>> c=[1 2]; >> A.^2


>> d=[3 4]; ans =
>> c*d 1 4 9
16 25 36
??? Error using _*_
49 64 81
times
Matrix dimensions must >> A^2
agree. ans =
30 36 42
A^2 = A * A 66 81 96
102 126 150
Overview of Matlab - Matrix manipulation
Matrices (Divide and element-wise operator)
>> 8/2
 The right division: the conventional division we all day use. ans =
4
 The left division: Contrary to the right division, the left division reverse the division.
>> 8\2
ans =
Using element by element division 0.2500

>> A./B >> A.\B

ans = ans =

0.3333 1.0000 3.0000 1.0000


Using the left division 2.0000 2.0000 0.5000 0.5000
Overview of Matlab – Scalar, vector and matrix functions:
 Scalar functions – used for scalars and operate element-wise
when applied to a matrix or vector:
e.g. sin - cos – tan - atan – asin
abs - angle –sqrt
 Vector functions – operate on vectors returning scalar value:
e.g. max – min – mean – prod – sum – length
 Matrix functions – perform operations on matrices:
e.g. Size – inv – det

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.50o
solution =
14.0000+ 8.0000i
28.0000+ 1.0000i
(0.1 + j0.2)V1 – j0.2V2 = -j2
- j0.2V1 + j0.1V2 = 1.5

0.1  j 0.2  j 0.2  V1   j2


  j 0.2 j 0.1  V2  =  1.5 

A x = y
Overview of Matlab – M-Files
 Script and function files.

M-files

Script Function
Collections of commands User defined commands

Executed in sequence when called Normally has input & output

Saved with extension “.m”


Saved with extension “.m”
Overview of Matlab - Plotting:
t = 0:0.25:7;
y = sin(t); [X,Y] = meshgrid(-2:.2:2);
plot(t,y)
title('Sine Wave as a Function of Time') Z = X .* exp(-X.^2 - Y.^2);
xlabel('Time (secs)') surf(X,Y,Z)
ylabel('Amplitude')
Overview of Matlab – M-Files & plotting
Example-2:
 RLC circuit
Write an m–file to plot Z, Xc and XL versus frequency for R =10, C = 100 uF, L = 0.01 H.

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 v = 1.0:-0.2:0.0 n = 10;


f = n;
disp(v) while n > 1
end n = n-1;
f = f*n;
end n = input('Enter a number: ');
disp(['n! = ' num2str(f)])
switch n
case -1
disp('negative one')
if overallMean < .49 case 0
disp('Mean is less than expected') disp('zero')
elseif overallMean > .51 case 1
disp('Mean is greater than expected') disp('positive one')
else otherwise
disp('Mean is within the expected range') disp('other value')
end end
Overview of Matlab - Animation:
Overview of Matlab - Animation:
 Animation plot of sine function as t change from 0 to 7s:

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];

 To find the value of the above polynomial at s = 2.


poly_val = polyval( p ,2)

 Finding the roots would be as easy as entering the following command:


s = roots( p )

 Multiply two polynomials together:


x = [1 2];
y = [1 4 8];
z = conv(x,y)
Overview of Matlab – M-files Functions

 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)

Output variable Must match the file name


input variable

function f = fact(n) >> fact(5)


f = prod(1:n); ans =
end 120
Overview of Matlab – Differential equations:
 Create function that represent the differential
Equation of the system and save it as m file

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

 Utility functions to deal with NaN: >> pi


ex. [isnan]
>> isnan(0/0) ans =

ans = 3.1416

1
Overview of Matlab - Help

>> doc sin


 Use word [doc]:

 Use word [help]: >> help sin

 Tutorials in the Matlab documentation:


Getting started with Matlab.
Language fundamentals.
Matlab Cheat sheet
Second: Overview of Simulink
Overview of Simulink :
 Basic Elements.
 Simple Example.
 Animation in Simulink.
 Help in Simulink.
Overview of Simulink - Basic Elements:
 There are two major classes of items in Simulink:
blocks and lines.
 Blocks are used to generate, modify, combine, output, and display signals.
 Lines are used to transfer signals from one block to another.
Overview of Simulink - Basic Elements - blocks:

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:

 Pendulum differential equation.

 ¨ 𝑔
𝜃=− ∗ sin ⁡(𝜃)
𝑙

 Simscape Toolbox:
can simulated the dynamic of the system
and give animation without equation.
Overview of Simulink - Help:

 For  on-line help, type:


help commandname
doc scope

 Getting Started with Simulink :


Next lab:

Requirement from the students:


 Quiz to test your understanding for this lab

Subjects in the next lab:


 Dc motor – modeling and analysis in Matlab/Simulink
Files Associated with Lab1:

 Control Tutorials for MATLAB and Simulink - MATLAB Basics Tutorial.pdf


 Control Tutorials for MATLAB and Simulink - Simulink Basics Tutorial.pdf
 Matlab/Simulink files.
 Other resources:
- Matlab documentation.
- Simulink documentation.
- Matlab Cheat sheet.

References:
 https://www.mathworks.com/help/index.html
 http://ctms.engin.umich.edu/CTMS/index.php
Any Questions ?!

By: Mohamed Doba


fb.com/mnb.doba

You might also like