为 PLECS 运行 Octave 脚本
我正在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于我如何使用 struct() 函数。我可以设置多个变量并将值设置为单个结构。这又解决了我在一个循环中执行 2 个模拟的问题。
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.