Four mode EMS simulation circuit for presentation
Afficher commentaires plus anciens
% Create and open a new model
modelName = 'MicrogridModel';
new_system(modelName);
open_system(modelName);
% ----- Add Blocks -----
% 3-phase grid source (440 V line voltage, 50 Hz)
add_block('simscape/Electrical/Sources/Programmable Voltage Source (Three-Phase)', [modelName '/Grid'], ...
'Position', [100 50 140 100]);
set_param([modelName '/Grid'], 'Frequency', '50', 'ACVoltage', '440');
% PV DC source (placeholder, e.g., 600 V)
add_block('simscape/Electrical/Sources/DC Voltage Source', [modelName '/PV_Source'], ...
'Position', [100 200 140 250]);
set_param([modelName '/PV_Source'], 'Voltage', '600');
% Battery (Table-Based, e.g., 768 V, 1556 Ah)
add_block('simscape/Electrical/Sources/Battery (Table-Based)', [modelName '/Battery'], ...
'Position', [100 350 140 400]);
set_param([modelName '/Battery'], 'NominalVoltage', '768', 'Capacity', '1556');
% DC-DC Converter (e.g., regulating 768V to 500V output)
add_block('simscape/Electrical/Semiconductors & Converters/DC-DC Converter', [modelName '/DC_DC'], ...
'Position', [250 200 300 260]);
set_param([modelName '/DC_DC'], 'NominalVoltage', '768', 'OutputVoltage', '500');
% Inverter (Universal Bridge)
add_block('simscape/Electrical/Sources/Universal Bridge', [modelName '/Inverter'], ...
'Position', [250 50 300 120]);
set_param([modelName '/Inverter'], 'PowerElectronicDevices', 'IGBT/Diode (4 quadrant)');
% Diesel generator (Synchronous Machine, 440 V)
add_block('simscape/Electrical/Machines/Synchronous Machine', [modelName '/DieselGen'], ...
'Position', [250 350 300 420]);
set_param([modelName '/DieselGen'], 'NominalVoltage', '440');
% Three-phase load (R=10 Ω, L=0.01 H)
add_block('simscape/Electrical/Elements/Series RLC Branch', [modelName '/Load'], ...
'Position', [450 200 500 250]);
set_param([modelName '/Load'], 'BranchType', 'RL', 'R', '10', 'L', '0.01');
% ----- Connect Blocks -----
add_line(modelName, 'Grid/1', 'Inverter/1'); % Grid to Inverter input
add_line(modelName, 'PV_Source/+', 'DC_DC/+','autorouting','smart');
add_line(modelName, 'Battery/+', 'DC_DC/-','autorouting','smart');
add_line(modelName, 'DC_DC/1', 'Inverter/3','autorouting','smart');
add_line(modelName, 'DC_DC/2', 'Inverter/4','autorouting','smart');
add_line(modelName, 'Inverter/1', 'Load/1');
add_line(modelName, 'Inverter/2', 'Load/2');
add_line(modelName, 'Inverter/3', 'Load/3');
add_line(modelName, 'DieselGen/1', 'Load/1');
add_line(modelName, 'DieselGen/2', 'Load/2');
add_line(modelName, 'DieselGen/3', 'Load/3');
% Save the constructed model
save_system(modelName);
There is no block named 'simscape/Electrical/Sources/Programmable Voltage Source (Three-Phase)'
>>
Réponses (1)
Answer from AI:
Here are the two simplest and most common ways to retrieve the exact library path programmatically or using the GUI.
Method 1: The gcb Trick (Fastest via GUI)
The command gcb stands for "Get Current Block". You can use it to copy the exact path directly from the Simulink Library Browser:
- Open your Simulink Library Browser.
- Locate the Programmable Voltage Source (Three-Phase) block.
- Left-click once on the block inside the Library Browser to highlight it.
- Go to the MATLAB Command Window and type:
matlab
gcb
5. MATLAB will output the precise internal path as a string (for example, sps_lib/Electrical Sources/
Programmable Voltage Source (Three-Phase)). Copy this output directly into your add_block command.
Method 2: Programmatic Search with find_system
Depending on your MATLAB version, this Simscape Electrical block is often contained inside the underlying power systems library (historically named sps_lib).
You can force MATLAB to search all block libraries to find the exact match by running this in your Command Window:
matlab
% Load the library into memory first to ensure it can be searched
load_system('sps_lib');
% Search for the exact block name inside the library
paths = find_system('sps_lib', 'Name', 'Programmable Voltage Source (Three-Phase)')
Put It Together: Your Corrected Script
Once you have verified the source path string using one of the methods above, format your code like this to prevent syntax errors:
matlab
% 1. Cleanly define your variables
modelName = 'my_model';
blockSource = 'sps_lib/Electrical Sources/Programmable Voltage Source (Three-Phase)'; % Replace with your exact gcb output
blockDest = [modelName, '/Grid'];
% 2. Add the block safely
add_block(blockSource, blockDest, 'Position', [100 50 140 100]);
Catégories
En savoir plus sur Sources dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!