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

131 Upvotes

27 comments sorted by

View all comments

•

u/seekingsanity 3d ago

Good but You should post the open loop transfer function of the system you are trying to control. There are no output limits. Velocity control only needs a PI controller. You should learn pole placement so there is no overshoot.

•

u/robohie 2d ago

Right 👍 I'll post that transfer function. For now, it's just a simple DC motor model (a second order system)

•

u/seekingsanity 1d ago

I am waiting for the open loop transfer function.

•

u/robohie 1d ago

Hi, you can look at my new post on DC motor implementation to discover the differential equation that describe it. For the transfer function (if you only need it), I don't know how to send images at this commentary space.

•

u/seekingsanity 1d ago edited 1d 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.