构建自定义组件



我在Simulink中有一个"Thermal Mass"块,它代表热质量,热质量是一种材料或材料组合存储内能的能力。在这个Simulink的标准块中,必须输入初始温度。只有一个信号可以连接到块。该块的源代码如下所示:

component mass
% Thermal Mass
% The block represents a thermal mass, which is the ability of a material 
% or combination of materials to store internal energy. The property is
% characterized by mass of the material and its specific heat.
%
% The block has one thermal conserving port. 
% The block positive direction is from its port towards the block. This
% means that the heat flow is positive if it flows into the block.
% Copyright 2005-2013 The MathWorks, Inc.
nodes
    M = foundation.thermal.thermal; % :top
end
parameters
    mass = { 1, 'kg' };              % Mass
    sp_heat = { 447, 'J/(kg*K)' };   % Specific heat
end
variables
    Q = { 0, 'J/s' }; % Heat flow
end
variables(Conversion=absolute)
    T = { 300, 'K' }; % Temperature
end
function setup
    % Parameter range checking
    if mass <= 0
        pm_error('simscape:GreaterThanZero','Mass')
    end
    if sp_heat <= 0
        pm_error('simscape:GreaterThanZero','Specific heat')
    end
end
branches
    Q : M.Q -> *;
end
equations
    T == M.T;
    Q == mass * sp_heat * T.der;
    assert(T>0, 'Temperature must be greater than absolute zero')
end
end

我想建立另一个组件,它的初始温度可以来自另一个块,这样它也可以在其他地方计算。一个输入参数和其他参数应该是一样的。我是Simulink的新手,对域名了解不多。知道怎么做吗?

谢谢!

在Simulink块上输入的参数通常用于初始值和块行为的调优。虽然新版本的Simulink将允许您在模拟期间调整一些参数,但其他参数将被锁定并且不可修改。这可能意味着您需要首先执行一个模型来计算您的热质量的初始值,然后使用该温度作为初始值启动第二次模拟。

我相信关于如何控制块参数的Simulink帮助将是有用的。根据你的模型的具体设计,这里发现的不同技术可能或多或少适用,但总的来说,我知道2种简单易行的方法来完成修改蒙版值。

  1. 将值设置为Matlab基本工作空间中的变量。
  2. 将块放置在遮罩子系统中。掩码可以用来定义一个变量,该变量可以被其中的所有块访问。

这是不可能的,虽然您可以执行一些预处理来确定初始温度,但您不能将其作为其他块的输入。

Jared描述的解决方法可能就是你正在寻找的。

实际上很少需要这样做,如果你告诉我们你为什么要设置这个,我们可能会帮助你。

最新更新