Why does "subsystem2ssc" generate code that cannot be built using "ssc_build" if the subsystem contains further subsystems?

4 次查看(过去 30 天)
I wanted to generate a Simscape library block for a subsystem in a model, where the subsystem contained further subsystems. Therefore I wanted to use "subsystem2ssc" to generate the SSC files for my component, place all the SSC files in a package directory, and then use "ssc_build" to make the single Simscape component for my top-level subsystem.
However, when trying to do "ssc_build" it errors with the following:
Error using ssc_build
Failed to generate 'mySSCFiles_lib'
Caused by:
Simscape file with package path 'myNestedSubsystem1' is not on MATLAB path and not in import context declared by import statements. Ensure the Simscape file is on MATLAB path or in import context. If the Simscape file is
moved or renamed, use its new package path.
In mySSCFiles.mySubsystem (line 17)
I then tried expanding every subsystem that is inside the top-level subsystem that I wanted to use "subsystem2ssc" on, and then it generated the single SSC file that I could use "ssc_build" on to build my component.
Is this a limitation of "subsystem2ssc" with nested subsystems?

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2024-2-29
The behaviour you are experiencing is expected as "subsystem2ssc" does not really know anything about the package hierarchy the user eventually wants to put the files in (it may not necessarily be the folder you generate the files into). So we generate the files in a flat hierarchy, which works when using a Simscape component block.
Therefore in order to run "ssc_build" or "ssc_mirror" you would have to edit paths in the files to match your intended package structure. An example of this is provided below:
 
If we have a subsystem called "mySubsystem" that contains two further subsystems inside, named "A" and "B", and we execute "subsystem2ssc" on "mySubsystem" we generate 3 SSC files, "mySubsystem.ssc", "A.ssc", and "B.ssc". We place these inside a package directory named "+mySSCFiles" and then want to execute "ssc_build" to generate the Simscape component for "mySubsystem". However, currently, the Components section of the "mySubsystem.ssc" file looks like the following:
components(ExternalAccess = observe)
A = A;
B = B;
end
So you will need to append the location of the components to the package directory they are in (even if it is the same package directory). So the following change needs to be made:
components(ExternalAccess = observe)
A = mySubsystem.A;
B = mySubsystem.B;
end
This limitation is mentioned on the following documentation page in the final paragraph of the "Suggested Workflows" section:
As mentioned in the above documentation "you have to edit the subcomponent paths in the generated files manually to match your intended package structure".  However, a potential alternative is to write a short script that uses "pwd" to identify the current folder name and then do a find-and-replace script that parses the generated SSC files to append the package name before the components.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Composite Components 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by