Position

model Position "Forced movement of a flange according to a reference position"
    extends Modelica.Mechanics.Translational.Interfaces.PartialElementaryOneFlangeAndSupport2(s(stateSelect = if exact then StateSelect.default else StateSelect.prefer));

    parameter Boolean exact = false "Is true/false for exact treatment/filtering of the input signal, respectively";
    parameter SI.Frequency f_crit = 50 "If exact=false, critical frequency of filter to filter input signal"
        annotation (Dialog(enable = not exact));
    SI.Velocity v(start = 0, stateSelect = if exact then StateSelect.default else StateSelect.prefer) "If exact=false, absolute velocity of flange else dummy";
    SI.Acceleration a(start = 0) "If exact=false, absolute acceleration of flange else dummy";
    Modelica.Blocks.Interfaces.RealInput s_ref(unit = "m") "Reference position of flange as input signal"
        annotation (Placement(transformation(extent = {
            {-140, -20}, 
            {-100, 20}})));
protected
    parameter Modelica.SIunits.AngularFrequency w_crit = 2 * Modelica.Constants.pi * f_crit "Critical frequency";
    constant Real af = 1.3617 "s coefficient of Bessel filter";
    constant Real bf = 0.618 "s*s coefficient of Bessel filter";
initial equation
    if not exact then 
        s = s_ref;
    end if;
equation
    if exact then 
        s = s_ref;
        v = 0;
        a = 0;
    else 
        v = der(s);
        a = der(v);
        a = ((s_ref - s) * w_crit - af * v) * (w_crit / bf);
    end if;

    annotation (
        Documentation(info = "<html>\n<p>\nThe input signal <strong>s_ref</strong> defines the <strong>reference\nposition</strong> in [m]. Flange <strong>flange</strong> is <strong>forced</strong>\nto move relative to the support connector according to this reference motion. According to parameter\n<strong>exact</strong> (default = <strong>false</strong>), this is done in the following way:\n</p>\n<ol>\n<li><strong>exact=true</strong><br>\n    The reference position is treated <strong>exactly</strong>. This is only possible, if\n    the input signal is defined by an analytical function which can be\n    differentiated at least twice. If this prerequisite is fulfilled,\n    the Modelica translator will differentiate the input signal twice\n    in order to compute the reference acceleration of the flange.</li>\n<li><strong>exact=false</strong><br>\n    The reference position is <strong>filtered</strong> and the second derivative\n    of the filtered curve is used to compute the reference acceleration\n    of the flange. This second derivative is <strong>not</strong> computed by\n    numerical differentiation but by an appropriate realization of the\n    filter. For filtering, a second order Bessel filter is used.\n    The critical frequency (also called cut-off frequency) of the\n    filter is defined via parameter <strong>f_crit</strong> in [Hz]. This value\n    should be selected in such a way that it is higher as the essential\n    low frequencies in the signal.</li>\n</ol>\n<p>\nThe input signal can be provided from one of the signal generator\nblocks of the block library Modelica.Blocks.Sources.\n</p>\n\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Rectangle(
                    extent = {
                        {-100, 20}, 
                        {100, -20}},
                    lineColor = {0, 127, 0},
                    fillColor = {160, 215, 160},
                    fillPattern = FillPattern.Solid), 
                Text(
                    extent = {
                        {150, 60}, 
                        {-150, 100}},
                    textString = "%name",
                    lineColor = {0, 0, 255}), 
                Line(
                    points = {
                        {0, 52}, 
                        {0, 32}},
                    color = {0, 127, 0}), 
                Line(
                    points = {
                        {-29, 32}, 
                        {30, 32}},
                    color = {0, 127, 0}), 
                Line(
                    points = {
                        {-30, -32}, 
                        {30, -32}},
                    color = {0, 127, 0}), 
                Line(
                    points = {
                        {0, -32}, 
                        {0, -100}},
                    color = {0, 127, 0}), 
                Text(
                    extent = {
                        {30, -60}, 
                        {150, -30}},
                    textString = "exact="), 
                Text(
                    extent = {
                        {30, -90}, 
                        {150, -60}},
                    textString = "%exact"), 
                Text(
                    extent = {
                        {-140, -60}, 
                        {-40, -30}},
                    lineColor = {128, 128, 128},
                    horizontalAlignment = TextAlignment.Right,
                    textString = "s_ref")}));
end Position;