フィルターのクリア

how can I simulate this NMPC in close loop? i try using the matlab examples but i have a lot of parameters.

3 ビュー (過去 30 日間)
Here´s the NMPC
clc
clear all
close all
%% NMPC
% Parámetros
Ta = 23 + 273.15; % K
U = 10.0; % W/m^2-K
m = 4.0/1000.0; % kg
Cp = 0.5 * 1000.0; % J/kg-K
A = 12.0 / 100.0^2; % Area in m^2
alpha = 0.01; % W % heater
eps = 0.9; % Emissivity
sigma = 5.67e-8; % Stefan-Boltzman
Par = [Ta;U;m;Cp;A;alpha;eps;sigma];
%% Crear objeto NMPC
nx = 1; %Estados
ny = 1; %Salidas
nu = 1; %entradas
nlobj = nlmpc(nx,ny,nu);
nlobj.States.Name = 'T';
nlobj.MV.Name = 'H';
nlobj.Model.StateFcn = @(x,u,Par) prediction_model_jl(x,u,Par);
% No output function specified. Assuming "y = x" in the prediction model.
nlobj.Model.IsContinuousTime = true;
nlobj.Model.NumberOfParameters=1;
%% Restricciones NMPC
nlobj.States.Min = 0;
nlobj.MV.Min = 0;
nlobj.MV.Max = 100;
nlobj.MV.RateMin = -100;
nlobj.MV.RateMax = 100;
%% NMPC Sintonización
N=14;
Nu=10;
delta=0.69408;
lambda=0.24209;
Ts = 8;
nlobj.Ts = Ts;
nlobj.PredictionHorizon = N;
nlobj.ControlHorizon = Nu;
nlobj.Weights.OutputVariables = delta;
nlobj.Weights.ManipulatedVariablesRate = lambda;
here´s the prediction model
%Specify Prediction Model for Nonlinear MPC
function dTdt = prediction_model_jl(x,u,Par)
% Parameters
Ta = Par(1); % K
U = Par(2); % W/m^2-K
m = Par(3); % kg
Cp = Par(4); % J/kg-K
A = Par(5); % Area in m^2
alpha = Par(6); % W / % heater
eps = Par(7); % Emissivity
sigma = Par(8); % Stefan-Boltzman % Stefan-Boltzman
% Temperatura
T= x(1);
% Entradas
Q= u(1);
% Ecuaciones de los balances de energía
dTdt = (1.0/(m*Cp))*(U*A*(Ta-T) ...
+ eps * sigma * A * (Ta^4 - T^4) ...
+ alpha*Q);
end
The same prediction model is the plant model so i want to use the nmpc in a close loop to see the answer at the end of the plant.
%Initial States
x=23+273.15;
u=0;
%% Ref signal
% Define el vector de tiempo
t = linspace(0, 10, 1000);
initialValue = 23+273.15;
stepValue = 50;
stepTime = 5;
ref = initialValue + stepValue * (t >= stepTime);

回答 (1 件)

Ishu
Ishu 2023 年 9 月 7 日
Hi Juan,
In my understanding you have provided the code for 'NMPC' and now you want to simulate this 'NMPC' in a closed loop. For that you can make use of "for loop" iterating over 't'.
As the 'Par' is not changing so you can directly initialize these parameters in the "prediction_model_jl()" function itself rather than passing these as arguments. You can change your function accordingly.
function dTdt = prediction_model_jl(x,u)
% Parameters
% Parámetros
Ta = 23 + 273.15; % K
U = 10.0; % W/m^2-K
m = 4.0/1000.0; % kg
Cp = 0.5 * 1000.0; % J/kg-K
A = 12.0 / 100.0^2; % Area in m^2
alpha = 0.01; % W % heater
eps = 0.9; % Emissivity
sigma = 5.67e-8; % Stefan-Boltzman
% Temperatura
T= x(1);
% Entradas
Q= u(1);
% Ecuaciones de los balances de energía
dTdt = (1.0/(m*Cp))*(U*A*(Ta-T) ...
+ eps * sigma * A * (Ta^4 - T^4) ...
+ alpha*Q);
end
And also make other changes relating to this function calling.
Now you can create two vectors to store the system response
x_history = zeros(size(t));
u_history = zeros(size(t));
Simulating NMPC:
% Closed-loop simulation
for i = 1:length(t)
% Update the NMPC controller
[u, ~] = nlmpcmove(nlobj, x, u,ref(i));
% Simulate the system response
dxdt = prediction_model_jl(x, u);
x_history(i) = x + dxdt*Ts;
u_history(i) = u;
end
Plot the results:
figure;
subplot(2, 1, 1);
plot(t, ref, 'r--', 'LineWidth', 2);
hold on;
plot(t, x_history, 'k', 'LineWidth', 2);
xlabel('Time');
ylabel('Temperature (K)');
legend('Reference', 'System Response');
title('Closed-Loop System Response');
subplot(2, 1, 2);
plot(t, u_history, 'b', 'LineWidth', 2);
xlabel('Time');
ylabel('Control Input');
title('Control Input Profile');
For more information on 'nlmpc' you can refer this documentation:
Hope it helps!

カテゴリ

Help Center および File ExchangeModel Predictive Control Toolbox についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by