This project demonstrates an advanced approach to PID controller tuning using meta-heuristic optimization techniques, specifically the Simulated Annealing algorithm. The implementation focuses on automatically finding optimal PID controller parameters to meet specified performance requirements for a given plant model.
Traditional PID tuning methods like Ziegler-Nichols can provide decent results but often require manual fine-tuning to achieve optimal performance. This project explores how meta-heuristic optimization can automate the tuning process to precisely meet performance specifications such as maximum percent overshoot and settling time.
The project starts with a predefined transfer function model of the plant to be controlled. The example uses a higher-order transfer function, which would be challenging to tune manually:
G(s) = 1 / (s^3 + 3s^2 + 3s + 1)
The uncontrolled system is analyzed through:
- Transfer function representation
- Root locus plots
- Step response analysis
The controller tuning aims to satisfy specific closed-loop system requirements:
- Maximum percent overshoot (Mp): The maximum amount the response overshoots the steady-state value
- Settling time (Ts): The time required for the response to stay within a 2% band of the final value
These requirements are translated into target poles in the complex plane using damping ratio (ζ) and natural frequency (ωn) calculations.
The PID controller is implemented using the control library's transfer function capabilities. The standard form used is:
C(s) = Kp + Ki/s + Kd·s
A sophisticated cost function evaluates potential PID parameters by:
- Checking system stability
- Computing pole placement accuracy compared to target poles
- Evaluating steady-state performance
- Applying appropriate penalties for undesirable characteristics
The cost function is designed to guide the optimization algorithm toward solutions that satisfy both stability and performance requirements.
The project uses SciPy's dual_annealing implementation, which:
- Searches through a continuous parameter space within defined bounds
- Gradually reduces the "temperature" parameter to balance exploration and exploitation
- Records the optimization history for analysis and visualization
The algorithm efficiently navigates the complex search space to find near-optimal PID gains that minimize the cost function.
The project includes comprehensive visualization tools:
- Dynamic animation showing how poles and step response evolve during optimization
- Cost function convergence analysis
- Performance metrics comparison between requirements and achieved results
The animation is saved as an MP4 file for further analysis and presentation purposes.
The optimization process successfully finds PID parameters that achieve:
- Controlled pole placement close to the target poles
- Step response characteristics that meet or closely approach the specified requirements
- Stable and well-damped system behavior
The final evaluation compares the actual achieved performance metrics (overshoot and settling time) with the initial requirements, demonstrating the effectiveness of the approach.
The project relies on the following Python libraries:
- numpy
- matplotlib
- control
- scipy
The entire implementation is provided in a Jupyter Notebook (MetaHeuristicPID.ipynb
), which guides you through each step of the process with detailed explanations and visualizations.
To run the notebook:
- Ensure all dependencies are installed
- Open the notebook in Jupyter or a compatible environment
- Run the cells sequentially to see the optimization process in action
- The final animation will be saved as
pid_animation.mp4
The approach can be extended to different plants by modifying:
- The plant transfer function
- Performance requirements
- PID parameter bounds
- Optimization algorithm parameters
This makes the method applicable to a wide range of control engineering problems beyond the specific example presented.
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.dual_annealing.html https://python-control.readthedocs.io/en/0.10.2/ https://matplotlib.org/stable/api/animation_api.html