This repository contains a unified MATLAB and Python implementation of a reusable, feature-complete PID controller, together with a collection of simulation examples that reproduce common industrial and academic control scenarios.
The project is intended as a teaching, experimentation, and reference codebase for practical PID implementation, covering both fundamental and advanced control strategies.
.
├── matlab/ % MATLAB implementation and examples
├── python/ % Python implementation and examples
└── README.md % This file
Each language folder is self-contained and includes:
- A reusable PID controller implementation
- Simulation scripts for different control scenarios
- Shared utilities for process definition and plotting
This repository is not a packaged library or application. Instead, it focuses on:
- Providing a clear and reusable PID implementation
- Demonstrating practical control engineering techniques
- Allowing side-by-side comparison between MATLAB and Python implementations
- Serving as a didactic resource for students and practitioners
Both implementations (MATLAB and Python) support:
- P, PI, PD, and PID control
- Manual, automatic, and tracking modes
- Setpoint weighting (
b,c) - Feedforward integration
- Output saturation and rate limiting
- Anti-windup via back-calculation
- Second-order measurement filtering
- Controller duplication (copy/clone functionality)
The included examples cover typical control engineering situations:
- Manual to automatic transfer (bumpless switching)
- P / PD operation via integral deactivation
- Setpoint weighting effects
- Feedforward compensation
- Anti-windup strategies
- Measurement noise filtering
- Gain scheduling (linear and nonlinear systems)
- Selector / override control
Each example follows a consistent structure:
- Load process and simulation data
- Configure controller(s)
- Run a discrete-time simulation loop
- Store signals
- Plot results
Both implementations are conceptually equivalent and designed to mirror each other:
| Aspect | MATLAB | Python |
|---|---|---|
| Controller | @PID/PID.m class |
PID.py class |
| Simulation scripts | .m scripts |
.py scripts |
| Data setup | process_and_simulation_data.m |
process_and_simulation_data.py |
| Plotting | MATLAB plotting | matplotlib |
This makes the repository useful for:
- Translating control logic between environments
- Teaching implementation differences
- Verifying numerical consistency
- Open MATLAB
- Navigate to the
matlabfolder - Run any example:
Example_basic- Create and activate a virtual environment
- Install dependencies:
pip install -r requirements.txt- Run an example:
python3 Example_basic.pyIf you are new to the repository, a sensible progression is:
- Basic example
- MAN/AUTO transfer
- Setpoint weighting
- Feedforward and anti-windup
- Gain scheduling
- Selector control
- This repository is script-based (not a packaged library)
- No license file is currently included
- MATLAB and Python implementations are maintained in parallel but independently
- Some auxiliary files (e.g.,
.mat, autosave files) are used for reproducibility
This repository is especially useful for:
- Control engineering courses
- Research prototyping
- Algorithm validation
- Cross-language implementation comparison
Contributions are welcome, especially:
- Improvements to numerical consistency between implementations
- Additional control scenarios
- Documentation enhancements
No license has been defined yet. Add one before redistribution.