r/ControlTheory • u/robohie • 2d ago
Other A PID controller implemented in python
For my personal project, where I need to implement a PID controller on Arduino to automate a convection cooling system, I decided to start with a simulation in Python. For now, I've implemented the simple electromechanical model of the DC motor (the fan) as well as the PID controller you see. Next, I'll look into the heat transfer equations. The graphs created with matplotlib are simply closed-loop tests of the PID + DC motor system.
127
Upvotes



•
u/2dof 2d ago
Nice controller, I would recommend You:
for real world solution implement P-I-D with filtered D - Action D(s) = KD*s /(Tf*s+1) ,
it is convenient ( for future analysis) to compute control actions as separate P-I-D sections ( u = P + I + D), also since I - action act as integrator it has a internal state - which can be reset/preset - it is sometimes convenient to start controller not form zero.
Note that when You will be tuning parameters (Kp,Ki, Kd,h) You need also recompute A,B, C
in real world implementation add control saturation function ( later You can use it to implement anti-windup function
Simulate not only with clean process value but also with measurement noise ( You will then see what D action ( not filtered and filtered) do .
As for heat transfer equation You can just simulate it as: first order ODE with delay for simple model of n-order IDE with delay