PID Controller
Simulation of a PID controller tracking a step-changing setpoint.
You can also find this example as a single file in the GitHub repository.
The control system uses a PID controller block that computes the control signal based on the error between setpoint and output. The plant is modeled as an Integrator with a gain. As a block diagram it looks like this:

Import and Setup
First let's import the required classes and blocks:
System Parameters
We define the plant gain and PID parameters.
System Definition
Now we can construct the system by instantiating the blocks we need and collecting them in a list:
The connections form a feedback control loop. The Adder block with signature "+-" computes the error signal by subtracting the plant output from the setpoint.
Simulation Setup and Execution
We initialize the simulation with the RKCK54 solver (Runge-Kutta Cash-Karp 5th order with adaptive step size).
19:10:19 - INFO - LOGGING (log: True) 19:10:19 - INFO - BLOCKS (total: 6, dynamic: 2, static: 4, eventful: 0) 19:10:19 - INFO - GRAPH (nodes: 6, edges: 8, alg. depth: 4, loop depth: 0, runtime: 0.124ms) 19:10:19 - INFO - STARTING -> TRANSIENT (Duration: 100.00s) 19:10:19 - INFO - -------------------- 1% | 0.0s<0.2s | 1356.0 it/s 19:10:19 - INFO - ####---------------- 20% | 0.1s<119:40:51 | 2833.1 it/s 19:10:19 - INFO - ########------------ 40% | 0.1s<0.0s | 3802.5 it/s 19:10:19 - INFO - ############-------- 60% | 0.1s<21:26:59 | 3604.3 it/s 19:10:19 - INFO - ################---- 80% | 0.2s<0.0s | 3529.0 it/s 19:10:19 - INFO - #################### 100% | 0.2s<--:-- | 3540.5 it/s 19:10:19 - INFO - FINISHED -> TRANSIENT (total steps: 455, successful: 291, runtime: 188.31 ms)
Results
Let's plot the setpoint, output, and error signals to see how well the PID controller tracks the setpoint: