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).
18:38:02 - INFO - LOGGING (log: True) 18:38:02 - INFO - BLOCKS (total: 6, dynamic: 2, static: 4, eventful: 0) 18:38:02 - INFO - GRAPH (nodes: 6, edges: 8, alg. depth: 4, loop depth: 0, runtime: 0.142ms) 18:38:02 - INFO - STARTING -> TRANSIENT (Duration: 100.00s) 18:38:02 - INFO - -------------------- 1% | 0.0s<1.0s | 541.1 it/s 18:38:02 - INFO - ####---------------- 20% | 0.1s<--:-- | 1205.3 it/s 18:38:02 - INFO - ########------------ 40% | 0.2s<0.2s | 1172.6 it/s 18:38:02 - INFO - ############-------- 60% | 0.4s<55:14:09 | 1182.1 it/s 18:38:02 - INFO - ################---- 80% | 0.4s<0.0s | 1197.4 it/s 18:38:02 - INFO - #################### 100% | 0.5s<--:-- | 1178.0 it/s 18:38:02 - INFO - FINISHED -> TRANSIENT (total steps: 455, successful: 291, runtime: 486.89 ms)
Results
Let's plot the setpoint, output, and error signals to see how well the PID controller tracks the setpoint: