Simulink - 构建自定义组件

时间:2016-08-24 08:47:06

标签: matlab components block simulink simscape

我在Simulink中有一个“热质量”块,它代表一个热质量,它是材料或材料组合存储内部能量的能力。在此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的新手,对域名不太了解。任何想法,如何做到这一点?

谢谢!

2 个答案:

答案 0 :(得分:0)

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

我相信Simulink有助于了解control block parameters如何有用。根据您的模型的具体设计,这里找到的不同技术可能或多或少适用,但一般来说,我知道有两种简单而简单的方法来完成修改掩码值。

  1. 将值设置为Matlab基础工作区中的变量。
  2. 将块放在Masked subsystem内。掩码可用于定义可供其中所有块访问的变量。

答案 1 :(得分:0)

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

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

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

相关问题