BasicCutForce

model BasicCutForce "Measure cut force vector (frame_resolve must be connected)"
    import Modelica.Mechanics.MultiBody.Types.ResolveInFrameA;
    import Modelica.Mechanics.MultiBody.Frames;

    extends Internal.PartialCutForceBaseSensor;

    Modelica.Blocks.Interfaces.RealOutput force[2](each final quantity = "Force", each final unit = "N") "Cut force resolved in frame defined by resolveInFrame"
        annotation (Placement(transformation(
            origin = {-80, -110},
            extent = {
                {10, -10}, 
                {-10, 10}},
            rotation = 90)));
    parameter Boolean positiveSign = true "= true, if force with positive sign is returned (= frame_a.f), otherwise with negative sign (= frame_b.f)";
protected
    parameter Integer csign = if positiveSign then 1 else -1;
equation
    if resolveInFrame == ResolveInFrameA.world then 
        force = {frame_a.fx, frame_a.fy} * csign;
    elseif resolveInFrame == ResolveInFrameA.frame_a then 
        force = {{cos(frame_a.phi), sin(frame_a.phi)}, {-sin(frame_a.phi), cos(frame_a.phi)}} * {frame_a.fx, frame_a.fy} * csign;
    elseif resolveInFrame == ResolveInFrameA.frame_resolve then 
        force = {{cos(frame_resolve.phi), sin(frame_resolve.phi)}, {-sin(frame_resolve.phi), cos(frame_resolve.phi)}} * {frame_a.fx, frame_a.fy} * csign;
    else 
        assert(false, "Wrong value for parameter resolveInFrame");
        force = zeros(2);
    end if;

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}},
                grid = {1, 1}),
            graphics = {
                Text(
                    extent = {
                        {-190, -70}, 
                        {-74, -96}},
                    textString = "force"), 
                Line(
                    points = {
                        {-80, -100}, 
                        {-80, 0}},
                    color = {0, 0, 127})}),
        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>\nThis sensor outputs cut-force between the two connecting frames,\nwhereby the output signal <code>force&nbsp;= {frame_a.fx, frame_a.fy}</code>.\nIf parameter <strong>positiveSign</strong>&nbsp;= <strong>false</strong>, the negative\ncut-force is provided.\nThe cut-force is resolved in frame specified by the parameter\n<code>resolveInFrame</code>\n</p>\n<p>\nThe connector <code>frame_resolve</code> is always present and must,\ntherefore, be always connected from outside.\n</p>\n</html>"));
end BasicCutForce;