
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "drive_examples/gradnet/plot_6kw_pmsyrm_gn_fvc_meas.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_gradnet_plot_6kw_pmsyrm_gn_fvc_meas.py>`
        to download the full example code.

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

.. _sphx_glr_drive_examples_gradnet_plot_6kw_pmsyrm_gn_fvc_meas.py:


5.6-kW PM-SyRM, GradNet from measured data, FVC
===============================================

This example simulates flux-vector control (FVC) of a 5.6-kW PM synchronous reluctance
machine (Baldor ECS101M0H7EF4) drive. GradNet models trained on measured data without
spatial harmonics are used for both the machine model and the control system.

.. GENERATED FROM PYTHON SOURCE LINES 12-20

.. code-block:: Python

    from pathlib import Path

    import numpy as np

    import motulator.drive.control.sm as control
    import motulator.drive.gradnet as gn
    from motulator.drive import model, utils








.. GENERATED FROM PYTHON SOURCE LINES 21-22

Compute base values based on the nominal values (just for figures).

.. GENERATED FROM PYTHON SOURCE LINES 22-26

.. code-block:: Python


    nom = utils.NominalValues(U=460, I=8.8, f=60, P=5.6e3, tau=29.7)
    base = utils.BaseValues.from_nominal(nom, n_p=2)








.. GENERATED FROM PYTHON SOURCE LINES 27-28

Determine the path of the current script.

.. GENERATED FROM PYTHON SOURCE LINES 28-31

.. code-block:: Python


    p = Path(__file__).resolve().parent if "__file__" in globals() else Path.cwd()








.. GENERATED FROM PYTHON SOURCE LINES 32-34

Configure the system model using the GradNet current map, without spatial harmonics,
trained on the measured dataset.

.. GENERATED FROM PYTHON SOURCE LINES 34-45

.. code-block:: Python


    path = "trained_models/baldor_meas_curr_map_squareplus_d12_sub10.pth"
    gradnet = gn.load_gradnet(p / path, activation=gn.Squareplus)
    current_map = gn.CurrentMap(gradnet)
    par = model.SaturatedSynchronousMachinePars(n_p=2, R_s=0.63, i_s_dq_fcn=current_map)

    machine = model.SynchronousMachine(par)
    mechanics = model.MechanicalSystem(J=0.05)
    converter = model.VoltageSourceConverter(u_dc=540)
    mdl = model.Drive(machine, mechanics, converter)








.. GENERATED FROM PYTHON SOURCE LINES 46-48

Configure the control system using the GradNet flux map, without spatial harmonics,
trained on the measured dataset.

.. GENERATED FROM PYTHON SOURCE LINES 48-64

.. code-block:: Python


    # Parametrize the estimated machine model
    path = "trained_models/baldor_meas_flux_map_pnorm_d6_sub10.pth"
    est_flux_map = gn.FluxMap(gn.load_gradnet(p / path, activation=gn.PNormGradient))
    est_par = control.SaturatedSynchronousMachinePars(
        n_p=2, R_s=0.63, psi_s_dq_fcn=est_flux_map
    )

    # Configure the control system
    cfg = control.FluxVectorControllerCfg(
        i_s_max=2 * base.i, alpha_i=0, alpha_o=2 * np.pi * 8, J=0.05, sensorless=False
    )
    vector_ctrl = control.FluxVectorController(est_par, cfg)
    speed_ctrl = control.SpeedController(J=0.05, alpha_s=2 * np.pi * 4)
    ctrl = control.VectorControlSystem(vector_ctrl, speed_ctrl)








.. GENERATED FROM PYTHON SOURCE LINES 65-66

Visualize the control loci.

.. GENERATED FROM PYTHON SOURCE LINES 66-74

.. code-block:: Python


    i_s_vals = [1, 2, 3]  # Current values for the plots
    mc = utils.MachineCharacteristics(est_par)
    mc.plot_flux_vs_torque(i_s_vals, base)
    mc.plot_current_vs_torque(i_s_vals, base)
    mc.plot_current_loci(i_s_vals, base)
    mc.plot_flux_loci(i_s_vals, base)




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


    *

      .. image-sg:: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_001.png
         :alt: plot 6kw pmsyrm gn fvc meas
         :srcset: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_001.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_002.png
         :alt: plot 6kw pmsyrm gn fvc meas
         :srcset: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_002.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_003.png
         :alt: plot 6kw pmsyrm gn fvc meas
         :srcset: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_003.png
         :class: sphx-glr-multi-img

    *

      .. image-sg:: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_004.png
         :alt: plot 6kw pmsyrm gn fvc meas
         :srcset: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_004.png
         :class: sphx-glr-multi-img





.. GENERATED FROM PYTHON SOURCE LINES 75-76

Set the speed reference and the external load torque.

.. GENERATED FROM PYTHON SOURCE LINES 76-80

.. code-block:: Python


    ctrl.set_speed_ref(lambda t: (t > 0.25) * 2 * base.w_M)
    mdl.mechanics.set_external_load_torque(lambda t: (t > 1.25) * 0.5 * base.tau)








.. GENERATED FROM PYTHON SOURCE LINES 81-82

Create the simulation object, simulate, and plot the results in per-unit values.

.. GENERATED FROM PYTHON SOURCE LINES 82-86

.. code-block:: Python


    sim = model.Simulation(mdl, ctrl)
    res = sim.simulate(t_stop=1.75)
    utils.plot(res, base)



.. image-sg:: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_005.png
   :alt: plot 6kw pmsyrm gn fvc meas
   :srcset: /drive_examples/gradnet/images/sphx_glr_plot_6kw_pmsyrm_gn_fvc_meas_005.png
   :class: sphx-glr-single-img






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

   **Total running time of the script:** (1 minutes 36.317 seconds)


.. _sphx_glr_download_drive_examples_gradnet_plot_6kw_pmsyrm_gn_fvc_meas.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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