| What | Link |
|---|---|
| Repository | https://github.com/rohaan2802/PI_Control |
| GitHub Pages | https://rohaan2802.github.io/PI_Control/ |
| SciPy LTI reference | https://docs.scipy.org/doc/scipy/reference/signal.html#continuous-time-linear-systems |
- Live Links
- Overview
- What's Inside
- Model and Stability
- Baseline Results
- How the Metrics Work
- Gain Experiments
- Limitations
- Folder Structure
- How to Run
- Interactive Gain Lab
- Reproduce and Export
- Screenshots
- About the Author
A Python study of a proportional–integral controller for the damped plant G(s) = 1/[s(s + 2)]. It examines reference tracking, closed-loop stability, and open-loop frequency margins.
| Resource | File |
|---|---|
| Original assignment script | original_pi_controller.py (reference copy) |
| Analysis and CLI | main.py |
| Plot exporters | plots.py |
| Verification notes | verification.md |
| Gain comparison CLI | compare.py |
| Python project file | pyproject.toml |
| Browser simulator | gain_lab.js |
| Dependencies | requirements.txt |
| Website preview | index.html |
Under negative unity feedback, L(s) = (Kp s + Ki)/[s²(s + 2)] and T(s) = (Kp s + Ki)/(s³ + 2s² + Kp s + Ki). With positive gains, the Routh array gives Ki < 2 Kp. The controller zero is −Ki/Kp.
The plant has one integrator and one pole at −2. The controller adds another open-loop integrator and a zero at −Ki/Kp. Substituting the loop into the unity feedback equation gives the characteristic polynomial [1, 2, Kp, Ki]. The first column of its Routh array is 1, 2, (2 Kp − Ki)/2, Ki. Positive gains on the boundary Ki = 2 Kp give imaginary-axis poles, so the CLI classifies that case as not asymptotically stable.
The original gains are Kp = 2.02488613 and Ki = 0.06465480. The 160 s simulation gives 1.441 s rise time, 7.738% overshoot, 16.29 s settling time, and 63.303° phase margin. The stable closed-loop DC gain is one. Gain margin is infinite for the baseline loop.
Rise time uses the first 10% and 90% crossings of the unit reference, with interpolation between samples. Overshoot is measured relative to the unit target. Settling uses the last sample outside the ±2% band. Steady-state error comes from DC gain. Stability margins come from the open loop, while closed-loop magnitude and phase describe reference tracking.
| Field | How to interpret it |
|---|---|
| sampled_final | The simulated output at the final time, which can differ from the analytical limit |
| peak_time_s | The sampled time of the largest response in the simulation window |
| settling_time_s | The first sample after the last excursion outside the 2% band. A null value means no settling time was established. |
| gain_crossover_rad_s | Frequency where the open-loop magnitude is one |
| phase_margin_deg | Angular distance to −180° at unity gain |
The gallery holds one gain fixed while sweeping the other. It also shows the poles and unit-step responses around the Routh boundary. These sweeps illustrate sensitivity to the gains. They do not automate controller tuning.
This model assumes a linear continuous-time plant, ideal feedback, a unit step, and zero initial conditions. There is no hardware validation. Finite sampling limits peak and settling-time precision, especially near the stability boundary.
PI_Control/
├── pi_control/ Analysis and export code
├── docs/ Verification notes
├── assets/ 24 figures, previews and site assets
├── pyproject.toml Installable project configuration
├── requirements.txt
├── index.html
└── README.md
python -m venv .venv
.venv/Scripts/python -m pip install -r requirements.txt
.venv/Scripts/python -m pi_control --output outputsOmit the output flag to print the report only. Use --kp, --ki, or --duration to compare another configuration. Output files are generated on demand.
Open the Gain Lab and vary Kp or the ratio Ki / (2 Kp). The chart compares the selected gains with the original controller and the unit reference. Set the ratio to 1 with Set boundary, or restore the original gains with Reset to baseline.
For the unit step, the browser solves y‴ + 2y″ + Kp y′ + Ki y = Ki. The initial output and first derivative are zero, and the second derivative just after the step is Kp. The browser uses fourth-order Runge–Kutta with a 0.01 s step over 30 s. The Python command-line study uses SciPy and defaults to a 160 s window.
python -m pi_control --output outputs/baseline
python -m pi_control.compare --csv outputs/gain_comparison.csvThe first command exports metrics.json, step_response.csv, step_response.png, pole_zero.png, open_loop_bode.png and closed_loop_bode.png. The CSV columns are time in seconds, output, and signed tracking error. The comparison command exports seven configurations with their actual gains and measured results.
| Gain choice | Stability | Overshoot | 2% settling |
|---|---|---|---|
| Original PI gains | Stable | 7.74% | 16.29 s |
| Half Kp | Stable | 9.92% | 30.68 s |
| Double Kp | Stable | 17.62% | 3.72 s |
| Double Ki | Stable | 10.87% | 19.30 s |
| Ki = 1.8 Kp | Stable | 94.64% | 110.01 s |
| Ki = 2 Kp | Marginal | — | — |
| Ki = 2.2 Kp | Unstable | — | — |
This comparison uses the same 160 s horizon. Doubling Kp settles sooner in this model at the cost of more overshoot. Moving Ki near the boundary leaves the stable response weakly damped.
To install the project after activating a Python 3.14 virtual environment, run python -m pip install -e . in the project root. The configuration in pyproject.toml adds the pi-control and pi-compare console commands. The Python module commands work directly from the repository with the dependencies installed.
24 captures on consistent 1440 × 900 frames. Select any preview to open the full image.
Plant and PI controller · Open-loop transfer function · Closed-loop transfer function · Routh stability condition · Baseline poles and zero · Slow pole and zero close-up · Model assumptions · Command-line workflow
Full unit-step response · First peak close-up · Rise-time thresholds · Settling inside the 2% band · Baseline step metrics · Tracking error over time · Why the horizon matters
Open-loop magnitude · Open-loop phase · Closed-loop magnitude · Closed-loop phase · Baseline stability margins
Proportional gain sweep · Integral gain sweep · Pole movement as Ki rises · Across the stability boundary
Continuous-time transfer functions from the original assignment.
The loop combines the controller and plant. Its response determines the stability margins.
Unity feedback gives a third-order characteristic polynomial.
For positive gains, strict stability requires Ki < 2 Kp.
The long horizon shows the slow approach to the analytical final value.
The baseline peak occurs at about 3.14 s.
The first crossings of 0.1 and 0.9 define the 10–90% rise time.
The estimated settling time is 16.29 s on the baseline grid.
Metrics use the unit target as the steady-state value.
The signed difference between the unit target and the output.
The three poles lie in the left half-plane.
The real pole and controller zero are close together but distinct.
The gain crossover is where the open-loop magnitude reaches 0 dB.
The open-loop phase is evaluated at gain crossover to obtain phase margin.
This response describes reference tracking across frequencies.
Closed-loop phase is separate from the open-loop stability margins.
An infinite gain margin indicates no finite −180° phase crossover in the baseline loop.
Simulated responses at half, baseline, and double proportional gain with Ki held fixed.
Simulated responses at half, baseline, and double integral gain with Kp held fixed.
Blue points are stable and orange points lie beyond the Routh boundary.
Responses on either side of Ki = 2 Kp illustrate why the strict inequality matters.
The study uses an ideal continuous-time plant and a linear controller.
A finite sample and the true steady-state limit answer different questions.
Reproduce the study and export plots or the machine-readable report.
Mohammad Rohaan · Control systems coursework.