CurrentController

model CurrentController "Current controller"
    parameter Integer m = 3 "Number of phases";
    parameter Integer p "Number of pole pairs";

    extends Modelica.Blocks.Interfaces.MO(final nout = m);

    Modelica.Blocks.Interfaces.RealInput id_rms annotation (Placement(transformation(extent = {
        {-140, 40}, 
        {-100, 80}})));
    Modelica.Blocks.Interfaces.RealInput iq_rms annotation (Placement(transformation(extent = {
        {-140, -80}, 
        {-100, -40}})));
    Modelica.Blocks.Interfaces.RealInput phi(unit = "rad") annotation (Placement(transformation(
        origin = {0, -120},
        extent = {
            {20, -20}, 
            {-20, 20}},
        rotation = 270)));
    Modelica.Blocks.Math.Gain toPeak_d(k = sqrt(2)) annotation (Placement(transformation(extent = {
        {-60, 50}, 
        {-40, 70}})));
    Modelica.Blocks.Math.Gain toPeak_q(k = sqrt(2)) annotation (Placement(transformation(extent = {
        {-60, -70}, 
        {-40, -50}})));
    Modelica.Blocks.Math.Gain toGamma(k = -p) annotation (Placement(transformation(
        origin = {0, -50},
        extent = {
            {10, -10}, 
            {-10, 10}},
        rotation = 270)));
    Machines.SpacePhasors.Blocks.Rotator rotator annotation (Placement(transformation(extent = {
        {-10, -10}, 
        {10, 10}})));
    Modelica.Blocks.Sources.Constant i0(k = 0) annotation (Placement(transformation(extent = {
        {-10, 50}, 
        {10, 30}})));
    Machines.SpacePhasors.Blocks.FromSpacePhasor fromSpacePhasor(final m = m) annotation (Placement(transformation(extent = {
        {40, 10}, 
        {60, -10}})));
equation
    connect(iq_rms,toPeak_q.u) annotation (Line(
        points = {
            {-120, -60}, 
            {-62, -60}},
        color = {0, 0, 127}));
    connect(phi,toGamma.u) annotation (Line(
        points = {
            {0, -120}, 
            {0, -62}},
        color = {0, 0, 127}));
    connect(i0.y,fromSpacePhasor.zero) annotation (Line(
        points = {
            {11, 40}, 
            {20, 40}, 
            {20, 8}, 
            {38, 8}},
        color = {0, 0, 127}));
    connect(rotator.y,fromSpacePhasor.u) annotation (Line(
        points = {
            {11, 0}, 
            {24, 0}, 
            {38, 0}},
        color = {0, 0, 127}));
    connect(rotator.angle,toGamma.y) annotation (Line(
        points = {
            {0, -12}, 
            {0, -39}, 
            {0, -39}},
        color = {0, 0, 127}));
    connect(toPeak_d.u,id_rms) annotation (Line(
        points = {
            {-62, 60}, 
            {-120, 60}},
        color = {0, 0, 127}));
    connect(toPeak_d.y,rotator.u[1]) annotation (Line(
        points = {
            {-39, 60}, 
            {-30, 60}, 
            {-30, 0}, 
            {-12, 0}},
        color = {0, 0, 127}));
    connect(toPeak_q.y,rotator.u[2]) annotation (Line(
        points = {
            {-39, -60}, 
            {-30, -60}, 
            {-30, 0}, 
            {-12, 0}},
        color = {0, 0, 127}));
    connect(fromSpacePhasor.y,y) annotation (Line(
        points = {
            {61, 0}, 
            {110, 0}},
        color = {0, 0, 127}));

    annotation (
        Icon(
            coordinateSystem(
                preserveAspectRatio = false,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Text(
                    extent = {
                        {-100, 60}, 
                        {20, 40}},
                    lineColor = {0, 0, 255},
                    textString = "id_rms"), 
                Text(
                    extent = {
                        {-100, -40}, 
                        {20, -60}},
                    lineColor = {0, 0, 255},
                    textString = "iq_rms")}),
        Documentation(info = "<html>\n<p>\nSimple Current-Controller.\n</p>\n<p>\nThe desired rms values of d- and q-component of the space phasor current in rotor fixed coordinate system are given by inputs \"id_rms\" and \"iq_rms\".\nUsing the given rotor position (input \"phi\"), the correct three-phase currents (output \"y[3]\") are calculated.\nThey can be used to feed a current source which in turn feeds an induction machine.\n</p>\n</html>"));
end CurrentController;