FirstOrder

block FirstOrder "First order transfer function block (= 1 pole)"
    import Modelica.Blocks.Types.Init;

    parameter Real k(unit = "1") = 1 "Gain";
    parameter SIunits.Time T(start = 1) "Time Constant";
    parameter Modelica.Blocks.Types.Init initType = Modelica.Blocks.Types.Init.NoInit "Type of initialization (1: no init, 2: steady state, 3/4: initial output)"
        annotation (
            Evaluate = true,
            Dialog(group = "Initialization"));
    parameter Real y_start = 0 "Initial or guess value of output (= state)"
        annotation (Dialog(group = "Initialization"));

    extends Interfaces.SISO(y(start = y_start));
initial equation
    if initType == Init.SteadyState then 
        der(y) = 0;
    elseif initType == Init.InitialState or initType == Init.InitialOutput then 
        y = y_start;
    end if;
equation
    der(y) = (k * u - y) / T;

    annotation (
        Documentation(info = "<html>\n<p>\nThis blocks defines the transfer function between the input u\nand the output y as <em>first order</em> system:\n</p>\n<pre>\n               k\n     y = ------------ * u\n            T * s + 1\n</pre>\n<p>\nIf you would like to be able to change easily between different\ntransfer functions (FirstOrder, SecondOrder, ... ) by changing\nparameters, use the general block <strong>TransferFunction</strong> instead\nand model a first order SISO system with parameters<br>\nb = {k}, a = {T, 1}.\n</p>\n<pre>\nExample:\n   parameter: k = 0.3, T = 0.4\n   results in:\n             0.3\n      y = ----------- * u\n          0.4 s + 1.0\n</pre>\n\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {-80, 78}, 
                        {-80, -90}},
                    color = {192, 192, 192}), 
                Polygon(
                    lineColor = {192, 192, 192},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid,
                    points = {
                        {-80, 90}, 
                        {-88, 68}, 
                        {-72, 68}, 
                        {-80, 90}}), 
                Line(
                    points = {
                        {-90, -80}, 
                        {82, -80}},
                    color = {192, 192, 192}), 
                Polygon(
                    lineColor = {192, 192, 192},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.Solid,
                    points = {
                        {90, -80}, 
                        {68, -72}, 
                        {68, -88}, 
                        {90, -80}}), 
                Line(
                    origin = {-26.667, 6.667},
                    points = {
                        {106.667, 43.333}, 
                        {-13.333, 29.333}, 
                        {-53.333, -86.667}},
                    color = {0, 0, 127},
                    smooth = Smooth.Bezier), 
                Text(
                    lineColor = {192, 192, 192},
                    extent = {
                        {0, -60}, 
                        {60, 0}},
                    textString = "PT1"), 
                Text(
                    extent = {
                        {-150, -150}, 
                        {150, -110}},
                    textString = "T=%T")}),
        Diagram(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Text(
                    extent = {
                        {-48, 52}, 
                        {50, 8}},
                    textString = "k"), 
                Text(
                    extent = {
                        {-54, -6}, 
                        {56, -56}},
                    textString = "T s + 1"), 
                Line(points = {
                    {-50, 0}, 
                    {50, 0}}), 
                Rectangle(
                    extent = {
                        {-60, 60}, 
                        {60, -60}},
                    lineColor = {0, 0, 255}), 
                Line(
                    points = {
                        {-100, 0}, 
                        {-60, 0}},
                    color = {0, 0, 255}), 
                Line(
                    points = {
                        {60, 0}, 
                        {100, 0}},
                    color = {0, 0, 255})}));
end FirstOrder;