Skip to content

adegenaar/PID

Repository files navigation

License: MIT PythonTemplate

PID Controller for Python

Simple PID control class for Python.

based on the C example found here: PID Controller Written in C

More details on PID loop control can be found on Wikipedia

A calculator for tuning the PID loop is available here

Usage is simple:

  • Create the a PID object
    • pid = PIDController()
    • pid = PIDController(kp, ki, kd)
  • Set the initial values:
    • kp - (Proportional)
    • ki - (Integral)
    • kd - (Derivative)
    • limmin - Lower limit on the output delta
    • limmax - Upper Limit on the output delta
    • tau - Lag term for the Integrator
    • T - Time is seconds
    • limMinInt - Lower limit for the Integrator
    • limMaxInt - Upper limit for the Integrator
  • Loop, updating the expected (setpoint) and actual (measurement) values for a given time
    setpoint = 1.0
    
    print("Time(s)\tSystemOut\tController Out")
    t = 0.0
    while t < 4.0:
        measurement = <function for real values>(pid.out)
        pid.update(setpoint, measurement)
        print(f"{t}\t{measurement}\t{pid.out}")
        t += 0.01
    

About

PID Controller in python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages