我目前正在开发一个 simulink 模拟器,现在我正在尝试自定义一个 simscape 块,以便我可以将参数作为输入而不是固定值。
我已经添加了容量输入,但我不知道如何正确地将其传播到 C_Table,因为在生成库块时它需要是 1x3 向量。有人能帮我解决这个问题吗?
整个区块的代码:
component Em_tableMod
% Em_tableMod
% This block implements the cell's main branch voltage source, and determines
% values for capacity (C) and state of charge (SOC). The defining equations
% depend on cell temperature, T.
% Copyright 2012-2013 The MathWorks, Inc.
nodes
p = foundation.electrical.electrical; % +:left
n = foundation.electrical.electrical; % -:right
end
inputs
T = {293.15,'K'} % T:right
Capacity = {[0 0 0], 'A*hr'} % Cap:right
end
outputs
C = {31,'A*hr'} %C:left
SOC = {1,'1'} %SOC:left
end
parameters (Size=variable)
C_Table = {[1 1 1], 'A*hr'} % Capacity values at specified temperature breakpoints
Em_Table = {3.8*ones(5,3),'V'} % Matrix of voltage values, Em(SOC,T)
SOC_Table = {[0;0.1;0.5;0.9;1],'1'} % State of charge (SOC) breakpoints
Temp_Table = {[273.15 293.15 313.15],'K'} % Temperature (T) breakpoints
end
parameters
Qinit = {0,'A*hr'} % Initial charge deficit
end
variables(Access=private)
i = { 0, 'A' }; % Current
v = { 0, 'V' }; % Voltage
Qe = {0,'A*hr'}; % Charge deficit
end
function setup
% Check parameter values
if any(value(C_Table,'A*hr')<=0)
pm_error('simscape:GreaterThanZero','Capacity values at specified temperature breakpoints');
end
if any(any(value(Em_Table,'V')<=0))
pm_error('simscape:GreaterThanZero','Matrix of voltage values, Em(SOC,T)');
end
if any(value(SOC_Table,'1')<0)
pm_error('simscape:GreaterThanOrEqualToZero','State of charge (SOC) breakpoints');
end
if any(value(Temp_Table,'K')<0)
pm_error('simscape:GreaterThanOrEqualToZero','Temperature (T) breakpoints');
end
if value(Qinit,'A*hr')<0
pm_error('simscape:GreaterThanOrEqualToZero','Initial charge deficit');
end
% Set initial charge deficit
Qe = Qinit;
end
branches
i : p.i -> n.i;
end
equations
v == p.v - n.v;
% Charge deficit calculation, preventing SOC>1
if Qe<0 && i>0
Qe.der == 0;
else
Qe.der == -i;
end
% Perform the capacity table lookup
C == tablelookup(Temp_Table,C_Table,T,...
interpolation=linear,extrapolation=nearest)
% SOC Equation
SOC == 1 - Qe/C;
% Electrical equation by table lookup
v == tablelookup(SOC_Table,Temp_Table,Em_Table,SOC,T,...
interpolation=linear,extrapolation=nearest)
end
end