4

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

ar2015
  • 5,558
  • 8
  • 53
  • 110

2 Answers2

2

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.

am304
  • 13,758
  • 2
  • 22
  • 40
  • Thanks a lot. Is there any way to trace where parameter `H` comes from? http://i.stack.imgur.com/WIuLT.png – ar2015 Mar 12 '16 at 03:20
  • Have a look at the mask of the block, I suspect it is defined in here somewhere. @Daniel's suggestion of looking at the workspace variables in the model explorer is also a good one. – am304 Mar 13 '16 at 16:20
2

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.

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • Thanks a lot. Is there any way to trace where parameter `H` comes from? http://i.stack.imgur.com/WIuLT.png – ar2015 Mar 12 '16 at 03:19
  • http://www.mathworks.com/help/simulink/ug/workspace-variables-in-model-explorer.html – Daniel Mar 12 '16 at 10:03