Search code examples
modelicadymolapid-controller

How to keep the output signal of a PID block unchanged after a fixed time point?


I build a fluid model with a PID control system, and I wanna run my model until reaching a steady state and then keep the output signal of the PID system unchanged, so I could do step excitation stability tests. But right now I am not sure how to keep the output signal of the PID control system unchanged after a fixed time point. So I have to use a logical switch to change the signal source at a fixed time point.
My question is:
How could keep the output signal of a Block Component unchanged after a fixed time point?

enter image description here


Solution

  • I dont't think there is a suitable block in the Modelica Standard Library.

    But would that code do it?

    model KeepValueTime
      extends Modelica.Blocks.Interfaces.SISO;
    
      parameter Modelica.Units.SI.Time t = Modelica.Constants.inf "Time at which the value shall be kept";
      Real u_keep(start=0) "Value to be output when 'keepValue = true'";
    
    equation 
      if time < t then
        y = u;
      else
        y = u_keep;
      end if;
    
      when time >= t then
        u_keep = u;
      end when;
    
      annotation (uses(Modelica(version="4.0.0")));
    end KeepValueTime;
    

    A bit more general with a Boolean input:

    model KeepValue
      extends Modelica.Blocks.Interfaces.SISO;
    
      Real u_keep(start=0) "Value to be output when 'keepValue = true'";
    
      Modelica.Blocks.Interfaces.BooleanInput keepValue annotation (Placement(transformation(
            extent={{-20,-20},{20,20}},
            rotation=0,
            origin={-120,80}), iconTransformation(extent={{-140,60},{-100,100}}, rotation=0)));
    
    equation 
      if not keepValue then
        y = u;
      else
        y = u_keep;
      end if;
    
      when keepValue then
        u_keep = u;
      end when;
    
      annotation (uses(Modelica(version="4.0.0")));
    end KeepValue;
    

    A quick test:

    Test Example

    ...seems to do what you need: Example Result