为 PLECS 运行 Octave 脚本

发布于 2025-01-14 16:20:32 字数 1979 浏览 2 评论 0原文

我正在 PLECS 中使用数字控制系统模拟双有源桥(类似于 Simulink)。我想做的是运行一系列模拟,在其中更改与控制器相关的两个变量(Kp 和 Ki),要进行此参数扫描,我必须在 Octave 中创建一个模拟脚本。我已按照官方教程进行操作(https://www.youtube.com/watch ?v=RB3EdvIE7ds&ab_channel=Plexim),但是我没有设法对变量进行适当的扫描。 我期望大多数参数扫描的输出结果,但是我没有得到大多数参数扫描的输出*。我看到的问题: 某些值未正确导入。 有时,实时结果会呈现输出波形,但是当自动保存迹线时,它会消失。

我尝试过的: 我尝试将 Kp 和 Ki 的初始化值更改为 0,然后更改为 1。这会导致无效结果,系统基本上不执行任何操作。 将 .csv 文件中的数据更改为通用格式而不是科学格式。

我认为正在发生的事情: “plecs('simulate', ...)”命令单独运行,导致执行 2 个单独的模拟。我不知道如何解决这个问题,但是我是否必须将 Kp 和 Ki 结构组合在一起并将其用作“plecs('simulate', ...)”函数的参数?

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

[仿真结果、代码、数据][1]

*无效结果是附图中0处可以看到的直线 [1]: https://i.sstatic.net/SXHfW.png

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.sstatic.net/SXHfW.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧瑾黎汐 2025-01-21 16:20:32

问题在于我如何使用 struct() 函数。我可以设置多个变量并将值设置为单个结构。这又解决了我在一个循环中执行 2 个模拟的问题。

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文