From feb6ec844cf2d0cdb07acd609615675141e2706a Mon Sep 17 00:00:00 2001 From: Yuan Xu Date: Thu, 11 May 2023 12:00:59 +0200 Subject: update previous files --- templates/MPC.m | 49 ++----------------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) (limited to 'templates/MPC.m') 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 -- cgit v1.2.1