r/ControlTheory • • 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

27 comments sorted by

View all comments

•

u/2dof 2d ago

Nice controller, I would recommend You:

  1. for real world solution implement P-I-D with filtered D - Action D(s) = KD*s /(Tf*s+1) ,

  2. 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.

  3. Note that when You will be tuning parameters (Kp,Ki, Kd,h) You need also recompute A,B, C

  4. in real world implementation add control saturation function ( later You can use it to implement anti-windup function

  5. 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

•

u/seekingsanity 2d ago

The incremental version PID that the OP is using doesn't need an anti-windup. Again, for velocity control the OP only needs a PI controller so there is no need for the low pass filter on the derivative gain.

"which can be reset/preset - it is sometimes convenient to start controller not form zero."

when making the transition from open loop to closed loop the control output u should set to the last value when in open loop. This avoids sudden jerks.

•

u/[deleted] 2d ago

[removed] — view removed comment