3
votes

In MATLAB Simulink, I added an MPC (Model predictive control block).

I looked inside this block:

mpc1

Inside it there is a wrapper subsystem called MPC. I opened this one via double click:

mpc2

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:

https://www.dropbox.com/s/vx67urpkt9qki9e/simulink.zip?dl=0

2
Interesting question! Tried to figure out about this, but can't open your model in due to you have newer MATLAB version.Mikhail_Sam
@Mikhail_Sam in your matlab please add an MPC block and try to open it.ar2015

2 Answers

2
votes

I suspect some of the "inputs" are not actually inputs, but parameters passed to the function. See Add Parameter Arguments in the documentation for more details.

2
votes

For a Matlab Function block, there are two types of input arguments to the m-code. The input signals you already know and parameters. Go to edit data, you will see which are switched to paremeter, these variables come from a mask or your workspace.