Trying to generate code from the command line only for blocks within a model reference
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a Simulink top-level model which contains a model reference. The contents of the top-level model are there purely for simulation. I don't need to generate code for anything that exists in the top-level model. The model reference however, contains my controller that ultimately runs on a microcontroller. The contents of the model reference are the only code I need to generate. Here is a snippet of the top-level model showing the model reference (Control_Restructured).

Inside the model reference block looks like this:

The Control subsystem contains all of the blocks of my referenced model. What I have been doing to generate code is simply right click on the Control block, Choose C/C++ Code, and then Click Embedded Code Quick Start. There are some Code Generation parameters setup on the Control subsystem block that ensure the file and function names are what we want, etc.
I'm not the original author of this whole configuration. I believe it was done this way to keep the controller, which needs to be generated into code separate from everything needed for simulation. For what we've been doing so far it has worked well.
Now we are getting ready to release the software and we want to generate code from our build server and I need to introduce some parameters to create two different build configurations. The best way I've come up with to do this is to generate the code from the Matlab command line. The catch seems to be that the model reference creates a hierarchy that doesn't let me directly pass a path to the Control submodule into rtwbuild(). I can pass the top-level model but then it tries to generate code for both that model and the referenced model.
A BlockPath object to the Control submodule looks like this:
ans =
Simulink.BlockPath
Package: Simulink
Block Path:
Restructured_System_model_Vyper_Python/Model1
Control_Restructured/Control
However, I can't pass a BlockPath object to rtwbuild(). I can only pass a text string. Is there a way to create a single text string path to the block I need to generate code on? Is there a better way I should do this?
Any help is appreciated.
0 Commenti
Risposta accettata
Altaïr
il 18 Feb 2025
The Block Path value of a Simulink.BlockPath object represents the model hierarchy. To extract the block path string from this object, the getBlock function can be used. An index corresponding to the model hierarchy can be specified in the getBlock function. For example, here are the expected results for the Simulink.BlockPath object in question:
getBlock(ans, 1)
This returns: 'Restructured_System_model_Vyper_Python/Model1'
getBlock(ans, 2)
This returns: 'Control_Restructured/Control'
This indicates that the model 'Control_Restructured/Control' is at a lower heirarchy and is referenced by the model 'Restructured_System_model_Vyper_Python/Model1'. To learn more about the getBlock function, the following command can be used:
doc getBlock
The procedure of navigating into Model1 in the top-level model, right-clicking the Control subsystem, and using Embedded Code Quick Start is equivalent to generating code using the second block path ('Control_Restructured/Control'). The primary command equivalent to this GUI action, after running gcbp in the command line to get the Simulink.BlockPath object, is:
rtwbuild(getBlock(ans, 2))
Additional arguments available with the rtwbuild function can be accessed through the following command:
web(fullfile(docroot, 'ecoder/ref/rtwbuild.html#namevaluepairs'))
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Deployment, Integration, and Supported Hardware in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!