How do I output a bus object from a constant block in Simulink? Keep encountering errors that I can't figure out...

7 visualizaciones (últimos 30 días)
I'm working on a project where I want to use a constant block to output a bus object that will be fed into the bus input port on a bus assignment block. I also want to store this constant data in the model workspace, but the bus object itself comes from a data dictionary.
I currently have the model workspace with my parameter set up like this:
And when I try to Update Diagram, the error that the diagnostic viewer always returns is:
The main thing that confuses me is that I copied this format for outputting a bus from a constant in the model workspace from another model where it works flawlessly. I have checked and double checked that I have it set up the same, yet Simulink does not seem to think that the parameter is actually set as a struct.

Respuesta aceptada

George Pence
George Pence el 31 de En. de 2018
I discovered how to correct the error with the advice of a coworker. Essentially when I exported my Simulink parameter object and examined the code, it was labeled as a struct that output the desired bus object, but had none of the actual data information.
Normally, I would think Matlab would already link to the bus object that was specified and output the proper data fields, but apparently it does not.
My code looked like this:
Input = Simulink.Parameter;
saveVarsTmp{1} = struct;
saveVarsTmp{1}.flag = 0;
% No data in between these lines :(
Input.Value = saveVarsTmp{1};
Input.CoderInfo.StorageClass = 'Auto';
Input.CoderInfo.Alias = '';
Input.CoderInfo.Alignment = -1;
Input.CoderInfo.CustomStorageClass = 'Default';
Input.CoderInfo.CustomAttributes.ConcurrentAccess = false;
Input.Description = '';
Input.DataType = 'Bus: platformState_IO';
Input.Min = [];
Input.Max = [];
Input.DocUnits = '';
clear saveVarsTmp;
But the proper format should have been this:
Input = Simulink.Parameter;
saveVarsTmp{1} = struct;
saveVarsTmp{1}.flag = 0;
% -----------------------
saveVarsTmp{1}.data.dataName1= single(0); % single value data
saveVarsTmp{1}.data.dataName2= single(0); % single value data
saveVarsTmp{1}.data.dataName3= single( ...
[0; 0; 0]); % data with dimension of 3
% -----------------------
Input.Value = saveVarsTmp{1};
Input.CoderInfo.StorageClass = 'Auto';
Input.CoderInfo.Alias = '';
Input.CoderInfo.Alignment = -1;
Input.CoderInfo.CustomStorageClass = 'Default';
Input.CoderInfo.CustomAttributes.ConcurrentAccess = false;
Input.Description = '';
Input.DataType = 'Bus: platformState_IO';
Input.Min = [];
Input.Max = [];
Input.DocUnits = '';
clear saveVarsTmp;
After this, I imported the edited .m file back into my model workspace and immediately all errors went away.

Más respuestas (0)

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by