Skip to content
Snippets Groups Projects
Commit 0b38b4bd authored by Federico Felici's avatar Federico Felici
Browse files

Template is also working with dynamic sldd

parent 1ec58c00
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
function SCDalgo_template_inBus()
% SCDALGO_TEMPLATE_INBUS initializes a set of bus objects in the MATLAB base workspace
% Bus object: SCDalgo_template_inBus
clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'signal';
elems(1).Dimensions = 1;
elems(1).DimensionsMode = 'Fixed';
elems(1).DataType = 'single';
elems(1).SampleTime = -1;
elems(1).Complexity = 'real';
elems(1).Min = [];
elems(1).Max = [];
elems(1).DocUnits = '';
elems(1).Description = '';
SCDalgo_template_inBus = Simulink.Bus;
SCDalgo_template_inBus.HeaderFile = '';
SCDalgo_template_inBus.Description = '';
SCDalgo_template_inBus.DataScope = 'Auto';
SCDalgo_template_inBus.Alignment = -1;
SCDalgo_template_inBus.Elements = elems;
clear elems;
assignin('base','SCDalgo_template_inBus', SCDalgo_template_inBus);
function fp = SCDalgo_template_loadfp(obj)
%% Timing
if nargin>0
fp.timing = obj.gettiming; %get t_struct from object
end
%% Load other fixed parameters
fp.timing = obj.gettiming;
end
\ No newline at end of file
function SCDalgo_template_outBus()
% SCDalgo_template_outBUS initializes a set of bus objects in the MATLAB base workspace
% Bus object: SCDalgo_template_outBus
clear elems;
elems(1) = Simulink.BusElement;
elems(1).Name = 'signal';
elems(1).Dimensions = 1;
elems(1).DimensionsMode = 'Fixed';
elems(1).DataType = 'single';
elems(1).SampleTime = -1;
elems(1).Complexity = 'real';
elems(1).Min = [];
elems(1).Max = [];
elems(1).DocUnits = '';
elems(1).Description = '';
SCDalgo_template_outBus = Simulink.Bus;
SCDalgo_template_outBus.HeaderFile = '';
SCDalgo_template_outBus.Description = '';
SCDalgo_template_outBus.DataScope = 'Auto';
SCDalgo_template_outBus.Alignment = -1;
SCDalgo_template_outBus.Elements = elems;
clear elems;
assignin('base','SCDalgo_template_outBus', SCDalgo_template_outBus);
classdef SCDalgo_liuqe_test < SCDalgo_test
properties
algoobj = SCDalgo_liuqe_obj();
algoobj = SCDalgoobj_liuqe();
end
end
\ No newline at end of file
......@@ -14,6 +14,10 @@ classdef SCDclass_algo
stdinits % Standard inits scripts for fixed parameters
timing % Timing info structure
exportedtpsdefaults % default tunable parameters defining functions
inBus % name of input bus
outBus % name of output bus
modelslx % slx model file name
folder % folder containing algorithm
end
methods
......@@ -34,6 +38,16 @@ classdef SCDclass_algo
obj.timing.t_stop=1;
obj.timing.dt=1e-3;
% buses
obj.inBus = [obj.modelname,'_inBus' ];
obj.outBus = [obj.modelname,'_outBus'];
obj.modelslx = [obj.modelname,'.slx'];
% files
% algo path depending on .slx location
assert(~isempty(which(obj.modelslx)),'can''t find slx model %s',obj.modelslx);
obj.folder = fileparts(which(obj.modelslx));
% Standard data dictionary equal to algorithm name,
% overriddable by the setter method
obj=obj.setdatadictionary([name '.sldd']);
......@@ -112,10 +126,9 @@ classdef SCDclass_algo
out = obj.datadictionary;
end
function out = opendatadictionarydesigndata(obj)
ddname = obj.getdatadictionary;
dict = Simulink.data.dictionary.open(ddname);
out=getSection(dict, 'Design Data');
function designDataObj = opendatadictionarydesigndata(obj)
dict = Simulink.data.dictionary.open(obj.getdatadictionary);
designDataObj = getSection(dict, 'Design Data');
end
function dictionaryObj = createdatadictionary(obj,varargin)
......@@ -134,7 +147,8 @@ classdef SCDclass_algo
end
% Create
dictionaryObj = Simulink.data.dictionary.create(dd);
ddpath = fullfile(obj.folder,dd);
dictionaryObj = Simulink.data.dictionary.create(ddpath);
end
function obj = setreferenceddatadictionaries(obj,refdd)
......@@ -362,20 +376,34 @@ classdef SCDclass_algo
fprintf('generating data dictionary %s\n',obj.getdatadictionary);
% generate/initialize data dictionary
dictionaryObj = obj.createdatadictionary;
designDataObj = opendatadictionarydesigndata(obj);
% link data dictionary to model and disable access to base
obj.load;
set_param(obj.getname,'DataDictionary',obj.getdatadictionary,'EnableAccessToBaseWorkspace','off');
set_param(obj.getname,'DataDictionary',obj.getdatadictionary,'EnableAccessToBaseWorkspace','on');
% call initialization functions to populate dd
% call initialization functions to populate dd with fixed parameters
obj.callinits;
% always reference configurations.sldd
dictionaryObj.addDataSource('configurations.sldd');
% populate with template tunable parameters
obj.updatetemplatetp;
% add buses
if ~isempty(which(obj.inBus)) && ~isempty(which(obj.outBus))
fprintf('Add buses to data dictionary: %s, %s\n',obj.inBus,obj.outBus);
eval(obj.inBus); % eval buses in base workspace
eval(obj.outBus);
addEntry(designDataObj,obj.inBus ,evalin('base',obj.inBus ));
addEntry(designDataObj,obj.outBus,evalin('base',obj.outBus));
evalin('base',sprintf('clear %s %s',obj.inBus,obj.outBus));
else
fprintf('no buses imported in datadictionary - assuming they are already there')
end
% also reference other optional data dictionaries (e.g. used by
% lower-level components of an algorithm)
for refdd = obj.refdatadictionaries
% add configurations.sldd as referenced data dictionary, plus
% other optional data dictionaries (e.g. used by lower-level components of an algorithm)
for refdd = ['configurations.sldd',obj.refdatadictionaries]
fprintf('adding referenced data dictionary %s to %s \n',refdd{:},obj.getdatadictionary)
dictionaryObj.addDataSource(refdd{:});
end
end
......
......@@ -28,7 +28,7 @@ classdef SCDalgo_test < matlab.unittest.TestCase
end
function test_test_harness(testCase)
testCase.algoobj.test_harness;
testCase.algoobj.test_harness;
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment