Position

model Position "Forced movement of a flange according to a reference angle signal"
    extends Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;

    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.Angle phi(stateSelect = if exact then StateSelect.default else StateSelect.prefer) "Rotation angle of flange with respect to support";
    SI.AngularVelocity w(start = 0, stateSelect = if exact then StateSelect.default else StateSelect.prefer) "If exact=false, Angular velocity of flange with respect to support else dummy";
    SI.AngularAcceleration a(start = 0) "If exact=false, Angular acceleration of flange with respect to support else dummy";
    Modelica.Blocks.Interfaces.RealInput phi_ref(final quantity = "Angle", final unit = "rad", displayUnit = "deg") "Reference angle of flange with respect to support 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 
        phi = phi_ref;
    end if;
equation
    if exact then 
        phi = phi_ref;
        w = 0;
        a = 0;
    else 
        w = der(phi);
        a = der(w);
        a = ((phi_ref - phi) * w_crit - af * w) * (w_crit / bf);
    end if;
    phi = flange.phi - phi_support;

    annotation (
        Documentation(info = "<html>\n<p>\nThe input signal <strong>phi_ref</strong> defines the <strong>reference\nangle</strong> in [rad]. Flange <strong>flange</strong> is <strong>forced</strong>\nto move according to this reference motion relative to flange support. 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 angle 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 angle 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</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Rectangle(
                    lineColor = {64, 64, 64},
                    fillColor = {192, 192, 192},
                    fillPattern = FillPattern.HorizontalCylinder,
                    extent = {
                        {-100, -20}, 
                        {100, 20}}), 
                Line(points = {
                    {-30, -32}, 
                    {30, -32}}), 
                Line(points = {
                    {0, 52}, 
                    {0, 32}}), 
                Line(points = {
                    {-29, 32}, 
                    {30, 32}}), 
                Line(points = {
                    {0, -32}, 
                    {0, -100}}), 
                Text(
                    extent = {
                        {-150, -60}, 
                        {-40, -30}},
                    lineColor = {128, 128, 128},
                    textString = "phi_ref",
                    horizontalAlignment = TextAlignment.Right), 
                Text(
                    lineColor = {0, 0, 255},
                    extent = {
                        {-150, 60}, 
                        {150, 100}},
                    textString = "%name"), 
                Text(
                    extent = {
                        {30, -60}, 
                        {150, -30}},
                    textString = "exact="), 
                Text(
                    extent = {
                        {30, -90}, 
                        {150, -60}},
                    textString = "%exact")}));
end Position;