Error when NLMPC optimization "TimeVarying" and "Adaptive" is used

조회 수: 4 (최근 30일)
Nishanth Rao
Nishanth Rao 2021년 7월 21일
댓글: 世忠 2023년 11월 20일
I have a highly non-linear state space function comprising of 60 states, and 16 control inputs. I assume that output vector is equal to the state vector. In order to create a non-linear MPC controller, I use the function but the simulation is taking a very long time. However, in the documentation of the function, it is said that the optimization variable can be set as or , which implements a linear MPC. But when I run the code, there is an error that comes after some iterations:
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of
rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in znlmpc_getDecisions (line 30)
Umv = reshape(coredata.Iz2u*uz,nmv,p)';
Error in znlmpc_getXUe (line 30)
[X(2:p1,:), Umv(1:p1-1,:), e] = znlmpc_getDecisions(coredata, z);
Error in nlmpc/nlmpcmove (line 247)
[X, U, e] = znlmpc_getXUe(coredata, z, x, runtimedata.md);
Error in nmpc_run (line 65)
mv = nlmpcmove(nlobj, x_state, last_mv, x_ref');
Related documentation
I wanted to know why this error is coming. For your reference, I have attached the implementation of the main program:
%% Initialize the variables
init_vars;
%% Set Non-Linear MPC Parameters
global data;
nlobj = nlmpc(data.nx, data.ny, data.nu);
nlobj.Ts = data.Ts;
nlobj.PredictionHorizon = data.Np;
nlobj.Model.StateFcn = "state_space";
nlobj.Optimization.RunAsLinearMPC = "TimeVarying";
%nlobj.Optimization.CustomCostFcn = "cost_function";
%nlobj.Optimization.ReplaceStandardCost = true;
nlobj.Weights.OutputVariables = data.weights_OV;
%nlobj.Weights.ManipulatedVariables = data.weights_MV;
%nlobj.Weights.ManipulatedVariablesRate = data.weights_MVR;
%% Set constraints
nlobj.States(3).Max = 0;
% The rpy of payload cannot go more than 5 degrees
nlobj.States(7).Min = -pi / 36;
nlobj.States(7).Max = pi / 36;
nlobj.States(8).Min = -pi / 36;
nlobj.States(8).Max = pi / 36;
nlobj.States(9).Min = -pi / 36;
nlobj.States(9).Max = pi / 36;
% rpy of each drone cannot go more than 15 degrees
for i=37:48
nlobj.States(i).Min = -pi / 6;
nlobj.States(i).Max = pi / 6;
end
% Thrust force is limited between [0N, 40N]. Note the NED convention.
% Torques are limited to [-5Nm, 5Nm].
for i=1:16
if ( mod(i - 1, 4) == 0 )
nlobj.ManipulatedVariables(i).Max = 0;
nlobj.ManipulatedVariables(i).Min = -40;
else
nlobj.ManipulatedVariables(i).Min = -10;
nlobj.ManipulatedVariables(i).Max = 10;
end
end
%% Validate the Prediction Model
x0 = reshape(data.x_i', [], 1);
u0 = zeros(data.nu, 1);
validateFcns(nlobj, x0, u0, [], [], zeros(1, data.nx));
%% Run the MPC algorithm
Duration = 20;
data_points = 1:(Duration/data.Ts);
time = 0:data.Ts:Duration;
x_state = reshape(data.x_i', [], 1);
xHistory = x_state';
last_mv = zeros(data.nu, 1);
for ct = data_points
t_ref = linspace(ct * data.Ts, (ct + data.Np - 1) * data.Ts, data.Np);
x_ref = genRefTraj(t_ref, x_state);
mv = nlmpcmove(nlobj, x_state, last_mv, x_ref');
[t, x] = ode45(@(t, x) state_space(x, mv), [0 data.Ts], x_state);
last_mv = mv;
x_state = x(end, :);
%Don't forget to constrain the norm of e_i's to one.
x_state(13:15) = x_state(13:15) / norm(x_state(13:15));
x_state(16:18) = x_state(16:18) / norm(x_state(16:18));
x_state(19:21) = x_state(19:21) / norm(x_state(19:21));
x_state(22:24) = x_state(22:24) / norm(x_state(22:24));
xHistory(ct + 1, :) = x_state;
xHistory(ct + 1, 3) = xHistory(ct +1, 3) * -1;
disp(x_state(1:3));
end
  댓글 수: 2
Julius Wanner
Julius Wanner 2022년 1월 26일
Has this problem been solved? I am struggling with the same issue... Thank you in advance!
世忠
世忠 2023년 11월 20일
Me too. Have you two solved this problem?. I met the same error.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Model Predictive Control Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by