Simulink.Bus and Embedded Coder

14 views (last 30 days)
I have a few Matlab files that work correctly and implement the functionality I need. I am now trying to port them to Simulink/Embedded Coder using the "Matlab Function" block. After resolving a number of "not supported" type problems, I am stuck on a problem that I don't know how to resolve.
The issue is this- the Matlab functions use a structure to keep track of the system state. They modify the state and pass it on to each other. Embedded Coder indicated that structs were not supported, so I added the following line that I found in a Matlab blog post- "outputState = Simulink.Bus.createObject(state);"
That seemed to improve things in that Embedded Coder got "farther". Now, though, it says the following- "Function 'Simulink.Bus' is not supported for code generation. Consider adding coder.extrinsic('Simulink.Bus') at the top of the function to bypass code generation." I tried adding the extrinsic, but it just came up with another error.
Can you use structs in Embedded Coder? If so, what do I need to do. I could break the state struct into individual values/arrays, but it would be very ugly and painful. Thanks for your time and help.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 5 Nov 2012
You need to specify the Bus type on the Ports and Data Manager of the MATLAB Function block, not in the MATLAB code itself. Please see Attach Bus Signals to MATLAB Function Blocks.
  2 Comments
Jim Clay
Jim Clay on 5 Nov 2012
Thank you, Kaustubha, this appears to be very helpful. I am getting closer to being able to create the Simulink.Bus object in my workspace, but I'm not quite there yet. I have some empty arrays in the struct that I use as dynamic buffers, but it appears to not like the fact that the arrays are empty. I'm guessing that it would also not like the arrays changing size during processing. I take it that I will have to set a fixed size and then keep track of the "true" size myself at runtime?
Kaustubha Govind
Kaustubha Govind on 6 Nov 2012
Signals whose size changes during simulation are called variable-size signals. I don't think variable-size signals can have an empty size (at least as of R2012b), but you can certainly have a variable-size signal as an element of a bus. See How can I create an output bus with variable dimensions using a structure in Embedded MATLAB?

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!