In MATLAB Simulink, I added an MPC (Model predictive control block).
I looked inside this block:
Inside it there is a wrapper subsystem called MPC
. I opened this one via double click:
The main block inside this subsystem is optimizer
. This block is a m-code block starting with this header:
function [xk1, u, cost, useq, status, xest, iAout] = fcn(...
xk, old_u, ym, ref, md, umin, umax, ymin, ymax, switch_in, ext_mv, MVtarget, isQP, nx, nu, ny, degrees, Hinv, Kx, Ku1, Kut, Kr, Kv, Mlim, ...
Mx, Mu1, Mv, z_degrees, utarget, p, uoff, voff, yoff, maxiter, nxQP, openloopflag, ...
lims_inport, no_umin, no_umax, no_ymin, no_ymax, switch_inport, no_switch, enable_value, ...
return_cost, H, return_sequence, Linv, Ac, ...
ywt, uwt, duwt, rhoeps, iA, ...
no_ywt, no_uwt, no_duwt, no_rhoeps,...
Wy, Wdu, Jm, SuJm, Su1, Sx, Hv, Wu, I1, ...
A, Bu, Bv, C, Dv, Mrows, nCC, Ecc, Fcc, Scc, Gcc, ...
nv, no_md, no_ref, no_uref, no_mv, Rscale, MDscale, myindex, ...
myoff, xoff, CustomEstimation, M, L)
%#codegen
coder.extrinsic('mpcblock_optimizer_double_mex');
coder.extrinsic('mpcblock_optimizer_single_mex');
coder.extrinsic('mpcblock_refmd_double_mex');
coder.extrinsic('mpcblock_refmd_single_mex');
My question is that why the number of inputs of the function in the code is much higher than the number of inputs ports of this block in simulink. Where are these variables generated? For example how is argument H
created before this function is called?
Here the Simulink file is attached: