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).
00:44:14 - INFO - LOGGING (log: True) 00:44:14 - INFO - BLOCKS (total: 6, dynamic: 2, static: 4, eventful: 0) 00:44:14 - INFO - GRAPH (nodes: 6, edges: 8, alg. depth: 4, loop depth: 0, runtime: 0.110ms) 00:44:14 - INFO - STARTING -> TRANSIENT (Duration: 100.00s) 00:44:14 - INFO - -------------------- 1% | 0.0s<0.2s | 1002.4 it/s 00:44:14 - INFO - ####---------------- 20% | 0.1s<--:-- | 1161.2 it/s 00:44:15 - INFO - ########------------ 40% | 0.2s<0.1s | 1380.5 it/s 00:44:15 - INFO - ############-------- 60% | 0.4s<74:34:25 | 1085.1 it/s 00:44:15 - INFO - ################---- 80% | 0.4s<0.0s | 1298.8 it/s 00:44:15 - INFO - #################### 100% | 0.5s<--:-- | 1363.3 it/s 00:44:15 - INFO - FINISHED -> TRANSIENT (total steps: 455, successful: 291, runtime: 487.03 ms)
Results
Let's plot the setpoint, output, and error signals to see how well the PID controller tracks the setpoint: