- To create the bus object before the model compiles using Simulink.Bus.createObject(thisStruct).
- In the MATLAB function block that in the model to create the struct output from the block. (the MATLAB function block must use the same bus name as the one you defined for the bus above.
Creating Instances of Bus Objects defined in the Bus Editor
24 views (last 30 days)
Show older comments
As I am Working with Multi Object Tracking I use many Simulink Bus objects and have to create many custom buses, often containing arrays of buses. The only way to do this in Simulink right now is using the Bus Editor. But if you want to create a Bus Object of this type, you defined in the Bus Editor, in a Matlab block, you have to define it all again using structs and then hand the struct to the output Bus. This is sometimes twice the work if you want to use arrays and have to use the repmat function to define an array of structures. There really should be an option to just create an instance of the Object defined in the Bus Editor, so you dont have to define all the fields again when using it in a Matlab Block. Maybe someone can tell me a way how to do this. Elseway this is a message for the MATLAB developers to think about adding a feature like this. Because right now everytime I want to use a new Sensor with the Multi Object Tracker Blocks i have to do way to much work, figuring out all the datatypes of the messages send by the sensor and creating an object for them in the Bus editor and also having to create a struct in the Matlab Block.
Also a feature to click on a bus and copy its definition into the Bus Editor would be great. But this would be just a little extra.
0 Comments
Answers (1)
Elad Kivelevitch
on 16 Apr 2021
Hi Niklas,
Thank you for your question and comments. I can definitely appreciate the difficulty in creating buses that you describe.
There are a few more options to create buses, which I don't know if you have considered.
One is described here using the bus creator block: https://www.mathworks.com/matlabcentral/answers/36626-what-is-the-difference-b-w-bus-editor-and-bus-creator-in-simulink?s_tid=answers_rc1-1_p1_Topic
For me, what usually works best is to define a separate function that knows how to convert the data you want to pass on the bus to a struct. For example:
function thisStruct = convertToStruct(thisData)
end
I then use this function in two places:
I hope this helps.
See Also
Categories
Find more on Simulink Environment Customization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!