Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

MatanPazi/motor_sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Motor Simulator

This repository contains a Python-based motor simulator designed to aid in control algorithm development. The simulation allows fine-grained control over motor and application settings and supports real-time switching behavior and dead-time effects.

Features

  • Simulates motor electrical and mechanical dynamics for Synchronous motors (Asynchronous TBD)
  • Takes into account mutual and self inductances, as well as inductance saturation and inductance time derivatives
  • Accounts for dead-time and switching behavior
  • Supports back-emf harmonics
  • Allows the simulation of short-circuiting all phases
  • Supports MTPA (Maximum torque per ampere) LUT (Lookup table) generation based on motor parameters
  • Supports loading external MTPA LUTs
  • Supports AFC (Adaptive feed forward cancellation) control for harmonic attenuation
  • Supports decoupling
  • Features a simple battery model
  • Supports an input filter (RLC network) from the battery
  • Supports unbalanced phases

How It Works

The simulator integrates electrical and mechanical motor equations to simulate motor behavior. A current vector is commanded, and following a current loop, the FOC voltages Vd and Vq are calculated. These voltages are transformed to transistor states (Taking dead-time into account). The phase currents are found by solving the voltage equations. And the user can plot anything they wish:

  • Phase currents
  • Phase voltages
  • Torque
  • Speed
  • Inductances (Self, mutual, dq)
  • etc.

Usage

Modify parameters by directly adjusting the config class initialization in the script:

class Config:
    def __init__(self):
        '''
        Initializes all script parameters:

        Args:
        ...

Parameter units and explanations are in the script.

Running the simulation, example:

# Instantiate objects
config = Config()
motor = Motor(config)
sim = Simulation(config)
app = Application(config)
control = MotorControl(config)
lut = LUT(config)

# Uncomment to show closed loop bode plots of q and d axes:
# estimate_BW(control, app)

# If direct torque command is desired, a LUT is required. Generate or upload.
if (app.torque_command_flag):
    if (app.generate_lut):
        # Calculates this motor's MTPA LUT
        lut.mtpa_gen(motor, app)
    else:
        # Upload LUTs from text file
        iq_table, id_table = extract_iq_id_tables()
        lut.mtpa_lut = np.stack((iq_table, -id_table), axis=-1) / 10


# Run the simulation
simulate_motor(motor, sim, app, control, lut)

# Plot results
...

WhatsApp Image 2024-10-15 at 09 22 12

WhatsApp Image 2024-10-15 at 09 22 12 (1)

Figure_1

Dependencies

This project requires the following Python modules:

License

This project is licensed under the MIT License - see the LICENSE file for details.

Miscellaneous

About

Python-based motor & controller simulator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages