-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim_controlpositional.m
More file actions
55 lines (44 loc) · 1.08 KB
/
Copy pathsim_controlpositional.m
File metadata and controls
55 lines (44 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
clear all; close all; clc
%% Discretization of First-Order Identified Model (Non-Parametric)
Ts = 0.1;
gp = tf(20,[50 1]); % First-order plant
gpd = c2d(gp,Ts,'zoh'); % Discrete plant
%% PI controller parameters
Kp = 0.8; % propotional gain
Ti = 9;% integral time
%% Closed-Loop Simulation (Direct difference equation)
[num,den] = tfdata(gpd,'v');
t = 0:Ts:60;
M=400;
Ref = M*ones(1,length(t));
% Histories
% states
y1 = 0;
I = 0;
u = 0;
for k=1:length(t)
%% plant
y(k) = num(2)*u - den(2)*y1;
% ---- FEEDBACK WITHOUT ANTIWINDUP ----
e = Ref(k) - y(k);
I = I + Ts*e;
u = Kp*e + Kp/Ti*I;
% ---- SATURATION ----
if u > 100
u = 100;
end
if u < 0
u = 0;
end
% ---- UPDATE STATES ----
y1=y(k);
Usim(k)=u;
end
%% PLOTS
subplot(2,1,1)
plot(t,y,'+',t,Ref,'--','MarkerSize',4)
xlabel('Time [s]'), ylabel('Response')
legend('Simulation','Reference')
subplot(2,1,2)
plot(t,Usim,'+','MarkerSize',4)
xlabel('Time [s]'), ylabel('Control signal')