'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;

Answers (3)

Jakobus Louw
Jakobus Louw on 9 Apr 2020
Its similar to Dhruv's answer, but the block is called SIgnal Specification.

Sai Sri Pathuri
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.

Dhruv Thakkar
Dhruv Thakkar on 12 Mar 2020
You can use Signal Dimension block to mention the dimension as [5 2] to ensure that there is no discrepency.

Community Treasure Hunt

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

Start Hunting!