Language: C++
Purpose: Simulates a closed-loop PID-controlled system that regulates speed toward a target value over discrete timesteps.
This project implements a minimal yet functional PID (Proportional–Integral–Derivative) controller coupled with a simple system simulator to visualize dynamic feedback control.
The system models how a controller drives a simulated variable (e.g., speed) toward a defined target through iterative updates.
The program produces an exponential-like convergence curve characteristic of stable PID systems, which can be plotted directly using Gnuplot from within C++.
PIDController— computes control signals usingKp,Ki, andKd.SystemSimulator— updates the simulated system’s state based on control input and responsiveness.Unit— integrates both components into a loop and manages Gnuplot visualization.
timestep: 0 current speed: 50 updated speed: 65.1
timestep: 10 current speed: 95.4 updated speed: 96.6
timestep: 50 current speed: 101.7 updated speed: 101.7
The resulting plot shows a smooth exponential rise with slight overshoot and fast stabilization — a hallmark of a properly tuned PID loop.
Simulation results are plotted using Gnuplot, launched directly from the program via a pipe:
set title "PID Controller Simulation"
set xlabel "Time step"
set ylabel "Speed"
plot '-' using 1:2 with lines title 'Current Speed', \
'-' using 1:2 with lines title 'Updated Speed'