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

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.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

PID_Py-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: PID_Py-0.1.1.tar.gz
  • Upload date:
  • Size: 4.3 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.1.tar.gz
Algorithm Hash digest
SHA256 b3ca00241268c2991509cba639fec99c52923c229bd1fd864af115a2ac7c3fc5
MD5 d25e663ef927b23f0d6c9f3984095bf8
BLAKE2b-256 024ce65ed5a0db5474dc3d1db23e847378b0d347a4fc27014bbb1986504cd2e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PID_Py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8e2d2518a57d1eec3de55e877910ec09fef27fcd11f76e4e68bdfdbdccda218
MD5 034e3ccd12984cf08c850f3e11e0a2a7
BLAKE2b-256 5314c6a43a93081bd7471909e2780421a78a125c1d38088f69d4ab00a638a0b0

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