Simulink Bus with Variable-Length nD Table
Show older comments
I am trying to write a library block that is configured by a structure stored in a Data Dictionary. I created two Bus types from my structure - the top-level block structure, and a 2D table structure.
p = Simulink.Parameter;
p.Value.Setting1 = 4.0;
p.Value.Setting2 = 2.3;
p.Value.Table1.Table = [ 2 2 ; 2 2 ];
p.Value.Table1.X = [ 1 2 ];
p.Value.Table1.Y = [ 3 4 ];
p.DataType = 'Bus: ns_Block';
% Create the Bus object from the MATLAB structure
p.CoderInfo.StorageClass = 'ExportedGlobal';
Simulink.Bus.createObject(p.Value);
ns_Table2D = Table1
ns_Block = slBus1;
ns_Block.Elements(3).DataType = 'Bus: ns_Table2D'
I then used this parameter as an input to a masked library block - it would configure some block settings, including an n-D Table, and the structure would be validated against my Bus type during compile time. However, the problem I'm running in to is that I don't always want my table to be the same size as the bus - sometimes I want it to be bigger or smaller, depending on the application - but I want my library block to be able to handle this. This works when the n-D Table is configured with Parameters for each entry (e.g. "Table data", "Breakpoints 1", etc.), but does not work when elements of a Bus structure are used. I don't quite understand the difference - the table data will still be statically assigned in the data dictionary, for example, instead of a 2x2 table it might be a 3x3 table.
I found Tunable Table Size in Generated Code but this still doesn't solve my problem and seems like a hack, I'm not trying to change the size of the table after compile time, I'm trying to change it before compile time.
What I am trying to do: I want a bus structure that represents an n-D Table that I can use the elements of in an n-D Table block (e.g. struct.Table, struct.X, etc.), whose shape (1D, 2D, etc.) will always be fixed but may be larger or smaller in the Data Dictionary/Base Workspace structure.
Edit: To clarify, let me give a real example of why I'm asking this question. I'm writing a number of blocks to control real-world actuators, like a throttle. A block to do this has a number of different tunable parameters - max/min duty cycle, PID gains, etc. - and a number of tables, e.g. "Speed/Load to Position" or "Position to Duty Cycle". While the calibration of a throttle will change between applications (the values of the structure), the control often does not (hence the library block). However, the size of the tables may change between applications - one application may have a [10 10] 2D table while the next might have a [12 12]. Maybe my solution is to simply set the Bus table structure to be as large as I will ever need and to interp2 the smaller table on to a large table, but it seems like this is something that should be easily accommodated by Simulink.
Answers (0)
Categories
Find more on Event Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!