-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcontroller_lqr.m
More file actions
30 lines (24 loc) · 792 Bytes
/
controller_lqr.m
File metadata and controls
30 lines (24 loc) · 792 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
% BRIEF:
% Controller function template. Input and output dimension MUST NOT be
% modified.
% INPUT:
% Q: State weighting matrix, dimension (3,3)
% R: Input weighting matrix, dimension (3,3)
% T: Measured system temperatures, dimension (3,1)
% OUTPUT:
% p: Heating and cooling power, dimension (3,1)
function p = controller_lqr(Q, R, T, ~, ~)
% controller variables
persistent param;
% initialize controller, if not done already
if isempty(param)
param = init(Q, R);
end
% compute control action
p = -param.K*(T-param.T_sp) + param.p_sp; % working in delta formulation
end
function param = init(Q, R)
% get basic controller parameters
param = compute_controller_base_parameters;
param.K = dlqr(param.A, param.B, Q, R);
end