I am working on a quadrotor 3dof ,and I have a problem with block nmpc can you help me?

9 次查看(过去 30 天)
Zero weights are applied to one or more OVs because there are fewer MVs than OVs.
Slack variable unused or zero-weighted in your custom cost function.
All constraints will be hard.
Model.StateFcn is OK.
Jacobian.StateFcn is OK.
Warning: Jacobian matrix with respect to "x" has maximum error = 3.9315 occurring at "(4,4)".
> In ctrlMsgUtils.warning (line 25)
In nlmpc/validateFcns>compareJac (line 378)
In nlmpc/validateFcns (line 175)
In Quadrotor6dof (line 60)
Warning: Jacobian matrix with respect to "umv" has maximum error = 0.45637 occurring at "(4,1)".
> In ctrlMsgUtils.warning (line 25)
In nlmpc/validateFcns>compareJac (line 378)
In nlmpc/validateFcns (line 176)
In Quadrotor6dof (line 60)
No output function specified. Assuming "y = x" in the prediction model.
Optimization.CustomCostFcn is OK.
Analysis of user-provided model, cost, and constraint functions complete.
Error using Quadrotor6dof (line 67)
Expected "ref" to be an array with number of columns equal to 6.
Error in nmpcblock_interface.m (line 165)
throw(ME)
Error in Quadrotor6dof.m (line 67)
Error in 's_hover_nmpc/Nonlinear MPC Controller/MPC/NLMPC' (line 24)
  1 个评论
Ibrahim
Ibrahim 2024-4-1
编辑:Sam Chak 2024-4-1
nx = 6;
ny = 6;
nu = 4;
nlobj = nlmpc(nx, ny, nu);
%nlobj = nlmpc(6,6,'MV',4,'MD',1,'UD',4)
nlobj.Model.StateFcn = "QuadrotorStateFcn";
nlobj.Jacobian.StateFcn = @QuadrotorStateJacobianFcn;
% nlobj.Model.OutputFcn = 'QuadrotorOutputFcn';
% nlobj.Model.OutputFcn = @(x,u,Ts) [x(1); x(3);x(5)];
rng(0)
% u=[1 1 1 1];
% validateFcns(nlobj,rand(nx,1),rand(nu,1));
Ts = 25;
p = 18;
m = 18;
% nlobj.Ts = Ts;
% nlobj.PredictionHorizon = p;
% nlobj.ControlHorizon = m;
% nlobj.MV = struct('Min',{0;0;0;0},'Max',{6;6;6;6});
% nlobj.MV = struct( ...
% Min={0;0;0;0}, ...
% Max={6;6;6;6}, ...
% RateMin={-2;-2;-2;-2}, ...
% RateMax={2;2;2;2} ...
% );
% nlobj.Model.NumberOfParameters = 1;
% nlobj.Weights.OutputVariables = [1 1 1 0 0 0];
% nlobj.Weights.ManipulatedVariables = [0.1 0.1 0.1 0.1];
% nlobj.Weights.ManipulatedVariablesRate = [0.1 0.1 0.1 0.1];
%%%%%%%%%%
nlobj.Ts = Ts;
nlobj.PredictionHorizon = p;
nlobj.ControlHorizon = m;
nlobj.MV = struct('Min', {0; 0; 0; 0}, 'Max', {6; 6; 6; 6});
nlobj.MV = struct( ...
Min = { 0; 0; 0; 0}, ...
Max = { 6; 6; 6; 6}, ...
RateMin = {-2; -2; -2; -2}, ...
RateMax = { 2; 2; 2; 2} ...
);
%nlobj.Model.NumberOfParameters = 1;
nlobj.Weights.OutputVariables = [0.1 0.1 0.1 0 0 0];
nlobj.Weights.ManipulatedVariables = [0.1 0.1 0.1 0.1];
nlobj.Weights.ManipulatedVariablesRate = [0.1 0.1 0.1 0.1];
% Specify the initial conditions
x = [0;0;0;0;0;0];
nlobj.Optimization.CustomCostFcn = @(X, U, e, data) Ts*sum(sum(U(1:p, :)));
nlobj.Optimization.ReplaceStandardCost = true;
% Nominal control target (average to keep quadrotor floating)
nloptions = nlmpcmoveopt;
nloptions.MVTarget = [4.9 4.9 4.9 4.9];
mv = nloptions.MVTarget;
% mv = nlmpcmove(nlobj,x,lastmv,ref);
lastmv = mv;
md = 0;
% ref=[1 0 0; 0 1 0; 0 0 1; 0 0 0; 0 0 0; 0 0 0];
% nlmpcmoveopt.options.Parameters={Ts x};
ref = zeros(1, nlobj.ny);
[mv, ~, Info] = nlmpcmove(nlobj, x, lastmv,ref);
validateFcns(nlobj, rand(nx, 1), rand(nu, 1));

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Earth and Planetary Science 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by