summaryrefslogtreecommitdiffstats
path: root/templates/LQR.m
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2023-05-24 16:22:02 +0200
committerNao Pross <np@0hm.ch>2023-05-24 16:32:02 +0200
commitb6f865025eed2db716f2f853435855edb0db9e82 (patch)
tree0211e0d07543dcea8e8e6048ae58a3458f5ab2d9 /templates/LQR.m
parentTake deliverables for system modelling from npross (diff)
downloadmpc_pe-b6f865025eed2db716f2f853435855edb0db9e82.tar.gz
mpc_pe-b6f865025eed2db716f2f853435855edb0db9e82.zip
Take deliverables for uncontrained optimal control from npross
According to table 5 they are: - LQR - LQR/eval (contained in LQR.m) - simulate - traj_contraints - lqr_tuning - lqr_tuning_script (.m and its .mat output file)
Diffstat (limited to 'templates/LQR.m')
-rw-r--r--templates/LQR.m10
1 files changed, 7 insertions, 3 deletions
diff --git a/templates/LQR.m b/templates/LQR.m
index 2a79da9..873546a 100644
--- a/templates/LQR.m
+++ b/templates/LQR.m
@@ -15,13 +15,17 @@ classdef LQR
%constructor
function obj = LQR(Q,R,params)
% YOUR CODE HERE
- % obj.K = ... (save feedback matrix for use in eval function)
+ E = zeros(params.model.nx);
+ S = zeros(params.model.nx, params.model.nu);
+ Pinf = idare(params.model.A, params.model.B, Q, R);
+ obj.K = -inv(R + params.model.B' * Pinf * params.model.B) ...
+ * params.model.B' * Pinf * params.model.A;
end
function [u, ctrl_info] = eval(obj,x)
% YOUR CODE HERE
- % u = ...
+ u = obj.K * x;
ctrl_info = struct('ctrl_feas',true);
end
end
-end \ No newline at end of file
+end