Skip to content

This project demonstrates an advanced approach to PID controller tuning using meta-heuristic optimization

Notifications You must be signed in to change notification settings

Ishikawa7/MetaHeuristicPIDTuning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Meta-Heuristic PID Controller Tuning

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.

Project Overview

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.

Key Components

1. Plant Modeling

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

Uncrontrolled Root Locus Uncontrolled time response

2. Performance Requirements

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.

3. PID Controller Implementation

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

4. Cost Function Design

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.

5. Simulated Annealing Optimization

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.

Cost history

6. Visualization and Analysis

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.

Evolution

Results

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.

Dependencies

The project relies on the following Python libraries:

  • numpy
  • matplotlib
  • control
  • scipy

Usage

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:

  1. Ensure all dependencies are installed
  2. Open the notebook in Jupyter or a compatible environment
  3. Run the cells sequentially to see the optimization process in action
  4. The final animation will be saved as pid_animation.mp4

Customization

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.

Useful links

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

About

This project demonstrates an advanced approach to PID controller tuning using meta-heuristic optimization

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published