Control Systems Coursework

PI Control

Step response, stability margins, and gain sensitivity for a PI-controlled plant.

PythonPI control24 figuresSciPyStabilityGain LabCSV + JSON

Overview

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.

What's Inside

ResourceLink
Analysis and CLIpi_control/__main__.py
Plot exporterspi_control/plots.py
Verification notesdocs/verification.md
Dependenciesrequirements.txt
Website previewindex.html

Model and Stability

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.

Baseline Results

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.

How the Metrics Work

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.

Reading a Report

Step metrics

Rise time uses the first threshold crossings. Peak and settling time depend on the simulation grid. A null settling time means the window did not establish settling.

Final value

The last simulated point depends on the duration. For a stable system the analytical final value is one, so the unit-step tracking error tends to zero.

Stability boundary

The Routh first column is 1, 2, (2 Kp − Ki)/2, Ki. At Ki = 2 Kp the poles include an imaginary-axis pair.

Gain Experiments

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.

Limitations

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.

Interactive Gain Lab

Change Kp and the fraction Ki / (2 Kp). At a fraction of 1 the poles reach the imaginary axis. Above 1 the nominal linear model is unstable.

Use the Python CLI for the step-response data.
  • Selected gains
  • Baseline gains (dashed)
  • Unit reference (dotted)

The browser integrates the ideal model for 30 seconds. Use the Python CLI and a longer horizon for settling estimates.

Screenshots

Filter by topic or search captions. Open a figure to inspect the full frame.

Reproduce and Export

The Python package includes the analysis engine, plot exporters, and a seven-case comparison. The project configuration supports installation and console commands.

python -m pi_control --output outputs/baseline
python -m pi_control.compare --csv outputs/gain_comparison.csv

The first command writes JSON, a time-series CSV, a step-response plot, a pole-zero map, and two Bode plots. The second produces a comparison table. Cases at and beyond marginal stability are included and use blank entries for steady-state metrics.

Folder Structure

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

How to Run

From the repository root on Windows:

python -m venv .venv
.venv/Scripts/python -m pip install -r requirements.txt
.venv/Scripts/python -m pi_control --output outputs

Omit the output flag to print metrics only. Add --help to see the available options.

About the Author

Mohammad Rohaan · Control systems coursework.

GitHub profile

Full image