HallSensor

model HallSensor "Hall sensor"
    import Modelica.Constants.pi;

    extends Modelica.Mechanics.Rotational.Interfaces.PartialElementaryOneFlangeAndSupport2;

    parameter Integer p(final min = 1, start = 2) "Number of pole pairs";
    parameter Modelica.SIunits.Angle phi0 = -pi / p "Initial mechanical angle";
    Modelica.Blocks.Interfaces.RealOutput y(quantity = "Angle", final unit = "rad", displayUnit = "deg") "\"Electrical angle\""
        annotation (Placement(transformation(extent = {
            {-100, -10}, 
            {-120, 10}})));
equation
    y = rem((flange.phi - phi_support - phi0) * p, 2 * pi);
    flange.tau = 0;

    annotation (
        Icon(
            coordinateSystem(preserveAspectRatio = false),
            graphics = {
                Text(
                    extent = {
                        {-100, -60}, 
                        {100, -80}},
                    lineColor = {28, 108, 200},
                    textString = "p=%p"), 
                Ellipse(
                    extent = {
                        {-60, 60}, 
                        {60, -60}},
                    lineColor = {28, 108, 200},
                    fillColor = {215, 215, 215},
                    fillPattern = FillPattern.Solid), 
                Line(
                    points = {
                        {0, 0}, 
                        {0, 60}},
                    color = {28, 108, 200}), 
                Line(
                    points = {
                        {0, -30}, 
                        {0, 30}},
                    color = {28, 108, 200},
                    origin = {-26, 15},
                    rotation = 60), 
                Line(
                    points = {
                        {0, -30}, 
                        {0, 30}},
                    color = {28, 108, 200},
                    origin = {26, 15},
                    rotation = -60), 
                Line(
                    points = {
                        {0, -60}, 
                        {0, 0}},
                    color = {28, 108, 200}), 
                Line(
                    points = {
                        {0, -30}, 
                        {0, 30}},
                    color = {28, 108, 200},
                    origin = {26, -15},
                    rotation = 60), 
                Line(
                    points = {
                        {0, -30}, 
                        {0, 30}},
                    color = {28, 108, 200},
                    origin = {-26, -15},
                    rotation = -60), 
                Ellipse(
                    extent = {
                        {-20, 20}, 
                        {20, -20}},
                    lineColor = {28, 108, 200},
                    fillColor = {255, 255, 255},
                    fillPattern = FillPattern.Solid), 
                Line(
                    points = {
                        {-60, 0}, 
                        {-100, 0}},
                    color = {28, 108, 200}), 
                Line(
                    points = {
                        {100, 0}, 
                        {60, 0}},
                    color = {28, 108, 200}), 
                Text(
                    extent = {
                        {-100, 100}, 
                        {100, 60}},
                    lineColor = {28, 108, 200},
                    fillColor = {255, 255, 255},
                    textString = "%name")}),
        Diagram(coordinateSystem(preserveAspectRatio = false)),
        Documentation(info = "<html>\n<p>\nSimple model of a hall sensor, i.e. measuring the angle of the flange (w.r.t. the optional support), multiplying by the number of phases p to obtain the electrical angle,\nand adding a correction term i.e. the initial angle of the flange phi0.\n</p>\n<p>\nNote that phi0 has to be set that way, that in shaft position phi0 the flux linkage of phase 1 is a maximum.\n</p>\n</html>"));
end HallSensor;