-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathP_control_script.m
More file actions
35 lines (30 loc) · 1010 Bytes
/
P_control_script.m
File metadata and controls
35 lines (30 loc) · 1010 Bytes
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
open_loop_script; % it generates system_tf_parameters.txt file
clc, clearvars, close all; % ritual to erase all the previous terminal message, vars, plots
fileID = fopen('system_tf_parameters.txt', 'r');
parameters = fscanf(fileID, '%f');
K = parameters(1);
T1 = parameters(2);
T2 = parameters(3);
fclose(fileID);
% p setting
K_p = ( T1 )/( K*T2 );
K_pmax = 0.2;
p = (K_p/K_pmax);
% temperature setpoint
set_val = 60;
% load dataset
f1 = xlsread('p-control-data.xlsx', 'Sheet1', 'B2:B59');
t1 = xlsread('p-control-data.xlsx', 'Sheet1', 'A2:A59');
% Plot dataset
plot(t1, f1); % main plot
ylim([20 65]);
hold on;
plot([t1(1), t1(end)], [f1(1),f1(1)]); % ambient temperature
hold on;
plot([t1(1), t1(end)], [set_val,set_val]); % temperature setpoint
xlabel('Time (s)');
ylabel('Temperature (°C)');
title('P control response');
legend("System response", "Ambient temperature", "Temperature setpoint", 'Location', 'best');
% peak overshoot computation
peak_overshoot = ( max(f1) - set_val )*100/set_val;