
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "drive_examples/grid_connection/plot_2kw_ipmsm_diode_cvc.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_drive_examples_grid_connection_plot_2kw_ipmsm_diode_cvc.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_drive_examples_grid_connection_plot_2kw_ipmsm_diode_cvc.py:


2.2-kW IPMSM, diode bridge, CVC
===============================

This example simulates sensorless current-vector control (CVC) of a 2.2-kW interior
permanent-magnet synchronous machine (IPMSM) drive, fed from a six-pulse diode bridge.
The diode bridge is supplied from a stiff grid through an AC choke.

.. GENERATED FROM PYTHON SOURCE LINES 12-21

.. code-block:: Python

    from math import pi, sqrt

    import motulator.drive.control.sm as control
    from motulator.common.model import CompositeModel, DCBus, Simulation, ThreePhaseSource
    from motulator.drive import model as drive_model
    from motulator.drive import utils as drive_utils
    from motulator.grid import model as grid_model
    from motulator.grid import utils as grid_utils








.. GENERATED FROM PYTHON SOURCE LINES 22-23

Compute base values based on the nominal values.

.. GENERATED FROM PYTHON SOURCE LINES 23-27

.. code-block:: Python


    nom = drive_utils.NominalValues(U=370, I=4.3, f=75, P=2.2e3, tau=14)
    base = drive_utils.BaseValues.from_nominal(nom, n_p=3)








.. GENERATED FROM PYTHON SOURCE LINES 28-30

Configure the system model. The diode bridge and the inverter share the DC bus, and
their models are combined into a composite model.

.. GENERATED FROM PYTHON SOURCE LINES 30-51

.. code-block:: Python


    dc_bus = DCBus(C_dc=235e-6, u_dc=sqrt(2) * 400)
    grid_sys = grid_model.GridConverterSystem(
        grid_model.DiodeBridge(),
        grid_model.LFilter(L_f=0.5e-3),
        ThreePhaseSource(w_g=2 * pi * 50, e_g=sqrt(2 / 3) * 400),
        dc_bus=dc_bus,
    )

    par = drive_model.SynchronousMachinePars(
        n_p=3, R_s=3.6, L_d=0.036, L_q=0.051, psi_f=0.545
    )
    machine = drive_model.SynchronousMachine(par)
    mechanics = drive_model.MechanicalSystem(J=0.015)
    converter = drive_model.VoltageSourceConverter(
        modulator=drive_model.CarrierComparison()
    )
    drive_sys = drive_model.Drive(machine, mechanics, converter, dc_bus=dc_bus)

    mdl = CompositeModel({"grid": grid_sys, "drive": drive_sys})








.. GENERATED FROM PYTHON SOURCE LINES 52-53

Configure the control system.

.. GENERATED FROM PYTHON SOURCE LINES 53-62

.. code-block:: Python


    est_par = par  # Assume accurate model parameter estimates
    cfg = control.CurrentVectorControllerCfg(
        i_s_max=1.5 * base.i, alpha_o=2 * pi * 100, T_s=250e-6
    )
    vector_ctrl = control.CurrentVectorController(est_par, cfg)
    speed_ctrl = control.SpeedController(J=0.015, alpha_s=2 * pi * 4)
    ctrl = control.VectorControlSystem(vector_ctrl, speed_ctrl)








.. GENERATED FROM PYTHON SOURCE LINES 63-64

Set the speed reference and the external load torque.

.. GENERATED FROM PYTHON SOURCE LINES 64-68

.. code-block:: Python


    ctrl.set_speed_ref(lambda t: (t > 0.2) * base.w_M)
    mechanics.set_external_load_torque(lambda t: (t > 0.6) * nom.tau)








.. GENERATED FROM PYTHON SOURCE LINES 69-71

Create the simulation object, with the control system of the drive by the model
name, and simulate. Plot the drive results in per-unit values.

.. GENERATED FROM PYTHON SOURCE LINES 71-80

.. code-block:: Python


    sim = Simulation(mdl, {"drive": ctrl})
    res = sim.simulate(t_stop=1)
    res_drive = drive_model.SimulationResults(res.mdl.drive, res.ctrl.drive)
    res_grid = grid_model.SimulationResults(res.mdl.grid, res.ctrl.grid)
    # sphinx_gallery_thumbnail_number = 3
    drive_utils.plot(res_drive, base)
    drive_utils.plot_stator_waveforms(res_drive, base, t_lims=(0.8, 0.825))




.. rst-class:: sphx-glr-horizontal


    *

      .. image-sg:: /drive_examples/grid_connection/images/sphx_glr_plot_2kw_ipmsm_diode_cvc_001.png
         :alt: plot 2kw ipmsm diode cvc
         :srcset: /drive_examples/grid_connection/images/sphx_glr_plot_2kw_ipmsm_diode_cvc_001.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /drive_examples/grid_connection/images/sphx_glr_plot_2kw_ipmsm_diode_cvc_002.png
         :alt: plot 2kw ipmsm diode cvc
         :srcset: /drive_examples/grid_connection/images/sphx_glr_plot_2kw_ipmsm_diode_cvc_002.png
         :class: sphx-glr-multi-img





.. GENERATED FROM PYTHON SOURCE LINES 81-83

Plot the grid voltages and currents. The diode bridge conducts in pulses, as the
DC-bus voltage is close to the peak of the line-to-line grid voltage.

.. GENERATED FROM PYTHON SOURCE LINES 83-85

.. code-block:: Python


    grid_utils.plot_grid_waveforms(res_grid, t_lims=(0.8, 0.825), plot_pcc_voltage=False)



.. image-sg:: /drive_examples/grid_connection/images/sphx_glr_plot_2kw_ipmsm_diode_cvc_003.png
   :alt: plot 2kw ipmsm diode cvc
   :srcset: /drive_examples/grid_connection/images/sphx_glr_plot_2kw_ipmsm_diode_cvc_003.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 32.701 seconds)


.. _sphx_glr_download_drive_examples_grid_connection_plot_2kw_ipmsm_diode_cvc.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_2kw_ipmsm_diode_cvc.ipynb <plot_2kw_ipmsm_diode_cvc.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_2kw_ipmsm_diode_cvc.py <plot_2kw_ipmsm_diode_cvc.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_2kw_ipmsm_diode_cvc.zip <plot_2kw_ipmsm_diode_cvc.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
