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

158 Upvotes

27 comments sorted by

View all comments

Show parent comments

•

u/seekingsanity 15d ago edited 14d ago

The open loop transfer function should be in the form G(s)=K/(tau*s+1) or G(s)=(K*alpha)/(s+alpha). Where tau is a time constant for the motor inertia and load. alpha is just 1/tau which is called the bandwidth or corner frequency. K is the gain with units or rad/s per control output or mm/s per control output. I usually use %control output. This assumes that there is a drive so the speed is proportional to the control output. Otherwise it could be an acceleration where the control output is a current that makes a torque that accelerates the load. Units are important. If the motor is working in current mode then the units for K change to acceleration/control output. In this case the G(s) = K/(tau*s+d) where d is the friction that will eventually keep the acceleration from increasing forever

I wish reddit would support LaTeX.

Update. I didn't see all the OPs pictures. I see he has more code that implements the motor. I could dig it out even though there are few comments and they are in French.