Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

MATLAB Experiment Guide

The document is a MATLAB experiment guide focused on control techniques for mechatronic systems, detailing the use of Simulink and transfer functions. It covers various aspects including transfer function representation, time domain analysis, stability analysis, transient performance, steady-state error analysis, and root locus techniques. The guide provides examples and MATLAB code snippets for practical implementation of these concepts.

Uploaded by

sunshiqi31
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

MATLAB Experiment Guide

The document is a MATLAB experiment guide focused on control techniques for mechatronic systems, detailing the use of Simulink and transfer functions. It covers various aspects including transfer function representation, time domain analysis, stability analysis, transient performance, steady-state error analysis, and root locus techniques. The guide provides examples and MATLAB code snippets for practical implementation of these concepts.

Uploaded by

sunshiqi31
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Control Techniques for Mechatronical Systems

MATLAB Experiment Guide


1 Simulink
2 Transfer function
2.1 The rational true fraction of the transfer function
𝑪𝑪(𝒔𝒔) 𝒃𝒃𝒎𝒎 𝒔𝒔𝒎𝒎 + 𝒃𝒃𝒎𝒎−𝟏𝟏 𝒔𝒔𝒎𝒎−𝟏𝟏 + ⋯ + 𝒃𝒃𝟏𝟏 𝒔𝒔 + 𝒃𝒃𝟎𝟎
𝑮𝑮(𝒔𝒔) = =
𝑹𝑹(𝒔𝒔) 𝒂𝒂𝒏𝒏 𝒔𝒔𝒏𝒏 + 𝒂𝒂𝒏𝒏−𝟏𝟏 𝒔𝒔𝒏𝒏−𝟏𝟏 + ⋯ + 𝒂𝒂𝟏𝟏 𝒔𝒔 + 𝒂𝒂𝟎𝟎
num1 = [2, 1];
den1 = [1, 2, 2, 1];
sys1 = tf(num1, den1)
sys1 =

2 s + 1
---------------------
s^3 + 2 s^2 + 2 s + 1

Continuous-time transfer function.

2.2 Zero-pole form of the transfer function


(𝒔𝒔 − 𝒛𝒛𝟏𝟏 )(𝒔𝒔 − 𝒛𝒛𝟐𝟐 ) ⋯ (𝒔𝒔 − 𝒛𝒛𝒎𝒎 )
𝑮𝑮(𝒔𝒔) = 𝑲𝑲∗
(𝒔𝒔 − 𝒑𝒑𝟏𝟏 )(𝒔𝒔 − 𝒑𝒑𝟐𝟐 ) ⋯ (𝒔𝒔 − 𝒑𝒑𝒏𝒏 )
zeros = 0;
poles = [1-1i, 1+1i, 2];
k = 2;
sys2 = zpk(zeros, poles, k)
sys2 =

2 s
--------------------
(s-2) (s^2 - 2s + 2)

Continuous-time zero/pole/gain model.

2.3 Conversion between models


num1 = [2, 1];
den1 = [1, 2, 2, 1];
[Z1, P1, K1] = tf2zp(num1, den1)
Z1 =

-0.5000

P1 =

-1.0000 + 0.0000i
-0.5000 + 0.8660i
-0.5000 - 0.8660i

K1 =

zeros = 0;
poles = [1-1i, 1+1i, 2];
gain = 2;
[num2, den2] = zp2tf(zeros, poles, gain)
num2 =

0 0 2 0

den2 =

1 -4 6 -4
3 Time domain analysis
3.1 Typical input signal
num1 = [2, 1];
den1 = [1, 2, 2, 1];
sys1 = tf(num1, den1);
%impulse(sys1);
impulse(num1, den1);

num1 = [2, 1];


den1 = [1, 2, 2, 1];
sys1 = tf(num1, den1);
%step(sys1);
step(num1, den1);
3.2 Stability analysis
num1 = [2, 1];
den1 = [1, 2, 2, 1];
sys1 = tf(num1, den1);
pzmap(sys1);
grid on;

num1 = [2, 1];


