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).
02:14:34 - INFO - LOGGING (log: True) 02:14:34 - INFO - BLOCKS (total: 6, dynamic: 2, static: 4, eventful: 0) 02:14:34 - INFO - GRAPH (nodes: 6, edges: 8, alg. depth: 4, loop depth: 0, runtime: 0.138ms) 02:14:34 - INFO - STARTING -> TRANSIENT (Duration: 100.00s) 02:14:34 - INFO - -------------------- 1% | 0.0s<0.9s | 715.7 it/s 02:14:34 - INFO - ####---------------- 20% | 0.1s<161:42:33 | 2023.4 it/s 02:14:34 - INFO - ########------------ 40% | 0.1s<0.1s | 1396.5 it/s 02:14:34 - INFO - ############-------- 60% | 0.2s<40:49:10 | 1817.6 it/s 02:14:34 - INFO - ################---- 80% | 0.3s<0.0s | 1760.1 it/s 02:14:34 - INFO - #################### 100% | 0.3s<--:-- | 1520.9 it/s 02:14:34 - INFO - FINISHED -> TRANSIENT (total steps: 455, successful: 291, runtime: 342.56 ms)
Results
Let's plot the setpoint, output, and error signals to see how well the PID controller tracks the setpoint: