Search code examples
componentsmodelicaopenmodelica

How can I modify "Force2" component?


I'd like to ask for your help with the code I'm trying to write. I'd like to modify the "Force2" component to ask it to translate the force when the boolean displays true, and to give a force equal to 0 when the boolean displays false. Boolean governed by the position value of a sweptvolume. To do this, I first did this:

 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;

To see if it would display 5 and 0 as force according to the boolean data, which works. To generalize, I did this:

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;

which doesn't work, certainly because I'm asking it to take into account the values of a lambda sweptvolume. This modeling will certainly be clearer in explaining why I wrote this program.enter image description here In a second case, seeing that this last program didn't work, I asked that when the boolean displays true, my component should act as a rigid body, which gives me this:

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;

But I get this error:

"[ForceBleue: 96:1-96:8]: No viable alternative near token: extends"

New code:

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;

Do you have any tips on how to get what I'm looking for please? Thanks in advance for your help, Emma


Solution

  • After reading the comments, especially

    What I'm looking for is that once the position of my SweptVolume reaches 0.18m, the force is transmitted, otherwise F=0.

    I think the solution is actually the Modelica.Mechanics.Translational.Components.ElastoGap itself. I'm not sure if that helps, but the result is too large for a comment:

    Graphical description of model

    The result is:

    Result of model above

    and the corresponding code:

    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;
    

    In case the behavior is not correct when the force switches sign, try to add another ElastoGap flipped horizontally (which I didn' test)...