'Running an Octave script for PLECS

I am simulating a Dual Active Bridge with a digital control system in PLECS (similar to Simulink). What I want to do is to run a sequence of simulations where I change two variables related to the controller(Kp and Ki), to do this parameter sweep I have to create a simulation script in Octave. I have followed the official tutorial (https://www.youtube.com/watch?v=RB3EdvIE7ds&ab_channel=Plexim), however I didn't manage to achieve an appropriate sweep of the variables. I expect an output result from majority of the parameter sweeps, however I don't get an output from most of them*. The issues I am seeing: Some values aren't imported correctly. Sometimes are real-time result presents an output waveform, however when the trace is automatically saved it disappears.

What I have tried: I have tried changing the initialization value of Kp and Ki to 0, then to 1. This resulted in invalid results where the system essentially does nothing. Changing the data in the .csv file to be in general format rather than scientific.

What I think is happening: the "plecs('simulate', ...)" commands are running individually causing 2 separate simulations to be executed. I don't know how I would solve this issue, but would I have to combine the Kp and Ki structures together and use that as an argument of "plecs('simulate', ...)" function?

mdl = plecs('get', '', 'CurrentCircuit');
scopepath = [mdl '/Output'];
% clear all previous traces in scope 'Scope' in the current model
plecs('scope', scopepath, 'ClearTraces');

potentialStructure = struct('Kp', 0.0000819); %default value KP
integralStructure = struct('Ki', -0.0000505); %default value Ki
potStructure = struct('ModelVars', potentialStructure); %KP simStruct with 'ModelVars
intStructure = struct('ModelVars', integralStructure); %KI simStruct with 'ModelVars

Kpd = dlmread ('Digital Controller PI Values.csv',',', 'A2:A194'); %read first column
Kid = dlmread ('Digital Controller PI Values.csv',',', 'B2:B194'); %read second column


for ix = 1:length(Kpd) %how many loops - same as number of rows
  potStructure.ModelVars.Kp = Kpd(ix); %set value of KP
  intStructure.ModelVars.Ki = Kid(ix); %set value of KI
  plecs('simulate', potStructure); %override the Kp value in the model during each simulation run
  plecs('simulate', intStructure); %override the Ki value in the model during each simulation run
  %hold and label trace
  plecs('scope', scopepath, 'HoldTrace', ['Kp = ' mat2str(Kpd(ix)) ' Ki = ' mat2str(Kid(ix))]); 
end

[Simulation Results, Code, Data][1]

*The invalid results are the ones that can be seen as a straight line at 0 in the image attached [1]: https://i.stack.imgur.com/SXHfW.png



Solution 1:[1]

The issue lied how I was using the struct() function. I could set multiple variables and with set value to the single struct. This in turn solved my issue where I was executing 2 simulations in a single loop.

mdl = plecs('get', '', 'CurrentCircuit');
scopepath = [mdl '/Output'];
% clear all previous traces in scope 'Scope' in the current model
plecs('scope', scopepath, 'ClearTraces');

mdlVars = struct('Kp', 0.0000819, 'Ki', -0.0000505 ); %default value KP
simStruct = struct('ModelVars', mdlVars); %KP simStruct with 'ModelVars


Kpd = dlmread ('Digital Controller PI Values.csv',',', 'A2:A194'); %read first column
Kid = dlmread ('Digital Controller PI Values.csv',',', 'B2:B194'); %read second column


for ix = 1:length(Kpd) %how many loops - same as number of rows
  simStruct.ModelVars.Kp = Kpd(ix); %set value of KP
  simStruct.ModelVars.Ki = Kid(ix); %set value of KI
  plecs('simulate', simStruct); %override the Kp value in the model during each simulation run
  %hold and label trace
  plecs('scope', scopepath, 'HoldTrace', ['Kp = ' mat2str(Kpd(ix)) ' Ki = ' mat2str(Kid(ix))]); 
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Polo