BasicRelativeAngularVelocity

model BasicRelativeAngularVelocity "Basic sensor to measure relative angular velocity"
    import Modelica.Mechanics.MultiBody.Frames;
    import Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB;

    extends Modelica.Mechanics.MultiBody.Sensors.Internal.PartialRelativeBaseSensor;

    Modelica.Blocks.Interfaces.RealOutput w_rel[3](each final quantity = "AngularVelocity", each final unit = "rad/s") "Relative angular velocity vector"
        annotation (Placement(transformation(
            origin = {0, -110},
            extent = {
                {-10, -10}, 
                {10, 10}},
            rotation = 270)));
    parameter Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB resolveInFrame = Modelica.Mechanics.MultiBody.Types.ResolveInFrameAB.frame_a "Frame in which output vector w_rel is resolved (world, frame_a, frame_b, or frame_resolve)";
protected
    Modelica.Mechanics.MultiBody.Frames.Orientation R_rel "Relative orientation object from frame_a to frame_b";
equation
    if resolveInFrame == ResolveInFrameAB.frame_a then 
        w_rel = Frames.angularVelocity1(R_rel);
    elseif resolveInFrame == ResolveInFrameAB.frame_b then 
        w_rel = Frames.angularVelocity2(R_rel);
    elseif resolveInFrame == ResolveInFrameAB.world then 
        w_rel = Frames.resolve1(frame_a.R, Frames.angularVelocity1(R_rel));
    elseif resolveInFrame == ResolveInFrameAB.frame_resolve then 
        w_rel = Frames.resolveRelative(Frames.angularVelocity1(R_rel), frame_a.R, frame_resolve.R);
    else 
        assert(false, "Wrong value for parameter resolveInFrame");
        w_rel = zeros(3);
    end if;
    R_rel = Frames.relativeRotation(frame_a.R, frame_b.R);

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Text(
                    extent = {
                        {12, -76}, 
                        {96, -106}},
                    textString = "w_rel"), 
                Text(
                    extent = {
                        {-132, 90}, 
                        {129, 138}},
                    textString = "%name",
                    lineColor = {0, 0, 255})}),
        Documentation(info = "<html>\n<p>\nThis basic sensor is aimed to be used within advanced sensors where\nthe relative angular velocity between frame_a and frame_b should be determined.\nThis vector is provided at the output signal connector&nbsp;<strong>w_rel</strong>.\n</p>\n\n<p>\nVia parameter <strong>resolveInFrame</strong> it is defined, in which frame\nthe angular velocity is resolved:\n</p>\n\n<table border=1 cellspacing=0 cellpadding=2>\n<tr><th><strong>resolveInFrame =<br>Types.ResolveInFrameAB.</strong></th><th><strong>Meaning</strong></th></tr>\n<tr><td>world</td>\n    <td>Resolve vector in world frame</td></tr>\n\n<tr><td>frame_a</td>\n    <td>Resolve vector in frame_a</td></tr>\n\n<tr><td>frame_b</td>\n    <td>Resolve vector in frame_b</td></tr>\n\n<tr><td>frame_resolve</td>\n    <td>Resolve vector in frame_resolve</td></tr>\n</table>\n\n<p>\nIn this basic sensor model, <strong>the connector frame_resolve\nis always enabled and must be connected</strong>.\nIf resolveInFrame = Types.ResolveInFrameAB.frame_resolve, the vector&nbsp;w_rel is\nresolved in the frame to which frame_resolve is connected.\n</p>\n\n<h4>Example</h4>\n<p>\nIf resolveInFrame = Types.ResolveInFrameAB.frame_a, the output vector is\ncomputed as:\n</p>\n\n<blockquote><pre>\n// Relative orientation object from frame_a to frame_b\nR_rel = MultiBody.Frames.relativeRotation(frame_a.R, frame_b.R);\n\n// Angular velocity resolved in frame_a\nw_rel = MultiBody.Frames.angularVelocity1(R_rel);\n</pre></blockquote>\n</html>"));
end BasicRelativeAngularVelocity;