Switch Between Different Source Components
This example shows how you can try out several variants of a component in your model by pointing the Simscape Component block to different component files.
The component files used in this example are capacitor models with different levels of fidelity, to allow exploration of the effect of losses and nonlinearity. The source files are part of your product installation, located in the following namespace folder:
matlabroot/toolbox/physmod/simscape/supporting_files/example_libraries/+Capacitors
where matlabroot
is the MATLAB® root folder on your machine, as returned by entering
matlabroot
in the MATLAB Command Window. For more information about these capacitor models, see Case Study — Basic Custom Block Library.
To test capacitor models of different fidelity:
To create a new model with optimal settings for physical modeling, in the MATLAB Command Window, type:
sscnew
Open the Simscape > Utilities library and add the Simscape Component block to your model. At first, the block does not point to any component file, therefore it does not have any ports and the block icon says
Unspecified
.Double-click the block to open the source file selector dialog box.
Click and navigate to the folder containing the capacitor component files.
Select the
IdealCapacitor.ssc
file and click Open. The name of the source file appears in the text field of the source file selector dialog box, and the block name, description, and the link to source code appear in the Description pane.Note
Because the component file resides in a namespace, the file name in the selector dialog box field is the full name, starting from the namespace root.
Close the block dialog box. The block icon gets updated, based on the selected source component.
Note
The
+Capacitors
namespace folder contains image files, with the names corresponding to the Simscape™ component files, that define customized block icons. Therefore, when you point the Simscape Component block to theIdealCapacitor.ssc
source file, it uses theIdealCapacitor.jpg
in the same folder as the block icon. For details, see Customize the Block Icon.Build the test model and connect the blocks as shown in the following diagram.
Open the scope and simulate the model.
The Simscape Component block points to an ideal capacitor component. Simulation results show that, when the switch is flipped at t=5 seconds, the capacitor delivers 2.5 A to the load.
To switch to another capacitor model, open the Simscape Component block dialog box and click Description. It displays the currently selected component.
Click . The browser opens in the
+Capacitors
folder, because it contains the currently selected component.Select the
IdealUltraCapacitor.ssc
file and click Open. The name of the source file appears in the text field of the source file selector dialog box, and the block name, description, and the link to source code appear in the Description pane.Close the block dialog box. The block icon in the model diagram updates to reflect the new source component.
Rerun the simulation.
Simulation results show that, when the switch is flipped at t=5 seconds, the current delivered to the load is less than 2.5 A.
To make the effect more pronounced, open the block dialog box and increase the Rate of change of C with voltage V parameter value to 0.8 F/V.