Я пытаюсь реализовать класс Matlab в Simulink MATLABSystem. Когда я реализую суперкласс, симуляция работает нормально, но, используя подкласс, я получаю следующую ошибку:
"Simulink не может автоматически выводить свойства выходного сигнала« subclassSystem ». Simulink использует технологию генерации кода для автоматического определения свойств выходного сигнала из объекта System. Системный объект« subclass »содержит код, который не поддерживает код поколение.
Ошибка
'Неопределенная функция или переменная' obj '. Первое присваивание локальной переменной определяет ее класс. '
Произошла ошибка для системного блока MATLAB «subclassSystem». См. Строку 29, столбец 28 в файле 'superclass.m'. Ошибка обнаружена во время фазы распространения размера. "
Я прокомментировал эту строку в коде ниже
Должен ли я указать что-то дополнительное?
Здесь определение подкласса:
classdef subclass < superclass
properties(Access = protected) % These variables must be initialised. Here or in the setupImpl function
end
methods (Access=protected)
function resetImpl(obj)
end
%% Common functions
function setupImpl(obj)
% Perform one-time calculations, such as computing constants
setupImpl@superclass();
%obj.initFilter(obj.sampleTime, obj.delta_i, obj.delta_d, obj.g_mps2, obj.q0, obj.b_w0, obj.sigma_2_w, obj.sigma_2_a, obj.sigma_2_b_w, obj.sigma_2_yaw)
end
function attitude = stepImpl(obj,u, y)
% Implement algorithm.
attitude = 5;
end
end
methods
% Constructor must be empty for matlab.System. In Matlab call
% initFilter after the object was created. In simulink setupImpl()
% will be called
function obj = subclass()
obj@superclass();
end
end
end
Здесь определение суперкласса:
classdef superclass < matlab.System
% These variables must be initialized in the simulink model
properties
sigma_2_w;
sigma_2_a;
sigma_2_b_w;
sigma_2_yaw;
end
properties(Access = protected) % These variables must be initialised. Here or in the setupImpl function
R;
Q;
end
methods (Access = protected)
function resetImpl(obj)
end
%% Common functions
function setupImpl(obj)
% Perform one-time calculations, such as computing constants
obj.Q = diag([obj.sigma_2_w',obj.sigma_2_b_w']); % this is line 29
obj.R = diag([obj.sigma_2_a',obj.sigma_2_yaw']);
end
function attitude = stepImpl(obj,u, y)
% Implement algorithm.
attitude = 5;
end
end
methods
% Constructor must be empty for matlab.System. In Matlab call
% initFilter after the object was created. In simulink setupImpl()
% will be called
function obj = superclass()
% Support name-value pair arguments when constructing object
end
end
end