'Error in port widths or dimensions' for using Adaptive MPC controller
13 views (last 30 days)
I'm trying to construct the Co-simulation environment of path planning using MPC with CarSim.
but I'm struggle with debugging some errors. In the above simulink code, it makes a one Block error that says right below
"Error in port widths or dimensions. The signal connected to the "Model.B" port of the "Base_Model/Adaptive MPC Controller" block must be a matrix signal of 5 rows and 2 columns."
I don't definitley make sense since I think that the size of matix B is [5x2] as you can see above picture.
In addition, here is the Matlab Function code for generating state space matrix for updating model on adaptive MPC.
function [A,B,C,D,U,Y,X,DX] = fcn(x,u)
% Sample time
Ts = 0.1;
% Continuous-Time model
[Ac,Bc,Cc,Dc] = linmod('vehicleModel',x,u);
% Discretize using zero-order hold
nx = 5; nu = 2;
temp = coder.nullcopy(zeros(7,7));
A = coder.nullcopy(zeros(5,5));
B = coder.nullcopy(zeros(5,2));
C = coder.nullcopy(zeros(2,5));
D = coder.nullcopy(zeros(2,2));
X = coder.nullcopy(zeros(5,1));
U = coder.nullcopy(zeros(2,1));
Y = coder.nullcopy(zeros(2,1));
DX = coder.nullcopy(zeros(5,1));
% nx = size(Ac,1);
% nu = size(Bc,2);
temp = expm([[Ac Bc]*Ts; zeros(nu,nx+nu)]);
A = temp(1:nx, 1:nx);
B = temp(1:nx, nx+1:nx+nu);
C = Cc;
D = Dc;
% Nominal conditions of DT plant
X = x;
U = u;
Y = C*x;
DX = A*x + B*u - x;
Sai Sri Pathuri on 25 Feb 2020
The Bus Creator block you are using in the model combines all the output signals from ML function block. But the expected input of Adaptive MPC block is not the entire bus signal. So, you may use Bus Selector block to select the appropriate signal from the bus signal.