主要内容

自定义模块显示

R2026b

此示例展示了一个包含注解的完整组件文件,以及生成的库模块和对话框。图像文件 custom_spring.svg 与组件文件位于同一文件夹中。此示例说明了Customizing the Block Name and Appearance中所述的基本方法。

component spring 
% Rotational Spring
% This block implements a simple rotational spring.
  nodes
    r = foundation.mechanical.rotational.rotational; % rod
    c = foundation.mechanical.rotational.rotational; % case
  end 
  annotations
    r : Side = left;
    c : Side = right;
    Icon = 'custom_spring.svg';
  end
  parameters
    k = { 10, 'N*m/rad' }; % Spring rate
  end 
  variables
    theta = { 0, 'rad' };  % Deformation
    t = { 0, 'N*m' };      % Torque
    w = { 0, 'rad/s' };    % Angular velocity
  end
  branches
    t : r.t -> c.t;
  end
  equations
    assert(k>0)
    w == r.w - c.w; 
    t == k * theta; 
    w == der(theta);     
  end
end

另请参阅

主题