1
0
Fork
You've already forked EMotorSym
0
Electrical synchronous motor simulation library based on py control
  • Python 100%
2026年07月10日 16:46:31 +02:00
example update example to new api 2026年07月10日 15:38:41 +02:00
.gitignore add python packaging files 2026年06月30日 12:40:26 +02:00
__init__.py add python packaging files 2026年06月30日 12:40:26 +02:00
LICENSE add GPLV3 or higher LICENSE 2026年06月11日 16:25:40 +02:00
motor.py Fix naming 2026年07月10日 16:46:31 +02:00
pyproject.toml bump package version to 0.4.0 2026年07月10日 15:39:20 +02:00
readme.md update readme 2026年07月07日 17:33:24 +02:00
requirements.txt first commit 2026年06月11日 16:22:20 +02:00

Python Motors simulation library

Python Motors Simulation library is an electrical motor simulation library. It's base on python control and allow you to simulate synchronous motor behaviour in order to let you safely experiment your motor control algorithm.

You will find using examples in ./example folder.

Features

This library manage AC Synchronous Motor which consist of three type of motors:

  • Synchronous Reluctance Motor (SynRM)
  • Permanent Magnets Synchronous Motor (PMSM)
  • Permanent Magnets assisted Synchronous Motor (PMa_SynRMotor)

Motors model are based on python control NonlinearIOSystem class. I ovewrite the NonlinearIOSystem class initialisation to predefine update and output function along with inputs, output and state representation variables.

How to use it

First you need to add this package as dependency

echo "git+https://codeberg.org/KumaTec/EMotorSym.git" >> requirements.txt

Now you can import it to your python file import motor

API

Motor model creation

Simple example of motor creation:

from motor import SynMotor
pmsm = SynMotor(R=6.2, Ld=0.025, Lq=0.04, npp=3, Jm=0.0036, Bm=0.0011, Ke=0.305)
print(pmsm)

Difference between the three types of motors are done by parameters. For example a SynRM motor must have a Ke=0.

The SynMotor parameters are:

  • R: stator impedance value (Ohm)
  • Ld: direct inductance (H)
  • Lq: quadrature inductance (H)
  • npp: number of pairs of poles
  • Jm: Inertia (N.m/s2)
  • Bm: friction constant (N.m/s)
  • Ke: Permanent magnet flux (Wb) or Electrical constant (V.s/rad)
  • load_torque: user callback to compute motor torque load (None by default)

This motor object wait Vd and Vq as input paramters. The output vector had 5 parameters [Id, Iq, ohmega, theta, Tem, load]:

  • Id and Iq: Direct and quadratic current in Ampere
  • ohmega: rotor mecanical speed in RPM
  • theta: rotor mecanical position in radians
  • Tem: Electromagnetic Torque
  • load: external torque apply on the rotor

After that you can use it like a normal NonlinearIOSystem object.


** ABC coordinate system **

I had an helper function to get the motor in ABC coordinate system: abc_syn_motor. This function take a SynMotor object as parameter and return an NonLinearIOSystem.

This system had as input ['Va', 'Vb', 'Vc'] and as output [Ia, Ib, Ic, Id, Iq, omheage, theta, Tem, load]

Load callback

You can pass a callback function which will be call to get the rotor external torque value. The callback function signature must be:

def load_callback(time: float, speed: float):
 return 0.0

The function take two parameters:

  • time: that let you know actual simulation time
  • speed: actual rotor mechanical speed

and expect you to return a float value: the torque in N.m.

example:

def load_callback_time_offset(t,s):
 """
 Add a constant load after 3 sec
 """
 load = 0.0
 if t >= 3.0:
 load = 2.4 #N.m
 return load

Motor model simulation

To simulate motor behaviour with control library you must provide model input:

import control as ct
import numpy as np
from motor import SynMotor
def load(t, w):
 """
 No load until 2s of simulation and after constant load of 2 N.m
 """
 load = 0
 if t > 2.0:
 load = 2
 return load
synrm = SynMotor(6.2, 0.34, 0.105, 2, 0.008, 0.0001, load=load)
t = np.linspace(0, 5, 5000)
Vd = ...
Vq = ...
resp = ct.input_output_response(synrm, t, [Vd, Vq])

Or using it as normal control NonlinearIOSystem.