Genetic algorithm that optimizes PID values to minimize ISE. It can use either Matlab/Simulink or built-in Python model for simulating plant.
- Python 3.6+
- NumPy
- SciPy
- Control
- Matlotlib
- MATLAB Engine for Python
- TKInter
- Install Python 3.6+
- Clone this repo
- Install dependencies:
pip install numpy scipy matplotlib control
- Go into the repo directory and run
main.py
cd GA_PID_Tuner && python main.py
Described here: https://www.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
Opis większości plików i katalogów w projekcie:
genetic
- Genetic Algorithm reletated filesalgorithms
- Crossover, mutation and selection implementations
matlab
- Matlab and simulink filessimulate.m
- [function] Simulates model with Simulingsimulate2.m
- [function] Sumulates model WITHOUT Simulinkcircuit.slx
- Simulink model (Note: watch out the Simulation Parameters)run.m
- for testing purposes
sim
- model simulation and fitness calculationAbstractSimModel.py
- base classPythonSimulatedModel.py
- simulation in Python using Control libMatlabModel.py
- starts Matlab and runssimulate2.m
MatlabSimulinkModel.py
- Starts Matlab and runssimulate.m
+ Simulink
tests
- unit testsmain.py
- run this file to startconfig.py
- default configapplication.py
- UI Interface
By default, a Python built-in model is used for calculating fitness, but there is also Matlab support. To switch model to matlab, do the following:
- Make sure that you have Matlab Engine for Python installed
- Check the
matlab
directory to see how scripts are made - Open
application.py
- Add the beginning, add the proper import:
from sim.MatlabModel import MatlabModel
# Or, if you want to use Simulink:
from sim.MatlabSimulinkModel import MatlabSimulinkModel
- In line 289, change
PythonSimulatedModel(cfg)
to eitherMatlabModel(cfg)
orMatlabSimulinkModel(cfg)
self.simulation = Simulation(cfg,
PythonSimulatedModel(cfg),
GeneticAlgorithmImpl(cfg))