为何Modelica中Derivative模块无法接入CombiTimeTable模块输入?
问题原因与修复方案
报错原因
你遇到的类型不匹配问题,是因为CombiTimeTable的输出y默认是向量类型(你的table是8行2列,输出对应1维向量),但Derivative的输入u是标量类型,两者无法直接连接。
修复方法
方法1:将CombiTimeTable输出改为标量
直接修改CombiTimeTable的outputFormat参数,强制输出为标量:
model chariot_portique Modelica.Blocks.Sources.CombiTimeTable combiTimeTable( extrapolation = Modelica.Blocks.Types.Extrapolation.HoldLastPoint, table = [0, 0; 4, 3; 8, 3; 12, 0; 16, 0; 20, -3; 24, -3; 28, 0], tableOnFile = false, outputFormat = Modelica.Blocks.Types.OutputFormat.Scalar) // 新增参数修改输出类型 annotation(Placement(transformation(extent = {{-80, 20}, {-60, 40}}))); Modelica.Blocks.Continuous.Derivative derivative(T = 1, k = 1) annotation(Placement(visible = true, transformation(origin = {-26, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); equation connect(combiTimeTable.y, derivative.u) annotation(Line(points = {{-58, 30}, {-38, 30}}, color = {0, 0, 127})); annotation(experiment(StopTime = 20), uses(Modelica(version = "4.0.0"))); end chariot_portique;
方法2:用Selector提取向量元素(适合多列数据场景)
如果后续需要处理多列数据、保留向量输出,可插入Modelica.Blocks.Math.Selector模块提取第一列数据:
model chariot_portique Modelica.Blocks.Sources.CombiTimeTable combiTimeTable( extrapolation = Modelica.Blocks.Types.Extrapolation.HoldLastPoint, table = [0, 0; 4, 3; 8, 3; 12, 0; 16, 0; 20, -3; 24, -3; 28, 0], tableOnFile = false) annotation(Placement(transformation(extent = {{-80, 20}, {-60, 40}}))); Modelica.Blocks.Math.Selector selector(index = 1) // 提取向量第1个元素 annotation(Placement(transformation(origin = {-47, 30}, extent = {{-10, -10}, {10, 10}}))); Modelica.Blocks.Continuous.Derivative derivative(T = 1, k = 1) annotation(Placement(visible = true, transformation(origin = {-26, 30}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); equation connect(combiTimeTable.y, selector.u) annotation(Line(points = {{-58, 30}, {-57, 30}})); connect(selector.y, derivative.u) annotation(Line(points = {{-37, 30}, {-36, 30}})); annotation(experiment(StopTime = 20), uses(Modelica(version = "4.0.0"))); end chariot_portique;
内容的提问来源于stack exchange,提问作者scls
相关产品推荐
相关产品推荐

