如何修改“Force2”组件?

问题描述 投票:0回答:1

我想请求您帮助我编写我正在编写的代码。 我想修改“Force2”组件,要求它在布尔值显示 true 时平移力,并在布尔值显示 false 时给出等于 0 的力。由扫描体积的位置值控制的布尔值。 为此,我首先这样做了:

 model ForceBleue extends
 Modelica.Mechanics.Translational.Interfaces.PartialTwoFlanges;   
 Modelica.Blocks.Interfaces.BooleanInput u "Connector of Boolean input
 signal"annotation (Placement(transformation(
 extent={{-20,-20},{20,20}},
 rotation=270,
 origin={0,60}), iconTransformation(
 extent={{-20,-20},{20,20}},
 rotation=270,
 origin={0,40})));
 
 equation  if u == true then    flange_a.f = 5;      flange_b.f = 5 ; 
    else     flange_a.f = 0;      flange_b.f = 0;  end if;   annotation
    (defaultComponentName="force",
   Documentation(info="<html> <p> The input signal \"f\" in [N] characterizes an <em>external force</em> which acts (with positive
    sign) at both flanges, i.e., the components connected to these flanges
    are driven by force f. </p> <p> Input signal s can be provided from
    one of the signal generator blocks of Modelica.Blocks.Source. </p>
    
   </html>"),
     Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},
    {100,100}}), graphics={Text(
    extent={{-150,-40},{150,-80}},
    textString="%name",
    textColor={0,0,255}),Polygon(          points={{90,0},{60,-30},{60,-10},{10,-10},{10,10},{60,10},{60,30},{90,0}},
    lineColor={0,127,0},
   fillColor={160,215,160},
    fillPattern=FillPattern.Solid),    Polygon(
    points={{-90,0},{-60,30},{-60,10},{-10,10},{-10,-10},{-60,-10},{-60,-30},{-90,0}},
   lineColor={0,127,0},
   fillColor={160,215,160},
   fillPattern=FillPattern.Solid)}));  end ForceBleue;

看是否会根据布尔数据将5和0显示为force,有效。 概括而言,我这样做了:

model ForceBleue "Input signal acting as torque on two flanges"
extends Modelica.Mechanics.Translational.Interfaces.PartialTwoFlanges;
   Modelica.Blocks.Interfaces.BooleanInput u "Connector of Boolean input signal"annotation (Placement(transformation(
        extent={{-20,-20},{20,20}},
        rotation=270,
        origin={0,60}), iconTransformation(
        extent={{-20,-20},{20,20}},
        rotation=270,
        origin={0,40})));

equation
 if u == true then
   flange_a.f = Modelica.Fluid.Machines.SweptVolume.flange.f ;  
   flange_b.f = -Modelica.Fluid.Machines.SweptVolume.flange.f ;
 else 
   flange_a.f = 0;  
   flange_b.f = 0;
 end if;
  annotation (defaultComponentName="force",
    Documentation(info="<html>
<p>
The input signal \"f\" in [N] characterizes an <em>external
force</em> which acts (with positive sign) at both flanges,
i.e., the components connected to these flanges are driven by force f.
</p>
<p>
Input signal s can be provided from one of the signal generator
blocks of Modelica.Blocks.Source.
</p>

</html>"),
       Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},
            {100,100}}), graphics={Text(
              extent={{-150,-40},{150,-80}},
              textString="%name",
              textColor={0,0,255}),Polygon(
          points={{90,0},{60,-30},{60,-10},{10,-10},{10,10},{60,10},{60,30},{90,0}},
          lineColor={0,127,0},
          fillColor={160,215,160},
          fillPattern=FillPattern.Solid),    Polygon(
          points={{-90,0},{-60,30},{-60,10},{-10,10},{-10,-10},{-60,-10},{-60,-30},{-90,0}},
          lineColor={0,127,0},
          fillColor={160,215,160},
          fillPattern=FillPattern.Solid)}));
end ForceBleue;

这不起作用,当然是因为我要求它考虑 lambda 扫描体积的值。 这个模型肯定会更清楚地解释我为什么编写这个程序。 在第二种情况下,看到最后一个程序不起作用,我要求当布尔值显示 true 时,我的组件应该充当刚体,这给了我这个:

model ForceBleue
extends Modelica.Mechanics.Translational.Interfaces.PartialTwoFlanges;
   Modelica.Blocks.Interfaces.BooleanInput u "Connector of Boolean input signal"annotation (Placement(transformation(
        extent={{-20,-20},{20,20}},
        rotation=270,
        origin={0,60}), iconTransformation(
        extent={{-20,-20},{20,20}},
        rotation=270,
        origin={0,40})));

equation
 if u == true then
  extends Modelica.Mechanics.Translational.Interfaces.PartialRigid;
 else 
   flange_a.f = 0;  
   flange_b.f = 0;
 end if;
  annotation (defaultComponentName="force",
    Documentation(info="<html>
<p>
The input signal \"f\" in [N] characterizes an <em>external
force</em> which acts (with positive sign) at both flanges,
i.e., the components connected to these flanges are driven by force f.
</p>
<p>
Input signal s can be provided from one of the signal generator
blocks of Modelica.Blocks.Source.
</p>

</html>"),
       Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},
            {100,100}}), graphics={Text(
              extent={{-150,-40},{150,-80}},
              textString="%name",
              textColor={0,0,255}),Polygon(
          points={{90,0},{60,-30},{60,-10},{10,-10},{10,10},{60,10},{60,30},{90,0}},
          lineColor={0,127,0},
          fillColor={160,215,160},
          fillPattern=FillPattern.Solid),    Polygon(
          points={{-90,0},{-60,30},{-60,10},{-10,10},{-10,-10},{-60,-10},{-60,-30},{-90,0}},
          lineColor={0,127,0},
          fillColor={160,215,160},
          fillPattern=FillPattern.Solid)})); 
end ForceBleue;

但我收到此错误:

“[ForceBleue:96:1-96:8]:令牌附近没有可行的替代方案:扩展”

新代码:

model ForceBleue "Input signal acting as torque on two flanges"
extends Modelica.Mechanics.Translational.Interfaces.PartialTwoFlanges;
   Modelica.Blocks.Interfaces.BooleanInput u "Connector of Boolean input signal"annotation (Placement(transformation(
        extent={{-20,-20},{20,20}},
        rotation=270,
        origin={0,60}), iconTransformation(
        extent={{-20,-20},{20,20}},
        rotation=270,
        origin={0,40})));
   Modelica.Units.SI.Position s_rel(start=0);
equation
  flange_b.f= if u then -flange_a.f else 0;
  s_rel= flange_b.s - flange_a.s; "The load must continue to move despite the position 0.18 reached."
end ForceBleue;

您对如何获得我正在寻找的东西有什么建议吗? 在此先感谢您的帮助, 艾玛

components modelica openmodelica
1个回答
0
投票

看完评论后,尤其是

我要寻找的是,一旦我的SweptVolume的位置达到0.18m,力就被传递,否则F=0。

我认为解决方案实际上是

Modelica.Mechanics.Translational.Components.ElastoGap
本身。我不确定这是否有帮助,但结果太大,无法发表评论:

结果是:

以及对应的代码:

model ElastoGapTest
  Modelica.Mechanics.Translational.Sources.ConstantForce constantForce(f_constant=1)
    annotation (Placement(transformation(extent={{-70,-10},{-50,10}})));
  Modelica.Mechanics.Translational.Components.ElastoGap elastoGap(
    s_rel(fixed=true),
    v_rel(fixed=true),
    c=1e6,
    d=1e6,
    s_rel0=-0.18) annotation (Placement(transformation(extent={{10,-10},{30,10}})));
  Modelica.Mechanics.Translational.Components.Mass load(
    m=1,
    s(fixed=true),
    v(fixed=true)) annotation (Placement(transformation(extent={{50,-10},{70,10}})));
  Modelica.Mechanics.Translational.Components.Mass actuator(
    m=0.1,
    s(fixed=true),
    v(fixed=true)) annotation (Placement(transformation(extent={{-30,-10},{-10,10}})));
equation 
  connect(load.flange_a, elastoGap.flange_b) annotation (Line(points={{50,0},{30,0}}, color={0,127,0}));
  connect(actuator.flange_a, constantForce.flange) annotation (Line(points={{-30,0},{-50,0}}, color={0,127,0}));
  connect(actuator.flange_b, elastoGap.flange_a) annotation (Line(points={{-10,0},{10,0}}, color={0,127,0}));
  annotation (uses(Modelica(version="4.0.0")));
end ElastoGapTest;

如果力切换符号时行为不正确,请尝试添加另一个水平翻转的

ElastoGap
(我没有测试)...

© www.soinside.com 2019 - 2024. All rights reserved.