Skip to main content

Simple (but complete) PID controller in Python

Project description

PID_Py

PID_Py provide a PID controller wrote in Python. This PID controller is simple to use, but it's complete.

Installation

python3 -m pip install PID_Py

Usage

Minimum usage

from PID_Py.PID import PID

# Initialization
pid = PID(kp = 0.0, ki = 0.0, kd = 0.0)

...

# PID execution (call it as fast as you can)
command = pid(processValue = feedback, setpoint = targetValue)

In this usage the PID as no limitation, no history and the PID is in direct action (Error increasing -> Increase output).

Indirect action PID

If you have a system that required to decrease command to increase feedback, you can use indirectAction parameters.

from PID_Py.PID import PID

# Initialization
pid = PID(kp = 0.0, ki = 0.0, kd = 0.0, indirectAction = True)

...

# PID execution (call it as fast as you can)
command = pid(processValue = feedback, setpoint = targetValue)

Limiting output

If your command must be limit you can use outputLimits parameters.

from PID_Py.PID import PID

# Initialization
pid = PID(kp = 0.0, ki = 0.0, kd = 0.0, outputLimits = (0, 100))

...

# PID execution (call it as fast as you can)
command = pid(processValue = feedback, setpoint = targetValue)

By default the value is (None, None), wich implies that there is no limits. You can activate just the maximum limit with (None, 100). The same for the minimum limit (-100, None).

Historian

If you want to historize PID values, you can configure the historian to record values.

from PID_Py.PID import PID
from PID_Py.PID import HistorianParameters

# Initialization
historianParameters = HistorianParamters.SETPOINT | HistorianParameters.PROCESS_VALUE
pid = PID(kp = 0.0, ki = 0.0, kd = 0.0, historianParameters = HistorianParameters)

...

# PID execution (call it as fast as you can)
command = pid(processValue = feedback, setpoint = targetValue)

...

# PID Historian
import matplotlib.pyplot as plt

plt.plot(pid.historian["TIME"], pid.historian["SETPOINT"], label="Setpoint")

plt.plot(pid.historian["TIME"], pid.historian["PROCESS_VALUE"], label="Process value")

plt.legend()
plt.show()

In the example above, the PID historian records setpoint, processValue and time. Time is the elapsed time from the start. After that a graphic is draw with matplotlib.

Historian parameters list

  • P : proportionnal part
  • I : integral part
  • D : derivative part
  • ERROR : PID error
  • SETPOINT : PID setpoint
  • PROCESS_VALUE : PID process value
  • OUTPUT : PID output

Integral limitation

The integral part of the PID can be limit to avoid overshoot of the output when the error is too high (When the setpoint variation is too high, or when the system have trouble to reach setpoint).

from PID_Py.PID import PID

# Initialization
pid = PID(kp = 0.0, ki = 0.0, kd = 0.0, integralLimit = 20.0)

...

# PID execution (call it as fast as you can)
command = pid(processValue = feedback, setpoint = targetValue)

In the example above, the integral part of the PID is clamped between -20 and 20.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PID_Py-0.1.4.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

PID_Py-0.1.4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file PID_Py-0.1.4.tar.gz.

File metadata

  • Download URL: PID_Py-0.1.4.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for PID_Py-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c2aea48eb4348163f543a708ea6c5a081243c1b35aaf1949c753b9d2704e240d
MD5 4b56761447be2d295d1bde3f325675ff
BLAKE2b-256 8711cd64d3bf2452566ce4f781716bb3e30948f03a9d9a3ecb9138ddf4689d6a

See more details on using hashes here.

File details

Details for the file PID_Py-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: PID_Py-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for PID_Py-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4009093a315bfd80944b87252128d8bd3048d23fe0d491729478c6d15ac1af47
MD5 48846687081f2cbef9eb91b75a3019e7
BLAKE2b-256 6d91450a74d5295d46cbbd97e7d32651ec55393855727707dcc3ac0ff5f2c805

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page