2

我目前正在开发一个 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
4

2 回答 2

0

这是我为操纵电池容量所做的,将 c 设置为输入而不是输出。删除底部的所有 C_table 和容量表查找实例,以防止设置 c 的两个实例。这有效地防止了计算由于温度引起的容量变化,但我发现这对我来说只是一个小小的不便。

这是功能块代码:

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
        C = {1,'A*hr'} % Cap:right
        T = {293.15,'K'} % T:right
    end

    outputs
        SOC = {1,'1'}   %SOC:left
    end

    parameters (Size=variable)
        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(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



        % 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
于 2015-04-27T08:18:35.270 回答
0

我的建议是删除这一行

 C_Table = {[1 1 1], 'A*hr'} % Capacity values at specified temperature breakpoints

C_Table并替换by 的任何实例Capacity

于 2015-04-23T14:08:41.363 回答