diff options
author | Yuan Xu <yuanxu@student.ethz.ch> | 2023-05-11 12:00:59 +0200 |
---|---|---|
committer | Yuan Xu <yuanxu@student.ethz.ch> | 2023-05-11 12:00:59 +0200 |
commit | feb6ec844cf2d0cdb07acd609615675141e2706a (patch) | |
tree | 1a411c04d693358a6ffc2d2a07e09bb819a8f6cc /templates/MPC.m | |
parent | Revert mistakenly pushed to master (diff) | |
download | mpc_pe-yuanxu.tar.gz mpc_pe-yuanxu.zip |
update previous filesyuanxu
Diffstat (limited to '')
-rw-r--r-- | templates/MPC.m | 49 |
1 files changed, 2 insertions, 47 deletions
diff --git a/templates/MPC.m b/templates/MPC.m index b2d411d..355eb81 100644 --- a/templates/MPC.m +++ b/templates/MPC.m @@ -6,44 +6,6 @@ % Please see the LICENSE file that has been included as part of this package. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% classdef MPC -% properties -% yalmip_optimizer -% end -% -% methods -% function obj = MPC(Q,R,N,params) -% nu = params.model.nu; -% nx = params.model.nx; -% -% % define optimization variables -% U = sdpvar(repmat(nu,1,N),ones(1,N),'full'); -% X0 = sdpvar(nx,1,'full'); -% -% % YOUR CODE HERE -% -% opts = sdpsettings('verbose',1,'solver','quadprog'); -% obj.yalmip_optimizer = optimizer(constraints,objective,opts,X0,{U{1} objective}); -% end -% -% function [u, ctrl_info] = eval(obj,x) -% %% evaluate control action by solving MPC problem, e.g. -% tic; -% [optimizer_out,errorcode] = obj.yalmip_optimizer(x); -% solvetime = toc; -% -% [u, objective] = optimizer_out{:}; -% -% feasible = true; -% if (errorcode ~= 0) -% feasible = false; -% end -% -% ctrl_info = struct('ctrl_feas',feasible,'objective',objective,'solvetime',solvetime); -% end -% end -% end - classdef MPC properties yalmip_optimizer @@ -54,7 +16,6 @@ classdef MPC nu = params.model.nu; nx = params.model.nx; % YOUR CODE HERE - % define optimization variables A=params.model.A; B=params.model.B; U = sdpvar(repmat(nu,1,N),ones(1,N),'full'); @@ -62,7 +23,6 @@ classdef MPC [K,P,~] = dlqr(A,B,Q,R); - % define constraints % s_max=params.constraints.MaxAbsPositionXZ; % y_max=params.constraints.MaxAbsPositionY; % u_max = params.constraints.MaxAbsThrust; @@ -99,17 +59,12 @@ classdef MPC [optimizer_out,errorcode,~] = obj.yalmip_optimizer{x}; solvetime = toc; - % extract optimal control action and objective function value - u = optimizer_out{1}; - objective = optimizer_out{2}; + [u, objective] = optimizer_out{:}; - % check feasibility of optimization problem - feasible = ~isnan(objective) && ~isinf(objective); + feasible = true; if (errorcode ~= 0) feasible = false; end - - % create control info struct ctrl_info = struct('ctrl_feas',feasible,'objective',objective,'solvetime',solvetime); end end |