den1 = [1, 2, 2, 1];
sys1 = tf(num1, den1);
pole(sys1)
ans =

-1.0000 + 0.0000i
-0.5000 + 0.8660i
-0.5000 - 0.8660i

zero(sys1)
ans =

-0.5000
roots(den1)
ans =

-1.0000 + 0.0000i
-0.5000 + 0.8660i
-0.5000 - 0.8660i

3.3 Transient performance analysis


num1 = [2, 1];
den1 = [1, 2, 2, 1];
sys1 = tf(num1, den1);
%step(sys1);
step(num1, den1);
num1 = [2, 1];
den1 = [1, 2, 2, 1];
sys1 = tf(num1, den1);
[y, t] = step(sys1);
plot(t,y);
[Y, k] = max(y);
tp = t(k)
tp =

2.8552

C = dcgain(sys1);
[Y, k] = max(y);
percent_overshoot = 100 * (Y - C) / C
percent_overshoot =

43.3919

% tr: 0 - 100%
n = 1;
while y(n) < C
n = n + 1;
end
tr = t(n)
tr =

1.5658

% tr: 10% - 90%


n = 1;
while y(n) < 0.1 * C
n = n + 1;
end
m = 1;
while y(m) < 0.9 * C
m = m + 1;
end
tr = t(m) - t(n)
tr =

1.1052

i = length(t);
while (y(i) > 0.95 * C) & (y(i) < 1.05 * C)
i = i - 1;
end
ts = t(i)
ts =

7.2762

3.4 Steady-state error analysis


num1 = [2, 1];
den1 = [1, 2, 2, 1];
sys1 = tf(num1, den1);
C = dcgain(sys1);
Ess = 1 - C
Ess =

0
4 Root Locus Techniques
4.1 Common functions for drawing root locus
rlocus(): Evans root locus.

rlocfind(): Find root locus gains for a given set of roots.

Example 4-1:

zeros = [];
poles = [0, -2];
gain = 1;
GH = zpk(zeros, poles, gain);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);

Example 4-2:
𝑲𝑲∗
𝑮𝑮(𝒔𝒔)𝑯𝑯(𝒔𝒔) =
𝒔𝒔(𝒔𝒔 + 𝟏𝟏)(𝒔𝒔 + 𝟐𝟐)
zeros = [];
poles = [0, -1, -2];
gain = 1;
GH = zpk(zeros, poles, gain);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);

Example 4-3:
𝑲𝑲∗ (𝒔𝒔 + 𝟒𝟒)
𝑮𝑮(𝒔𝒔)𝑯𝑯(𝒔𝒔) =
𝒔𝒔(𝒔𝒔 + 𝟐𝟐)
zeros = [-4];
poles = [0, -2];
gain = 1;
GH = zpk(zeros, poles, gain);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);
Example 4-4:
𝑲𝑲∗ (𝒔𝒔 + 𝟏𝟏)
𝑮𝑮(𝒔𝒔)𝑯𝑯(𝒔𝒔) =
(𝒔𝒔 + 𝟏𝟏. 𝟓𝟓 + 𝒋𝒋)(𝒔𝒔 + 𝟏𝟏. 𝟓𝟓 − 𝒋𝒋)
zeros = [-1];
poles = [-1.5-1i, -1.5+1i];
gain = 1;
GH = zpk(zeros, poles, gain);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);
Example 4-5:
𝑲𝑲∗ (𝒔𝒔 + 𝟏𝟏. 𝟓𝟓)(𝒔𝒔 + 𝟐𝟐 − 𝒋𝒋)(𝒔𝒔 + 𝟐𝟐 + 𝒋𝒋)
𝑮𝑮(𝒔𝒔)𝑯𝑯(𝒔𝒔) =
𝒔𝒔(𝒔𝒔 + 𝟐𝟐. 𝟓𝟓)(𝒔𝒔 + 𝟎𝟎. 𝟓𝟓 − 𝟏𝟏. 𝟓𝟓𝟓𝟓)(𝒔𝒔 + 𝟎𝟎. 𝟓𝟓 + 𝟏𝟏. 𝟓𝟓𝟓𝟓)
zeros = [-1.5, -2+2i, -2-2i];
poles = [0, -2.5, -0.5+1.5i, -0.5-1.5i];
gain = 1;
GH = zpk(zeros, poles, gain);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis([-4, 0.5, -3.5, 3.5]);
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);

Example 4-6:
𝑲𝑲∗
𝑮𝑮𝟎𝟎 (𝒔𝒔) =
𝒔𝒔(𝒔𝒔 + 𝟏𝟏)(𝒔𝒔 + 𝟑𝟑. 𝟓𝟓)(𝒔𝒔 + 𝟑𝟑 − 𝒋𝒋𝒋𝒋)(𝒔𝒔 + 𝟑𝟑 + 𝒋𝒋𝒋𝒋)
zeros = [];
poles = [0, -1, -3.5, -3+2i, -3-2i];
gain = 1;
GH = zpk(zeros, poles, gain);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis([-10, 5, -5, 5]);
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);

Example 4-7:
𝑲𝑲∗ (𝒔𝒔 + 𝟏𝟏)
𝑮𝑮(𝒔𝒔) =
𝒔𝒔(𝒔𝒔 − 𝟏𝟏)(𝒔𝒔𝟐𝟐 + 𝟒𝟒𝟒𝟒 + 𝟏𝟏𝟏𝟏)
num = [1, 1];
den = conv([1, 0], conv([1 -1], [1, 4, 16]));
GH = tf(num, den);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis([-4.5, 3.5, -4.5, 4.5]);
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);
Example 4-8:
𝑲𝑲∗ 𝑲𝑲∗
𝑮𝑮(𝒔𝒔)𝑯𝑯(𝒔𝒔) = =
𝒔𝒔(𝒔𝒔𝟐𝟐 + 𝟔𝟔𝟔𝟔 + 𝟏𝟏𝟏𝟏) 𝒔𝒔(𝒔𝒔 + 𝟑𝟑 − 𝒋𝒋)(𝒔𝒔 + 𝟑𝟑 + 𝒋𝒋)
zeros = [];
poles = [0, -3+1i, -3-1i];
gain = 1;
GH = zpk(zeros, poles, gain);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis([-6, 1, -4, 4]);
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);
Example 4-9:
𝑲𝑲∗
𝑮𝑮(𝒔𝒔)𝑯𝑯(𝒔𝒔) =
𝒔𝒔(𝒔𝒔𝟐𝟐 + 𝟐𝟐𝟐𝟐 + 𝟐𝟐)(𝒔𝒔𝟐𝟐 + 𝟔𝟔𝟔𝟔 + 𝟏𝟏𝟏𝟏)
num = [1];
d1 = [1, 2, 2];
d2 = [1, 6, 13];
den1 = conv(d1, d2);
den = [den1, 0]; % den = [1, 8, 27, 38, 26, 0]
GH = tf(num,den);

rlocus(GH);
sgrid();

h = findobj(gcf,'type','line');
axis([-6, 2, -5, 5]);
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);

[k, p] = rlocfind(GH);

k =

29.5940

p =

-2.8163 + 2.1726i
-2.8163 - 2.1726i
-2.3581 + 0.0000i
-0.0046 + 0.9959i
-0.0046 - 0.9959i

4.2 Root locus analysis of step response


Example 4-10:
𝑲𝑲
𝑮𝑮(𝒔𝒔) =
𝒔𝒔(𝒔𝒔 + 𝟏𝟏)(𝒔𝒔 + 𝟐𝟐)

Find the system open-loop gain corresponding to the damping ratio 0.707, draw the step
response of a unit feedback closed loop system.
zeros = [];
poles = [0, -1, -2];
gain = 1;
G = zpk(zeros, poles, gain);

rlocus(G);
zeta = [0:0.707:1];
wn = [1:10];
sgrid(zeta, wn);

h = findobj(gcf,'type','line');
axis([-6, 2, -5, 5]);
axis equal;
set(h, 'LineWidth', 2);
set(h, 'markersize', 15);

[k,p] = rlocfind(G);

k =

0.6697
p =

-2.2409 + 0.0000i
-0.3796 + 0.3934i
-0.3796 - 0.3934i

k = 0.6697;
G = zpk(zeros, poles, k);
Gf = feedback(G, 1);
figure();
step(Gf);

h = findobj(gcf,'type','line');
set(h, 'LineWidth', 2);

5 Frequency Response Techniques


5.1 Nyquist Diagram
Example 5-1:
𝟐𝟐𝟐𝟐 + 𝟔𝟔
𝑮𝑮(𝒔𝒔) =
𝒔𝒔𝟑𝟑 + 𝟐𝟐𝒔𝒔𝟐𝟐 + 𝟓𝟓𝟓𝟓 + 𝟐𝟐
Draw the Nyquist diagram, determine system stability.
close all;
clear all;
num = [2, 6];
den = [1, 2, 5, 2];
nyquist(num,den);

% num = [2, 6];


% den = [1, 2, 5, 2];
% [re, im] = nyquist(num,den);
% plot(re, im);
% grid on;
%
% [re, im] = nyquist(num,den,0.5);

h = findobj(gcf,'type','line');
set(h, 'LineWidth', 2);

Example 5-2:

𝝎𝝎𝟐𝟐𝒏𝒏
𝑮𝑮(𝒔𝒔) =
𝒔𝒔𝟐𝟐 + 𝟐𝟐𝟐𝟐𝝎𝝎𝒏𝒏 𝒔𝒔 + 𝝎𝝎𝟐𝟐𝒏𝒏
Sketching the Nyquist diagram.
close all;
clear all;
zetas = [0.3, 0.5, 0.7, 0.9];
wn = 1;
for i = 1:4
num = wn * wn;
den = [1, 2*zetas(i), wn * wn];
nyquist(num,den);
axis('square');
hold on;
end
h = findobj(gcf,'type','line');
set(h, 'LineWidth', 2);

Example 5-3:
𝟐𝟐𝟐𝟐 + 𝟏𝟏
𝑮𝑮(𝒔𝒔) =
𝒔𝒔𝟐𝟐 (𝟎𝟎. 𝟓𝟓𝟓𝟓 + 𝟏𝟏)(𝒔𝒔 + 𝟏𝟏)
Sketching the Nyquist diagram.
num = [2, 1];
den = conv([1, 0, 0], conv([0.5, 1], [1, 1]));
nyquist(num, den, {0.2,10000});

h = findobj(gcf,'type','line');
set(h, 'LineWidth', 2);
5.2 Bode Plots
Example 5-4:
𝟑𝟑𝟑𝟑(𝟎𝟎. 𝟐𝟐𝟐𝟐 + 𝟏𝟏)
𝑮𝑮(𝒔𝒔) =
𝒔𝒔(𝒔𝒔𝟐𝟐+ 𝟏𝟏𝟏𝟏𝟏𝟏 + 𝟏𝟏𝟏𝟏𝟏𝟏𝟏𝟏)
Draw the Bode plot.
num = [6, 30];
den = conv([1, 0], [1, 16, 100]);
% bode(num, den);

bode(num, den, {0.1,100});

% [mag, phase, w] = bode(num, den, {0.1,100});


% semilogx(w, 20*log10(mag));

grid on;
h = findobj(gcf,'type','line');
set(h, 'LineWidth', 2);
Bode Diagram
20

-20
Magnitude (dB)

-40

-60

-80
-60

-90
Phase (deg)

-120

-150

-180
-1 1 2
10 10 0 10 10
Frequency (rad/s)

5.3 Gain Margin and Phase Margin


Example 5-5:
𝟏𝟏𝟏𝟏
𝑮𝑮(𝒔𝒔) =
𝒔𝒔𝟑𝟑 + 𝟑𝟑𝒔𝒔𝟐𝟐 + 𝟗𝟗𝟗𝟗
Find the magnitude/gain margin and phase margin.
close all;
clear all;
num = [10];
den = [1, 3, 9, 0];
margin(num,den);
grid on;

[Gm, Pm, Wcg, Wcp] = margin(num,den);

You might also like