MATLAB Answers

0

Function 'subsindex' is not defined for values of class 'ss'

Asked by Lorenzo Genuardi on 18 May 2018
Latest activity Commented on by Lorenzo Genuardi on 18 May 2018

Dear all,

I'm creating a MPC controller and I need to create the MPC object to insert in the Simulink model. Here is the code.

%% Parameters
load('parametri.mat')
par.gyro.phid = 80;
% Gyroscope
nGyros = par.gyro.nGyros; 
Ig = par.gyro.Is(1,1)*nGyros+par.gyro.Ig(2,2)*nGyros; % [kgm2]
Jg = par.gyro.Ig(1,1)*nGyros; % [kgm2]
phid = par.gyro.phid; % [rad/s]
% Hull
Ih = par.hull.FDA.M(5,5); % [kgm2]
Ainf = par.hull.FDA.Ainf(5,5); % [kgm2]
Kw = par.hull.FDA.K(5,5); % [Nm/rad]
Ieq = Ih+Ainf+par.gyro.Is(1,1)*nGyros+par.gyro.Ig(2,2)*nGyros; % [kgm2]
% Hydrodinamics - State Space Approximation
a11 = par.hull.TDM.ry.Ass(1,1);
a12 = par.hull.TDM.ry.Ass(1,2);
a13 = par.hull.TDM.ry.Ass(1,3);
a14 = par.hull.TDM.ry.Ass(1,4);
c1 = par.hull.TDM.ry.Css(1,1);
c2 = par.hull.TDM.ry.Css(1,2);
c3 = par.hull.TDM.ry.Css(1,3);
c4 = par.hull.TDM.ry.Css(1,4);
%% State Space Representation: - plant.struct
pl.Am =     [   0             0         -Jg*phid/Ig      0        0        0        0         0       0          0  
                1             0              0           0        0        0        0         0       0          0  
             Jg*phid/Ieq      0              0        -Kw/Ieq  -c1/Ieq  -c2/Ieq  -c3/Ieq   -c4/Ieq    0        1/Ieq
                0             0              1           0        0        0        0         0       0          0
                0             0              1           0       a11      a12      a13       a14      0          0
                0             0              0           0        1        0        0         0       0          0 
                0             0              0           0        0        1        0         0       0          0
                0             0              0           0        0        0        1         0       0          0    
                0             0              0           0        0        0        1         0      -1.5        -1      %-0.9139  -1.1424
                0             0              0           0        0        0        1         0       1          0     ];     
pl.Bm = [1/Ig
           0
           0
           0
           0
           0
           0
           0   
           0   
           0    ]; 
mpc.delta_gain = 2;
pl.Cm =        [0 
              1
              0 
             -mpc.delta_gain 
              0 
              0 
              0 
              0   
              0  
              0  ]';
pl.Dm = zeros(1,1);
Ts = 0.01;                                                  %sample time [s]
states = {'epsd' 'eps' 'deltad' 'delta' 'rfv1' 'rfv2' 'rfv3' 'rfv4' 'wfv1' 'wfv2'};
inputs = {'Teps'};
outputs = {'eps'};
LinSys = ss(pl.Am,pl.Bm,pl.Cm,pl.Dm, Ts, 'statename',states,'inputname',inputs,'outputname',outputs);
pl.poles_ol = eig(pl.Am); 
%% Building of the MPC controller                                                  
p = 4;                                                      %prediction time [s]
m = 4;                                                      %control time [s]
MPCobj = mpc(LinSys,Ts,p,m);

When I run the code, it appear the error

Function 'subsindex' is not defined for values of class 'ss'
Error in MPC_MatrixBuilder_augModel (line 78)
MPCobj = mpc(LinSys,Ts,p,m);

How can I fix it?

Thank you

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephen Cobeldick on 18 May 2018
 Accepted Answer

Problem: You have named some variable mpc:

mpc.delta_gain = ...

which means that you cannot call the mpc function.

Solution: change the name of that variable.

  1 Comment

Sign in to comment.