How to write StateFcn in Nonlinear MPC Controller

조회 수: 8 (최근 30일)
Frank
Frank 2024년 7월 15일
답변: Shubham 2024년 7월 18일
Nowdays, I am doing some works about visual servoing. But there are some troubles with the nonlinear MPC Controller. I have read the example named 'Control Quadruple-Tank Using Passivity-Based Nonlinear MPC'. There is a code nlobj.Model.StateFcn = "stateFcnQuadrupleTank".
I opened it, and the content shows as a picture as follows. It looks like the example uses code to express the dynamic system. I want to know if I can use a Simulink model, which is already done, to replace the code.
Thank a lot for your help!

채택된 답변

Shubham
Shubham 2024년 7월 18일
Hi Frank,
I understand that you want to use a Simulink model as a state function of a Nonlinear MPC Controller.
To use a Simulink model instead of a code to express dynamic system, say for example "stateFcnQuadrupleTank", you need to follow these steps:
  • Ensure that your Simulink model correctly represents correct dynamics of the system
  • The model should have input and outputs corresponding to the states and control inputs
  • Generate an S-Function from your Simulink model using Simulink Encoder (if the model is simple, then directly use MATLAB Function block to define state conditions directly) which is given below:
% Load the Simulink model
load_system('model_name');
% Generate the S-Function
rtwbuild('model_name');
  • You can use the "nlmpc" object in MATLAB to define the state function using the generated S-Function:
% Define the Nonlinear MPC object
nlobj = nlmpc(4, 1); % Assuming 4 states and 1 output for the quadruple-tank system
% Define the state function using the generated S-Function
nlobj.Model.StateFcn = 'model_name_sfcn';
Please refer to the following documentation link for more information on how to use S-Function:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear MPC Design에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by