Error using sqpInterface Nonlinear constraint function is undefined at initial point. Fmincon cannot continue.
22 ビュー (過去 30 日間)
古いコメントを表示
I got this error "Nonlinear constraint function is undefined at initial point. Fmincon cannot continue." when i ran a simulation to remove offset using extended kalman filter "EKF" in quadruple system. The target is to control level of water in the lower tank h1 and h2 by manipulating v1 and v2. check below for the code;
%NMPC CODE:
clc, clear all
%% Simulink Model
% To run this example, Simulink(R) is required.
if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink is required to run this example.')
return
end
%%initialize NMPC object and set properties
nx = 8;
ny = 2;
%nu = 2;
%'UD', [5,6,7,8,9,10]
nlobj = nlmpc(nx, ny, 'MV', [1,2], 'UD', [3,4,5,6]);
%The prediction model sample time is the same as the controller sample time
Ts = 3; %Ts = 2
nlobj.Ts = Ts;
%Prediction and control horizon
nlobj.PredictionHorizon = 20;
nlobj.ControlHorizon = [1];
%weights on output and manipulated variables
nlobj.Weights.OutputVariables = [1000,1000]; %0.1
nlobj.Weights.ManipulatedVariables = [10,10]; %0.05;
%nlobj.Weights.ManipulatedVariablesRate = [10,10];
%constraints on manipulated variables
nlobj.MV(1).RateMin = -1;
nlobj.MV(2).RateMin = -1;
nlobj.MV(1).RateMax = 1;
nlobj.Mv(2).RateMax = 1;
nlobj.MV(1).Min = 2.7;
nlobj.MV(2).Min = 2.7;
nlobj.MV(1).Max = 3.3;
nlobj.MV(1).Max = 3.3;
%constraint on output variables to keep them within reasonable bounds
nlobj.OV(1).Min = 11.16;
nlobj.OV(2).Min = 11.43;
%nlobj.OV(3).Min = 2.5;
%nlobj.OV(4).Min = 2.5;
nlobj.OV(1).Max = 13.64;
nlobj.OV(2).Max = 13.97;
%nlobj.OV(3).Max = 8;
%nlobj.OV(4).Max = 8;
%% specify the nonlinear state and output functions
nlobj.Model.StateFcn = 'four_tankStateFcnCT';
nlobj.Model.OutputFcn = 'four_tankOutputFcn';
SolverOptions.Algorithm = 'sqp';
%% validate the nonlinear MPC object with initial conditions
h0 = [12.44;13.17;4.73;4.986;0;0;0;0]; %[0.0033;920.86; 0.0104; 0.0085; 0.0118; 798];
u0 = [3.15;3.15];
validateFcns(nlobj, h0, u0);
%four_tankStateFcnCT CODE:
function dhdt = four_tankStateFcnCT(h, u)
% Define system parameters
g = 981; % gravitational constant (m/s^2)
% Tank areas (in cm^2)
A1 = 28;
A2 = 32;
A3 = 28;
A4 = 32;
% Outlet areas (in cm^2)
a1 = 0.071;
a2 = 0.057;
a3 = 0.071;
a4 = 0.057;
% Flow distribution coefficients
gamma1 = 0.43;
gamma2 = 0.34;
% Pump constants (flow per voltage)
k1 = 3.14;
k2 = 3.29;
% State variables (water levels in each tank)
h1 = h(1);
h2 = h(2);
h3 = h(3);
h4 = h(4);
% Inputs (pump voltages)
v1 = u(1);
v2 = u(2);
dh1 = h1;
dh2 = h2;
dh3 = h3;
dh4 = h4;
dhdt = zeros(8,1);
% Equations from the journal
dhdt(1) = -a1/A1 * sqrt(2 * g * h1) + a3/A1 * sqrt(2 * g * h3) + (gamma1 * k1 * v1) / A1 + dh1;
dhdt(2) = -a2/A2 * sqrt(2 * g * h2) + a4/A2 * sqrt(2 * g * h4) + (gamma2 * k2 * v2) / A2 + dh2;
dhdt(3) = -a3/A3 * sqrt(2 * g * h3) + ((1 - gamma2) * k2 * v2) / A3 + dh3;
dhdt(4) = -a4/A4 * sqrt(2 * g * h4) + ((1 - gamma1) * k1 * v1) / A4 + dh4;
dhdt(5) = u(3);
dhdt(6) = u(4);
dhdt(7) = u(5);
dhdt(8) = u(6);
%four_tankStateFcnDT CODE:
function hk1 = four_tankStateFcnDT(hk,uk)
hstep = 1;
hk1 = hk(:);
Nsteps = 2; % Number of integration time steps for Euler method
uk1 = [uk(:);0;0;0;0]; % The manipulated input + white noise of size 2
for i = 1:Nsteps
hk1 = hk1 + hstep*four_tankStateFcnCT(hk1,uk1);
end
%four_tankMeasFcn CODE:
function y = four_tankMeasFcn(h)
y = [h(1) ;
h(2)] ;
%four_tankOutputFcn CODE:
function y = four_tankOutputFcn(h,u)
y = [h(1) ;
h(2)] ;
0 件のコメント
回答 (1 件)
Suraj Kumar
2024 年 11 月 18 日 19:47
Hi Hammed,
You can refer to the following link which resolves a similar issue in detail:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Refinement についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!