Cannot Build Simscape Sublibraries

Hi all, I'm learning to use the Simscape environment and create custom libraries. I've run into an error trying to create a package with subdirectories. Using the THyd example from https://www.mathworks.com/help/simscape/lang/working-with-domain-parameters.html, my folders are structured as follows with my Documents\MATLAB folder which I've added with addpath:
- +TestModels
|-- +THyd
| |-- t_hyd.ssc
| |-- hyd_temp.ssc
| |-- h_temp_sensor.ssc
| |-- h_temp_ref.ssc
however when I try to run ssc_build TestModels I'm met with the following error:
Error using ssc_build
Failed to generate 'TestModels_lib'
Caused by:
Simscape file with package path 'THyd.t_hyd' 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 theSimscape file is moved or renamed, use its new package path.
• In TestModels.THyd.h_temp_ref (line 5)
where line 5 is the a = THyd.t_hyd node declaration. Removing +THyd from +TestModels and running ssc_build THyd works without issue. I can't seem to find record of this error anywhere else. Any thoughts on how to resolve the issue? I will be using the TestModels folder for future projects, so while just using THyd is fine for now I'm looking for a solution that allows subdirectories.

 Risposta accettata

Christopher
Christopher il 9 Giu 2023

0 voti

In spending a few more hours of trial and error I answered my own question, so here we go. The answer, as is often the case, is right in the error message. I was trying to declare an instance of THyd.t_hyd, when the actual path was TestModels.THyd.t_hyd. Creating a +package requires it be specified in the domain path, so that was my issue.
I actually realized this after working around the issue by creating a separate Simulink library and creating a subsystem within it as per https://www.mathworks.com/help/simulink/ug/adding-libraries-to-the-library-browser.html, so if you're experiencing the same or a similar error and the first method doesn't correct it, the attached link should do the trick. Happy coding!

Più risposte (0)

Categorie

Prodotti

Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by