summaryrefslogtreecommitdiffstats
path: root/templates/LQR.m
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2023-05-02 13:27:31 +0200
committerNao Pross <np@0hm.ch>2023-05-02 13:27:31 +0200
commite29fa3f2c56286eaaccb6fbe54029037f2a02d5b (patch)
tree3a368953d23745ddd18e0a9d4173c60a09e74082 /templates/LQR.m
parentADD: Create .gitignore (diff)
downloadmpc_pe-e29fa3f2c56286eaaccb6fbe54029037f2a02d5b.tar.gz
mpc_pe-e29fa3f2c56286eaaccb6fbe54029037f2a02d5b.zip
ADD: Tasks 1-9
Diffstat (limited to 'templates/LQR.m')
-rw-r--r--templates/LQR.m9
1 files changed, 6 insertions, 3 deletions
diff --git a/templates/LQR.m b/templates/LQR.m
index 2a79da9..76d95c6 100644
--- a/templates/LQR.m
+++ b/templates/LQR.m
@@ -15,13 +15,16 @@ classdef LQR
%constructor
function obj = LQR(Q,R,params)
% YOUR CODE HERE
- % obj.K = ... (save feedback matrix for use in eval function)
+ E = np.zeros(params.model.nx);
+ S = np.zeros(params.model.nx);
+ Pinf = idare(params.model.A, params.model.B, Q, R, S, E, 'noscaling')
+ obj.K = -inv(R + B' * Pinf * B) * B' * Pinf * 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