A Python library for power electronics and electrical system simulation.
- Electrical Models: Battery cells, ideal sources, resistors, RC loads
- DC-DC Converters: Buck, Boost, and Buck-Boost converters
- Controllers: P, PI, PD, and PID controllers
- Simulation Tools: Time-domain simulation with variable tracking
- Data I/O: CSV and TXT input/output for simulation data
- Visualization: Built-in plotting and system diagram generation
cd powerlab
pip install -e .import powerlab as pl
import matplotlib.pyplot as plt
# Define constants
V_REF = pl.Const(3.0)
V_IN = pl.Const(5.0)
R = pl.Const(10.0)
# Create variables
v_in, i_in, v_out, i_out = pl.Outputs(V_IN, 2.0, 0.0, 0.0)
d = pl.Var(0.5)
# Build the circuit
pl.IdealSource(v=v_in, i=i_in)
pl.BuckConverter(d=d, v_in=v_in, i_in=i_in, v_out=v_out, i_out=i_out)
pl.Resistor(r=R, v=v_out, i=i_out)
# Add a controller
pl.Controller(type=pl.PID(kp=0.1, ki=0.05, kd=0.01), ref=V_REF, fb=v_out, out=d)
# Generate system diagram
pl.diagram()
plt.show()
# Run simulation
import numpy as np
pl.run(np.linspace(0, 50, 201))
# Plot results
v_out.plot()
i_out.plot()
plt.legend(['v_out', 'i_out'])
plt.show()Adding models is simple. Just create a child class of powerlab.utils.model.Model and implement the required methods.
Here are some of the built-in models:
- RintCell: Battery cell with internal resistance
- IdealSource: Ideal voltage/current source
- Resistor: Simple resistor
- RCLoad: RC load model
- BuckConverter: Step-down converter
- BoostConverter: Step-up converter
- BuckBoostConverter: Step-up/down converter
Just call the main Controller class with the desired type (P, PI, PD, PID) and parameters.
- Python >= 3.8
- numpy >= 1.20.0
- matplotlib >= 3.3.0
- graphviz>=0.16
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open issues or submit pull requests for bug fixes and new features.