RelativeAcceleration

model RelativeAcceleration "Measure relative acceleration between the origins of two frame connectors"
    extends Internal.PartialRelativeSensor;

    Modelica.Blocks.Interfaces.RealOutput a_rel[3](final quantity = {"Acceleration", "Acceleration", "AngularAcceleration"}, final unit = {"m/s2", "m/s2", "rad/s2"}) "Vector of relative measurements from frame_a to frame_b on acceleration level, resolved in frame defined by resolveInFrame"
        annotation (Placement(transformation(
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = -90,
            origin = {0, -110})));
    Interfaces.Frame_resolve frame_resolve if resolveInFrame == Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB.frame_resolve "Coordinate system in which v_rel is optionally resolved"
        annotation (Placement(transformation(extent = {
            {84, 64}, 
            {116, 96}})));
    parameter Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB resolveInFrame = Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB.frame_a "Frame in which output vector v_rel shall be resolved (1: world, 2: frame_a, 3: frame_b, 4: frame_resolve)";
protected
    RelativePosition relativePosition(resolveInFrame = Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB.frame_a) annotation (Placement(transformation(extent = {
        {-10, 30}, 
        {10, 50}})));
    Interfaces.ZeroPosition zeroPosition if not resolveInFrame == Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB.frame_resolve annotation (Placement(transformation(extent = {
        {40, -30}, 
        {60, -10}})));
    Modelica.Blocks.Continuous.Der der_r_rel[3] annotation (Placement(transformation(
        extent = {
            {-10, -10}, 
            {10, 10}},
        rotation = 270,
        origin = {0, 0})));
    TransformRelativeVector transformRelativeVector(frame_r_in = Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB.frame_a, frame_r_out = resolveInFrame) annotation (Placement(transformation(extent = {
        {-10, -50}, 
        {10, -30}})));
    Modelica.Blocks.Continuous.Der der_r_rel1[3] annotation (Placement(transformation(
        extent = {
            {-10, -10}, 
            {10, 10}},
        rotation = 270,
        origin = {0, -70})));
equation
    connect(der_r_rel.y,transformRelativeVector.r_in) annotation (Line(
        points = {
            {-2.22045e-15, -11}, 
            {-2.22045e-15, -14}, 
            {0, -14}, 
            {0, -28}},
        color = {0, 0, 127}));
    connect(der_r_rel1.y,a_rel) annotation (Line(
        points = {
            {-2.22045e-15, -81}, 
            {-2.22045e-15, -110}, 
            {0, -110}},
        color = {0, 0, 127}));
    connect(relativePosition.frame_a,frame_a) annotation (Line(
        points = {
            {-10, 40}, 
            {-70, 40}, 
            {-70, 0}, 
            {-100, 0}},
        color = {95, 95, 95},
        thickness = 0.5));
    connect(relativePosition.frame_b,frame_b) annotation (Line(
        points = {
            {10, 40}, 
            {70, 40}, 
            {70, 0}, 
            {100, 0}},
        color = {95, 95, 95},
        thickness = 0.5));
    connect(relativePosition.r_rel,der_r_rel.u) annotation (Line(
        points = {
            {0, 29}, 
            {0, 12}, 
            {2.22045e-15, 12}},
        color = {0, 0, 127}));
    connect(zeroPosition.frame_resolve,transformRelativeVector.frame_resolve) annotation (Line(
        points = {
            {40, -20}, 
            {30, -20}, 
            {30, -31.9}, 
            {10, -31.9}},
        color = {95, 95, 95},
        pattern = LinePattern.Dot));
    connect(transformRelativeVector.frame_a,frame_a) annotation (Line(
        points = {
            {-10, -40}, 
            {-70, -40}, 
            {-70, 0}, 
            {-100, 0}},
        color = {95, 95, 95},
        thickness = 0.5));
    connect(transformRelativeVector.frame_b,frame_b) annotation (Line(
        points = {
            {10, -40}, 
            {70, -40}, 
            {70, 0}, 
            {100, 0}},
        color = {95, 95, 95},
        thickness = 0.5));
    connect(transformRelativeVector.r_out,der_r_rel1.u) annotation (Line(
        points = {
            {0, -51}, 
            {0, -58}, 
            {2.22045e-15, -58}},
        color = {0, 0, 127}));
    connect(transformRelativeVector.frame_resolve,frame_resolve) annotation (Line(
        points = {
            {10, -31.9}, 
            {30, -31.9}, 
            {30, 80}, 
            {100, 80}},
        color = {95, 95, 95},
        pattern = LinePattern.Dot));

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {0, -70}, 
                        {0, -100}},
                    color = {0, 0, 127}), 
                Text(
                    extent = {
                        {18, -80}, 
                        {102, -110}},
                    textString = "a_rel",
                    textColor = {0, 0, 0}), 
                Text(
                    extent = {
                        {-150, 140}, 
                        {150, 100}},
                    textString = "%name",
                    textColor = {0, 0, 255})}),
        Documentation(
            revisions = "<html>\n<p>\n<img src=\"modelica://PlanarMechanics/Resources/Images/dlr_logo.png\" alt=\"DLR logo\">\n<strong>Developed 2010 at the DLR Institute of System Dynamics and Control</strong>\n</p>\n</html>",
            info = "<html>\n<p>\nThe relative acceleration vector between the origins of <code>frame_a</code>\nand of <code>frame_b</code> are determined and provided at the output signal\nconnector <code>a_rel</code>.\n</p>\n<p>\nVia parameter <code>resolveInFrame</code> it is defined, in which frame\nthe acceleration vector is resolved.\n</p>\n\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n  <caption align=\"bottom\">Options of parameter <strong>resolveInFrame</strong></caption>\n  <tr>\n    <th>resolveInFrame = &hellip;</th>\n    <th>Output vector resolved in</th>\n  </tr>\n  <tr>\n    <td valign=\"top\">Types.ResolveInFrameAB.world</td>\n    <td valign=\"top\">world frame</td>\n  </tr>\n  <tr>\n    <td valign=\"top\">Types.ResolveInFrameAB.frame_a</td>\n    <td valign=\"top\">frame_a</td>\n  </tr>\n  <tr>\n    <td valign=\"top\">Types.ResolveInFrameAB.frame_b</td>\n    <td valign=\"top\">frame_b</td>\n  </tr>\n  <tr>\n    <td valign=\"top\">Types.ResolveInFrameAB.frame_resolve</td>\n    <td valign=\"top\">frame_resolve (must be connected)</td>\n  </tr>\n</table>\n\n<p>\nIf <code>resolveInFrame&nbsp;= Types.ResolveInFrameAB.frame_resolve</code>,\nthe conditional connector <code>frame_resolve</code> is enabled\nand <code>a_rel</code> is resolved in the frame, to which\n<code>frame_resolve</code> is connected.\nNote, if this connector is enabled, it must be connected.\n</p>\n<p>\nExample: If <code>resolveInFrame = Types.ResolveInFrameAB.frame_resolve</code>,\nthe output vector is computed as:\n</p>\n<div>\n<img src=\"modelica://PlanarMechanics/Resources/Images/equations/equation-LZbFgA50.png\" alt=\"r_rel = transpose([cos(frame_resolve.phi), -sin(frame_resolve.phi), 0; sin(frame_resolve.phi),cos(frame_resolve.phi), 0;0,0,1]) * [frame_b.x - frame_a.x;frame_b.y - frame_a.y;frame_b.phi - frame_a.phi]\"/>\n</div>\n<div>\n<img src=\"modelica://PlanarMechanics/Resources/Images/equations/equation-b53N2SsO.png\" alt=\"v_rela = der(r_rel)\"/>\n</div>\n<div>\n<img src=\"modelica://PlanarMechanics/Resources/Images/equations/equation-PGBmAMb7.png\" alt=\"v_rel = transpose([cos(frame_resolve.phi), -sin(frame_resolve.phi),0;sin(frame_resolve.phi),cos(frame_resolve.phi),0;0,0,1]) * [cos(frame_a.phi),-sin(frame_a.phi), 0;sin(frame_a.phi), cos(frame_a.phi),0;0,0,1] * r_rela\"/>\n</div>\n<div>\n<img src=\"modelica://PlanarMechanics/Resources/Images/equations/equation-NK9IGjAY.png\" alt=\"a_rel = der(v_rel)\"/>\n</div>\n</html>"));
end RelativeAcceleration;