advanced-pid
An advanced PID controller in Python. The derivative term can also be used in practice thanks to built-in first-order filter. Detailed information can be found here.
Usage is very simple:
from advanced_pid import PID
# Create PID controller
pid = PID(Kp=2.0, Ki=0.1, Kd=1.0, Tf=0.05)
# Control loop
while True:
# Get current measurement from system
timestamp, measurement = system.get_measurement()
# Calculate control signal by using PID controller
reference = 1.0
control = pid(timestamp, reference - measurement)
# Feed control signal to system
system.set_input(control)
Complete API documentation can be found here.
Usage
Biggest advantage of advanced-pid, the derivative term has a built-in first-order
filter.
advanced-pid package includes a toy mass-spring-damper system model for testing:
from advanced_pid import PID
from advanced_pid.models import MassSpringDamper
from matplotlib import pyplot as plt
from numpy import diff
# Create a mass-spring-damper system model
system = MassSpringDamper(mass=1.0, spring_const=1.0, damping_const=0.2)
system.set_initial_value(initial_position=1.0, initial_velocity=0.0)
# Create PID controller
pid = PID(Kp=1.0, Ki=0.0, Kd=2.0, Tf=0.5)
# Control loop
time, meas, cont = [], [], []
for i in range(800):
# Get current measurement from system
timestamp, measurement = system.get_measurement()
# Calculate control signal by using PID controller
control = pid(timestamp, -measurement)
# Feed control signal to system
system.set_input(control)
# Record for plotting
time.append(timestamp)
meas.append(measurement)
cont.append(control)
# Plot result
fig, (ax1, ax2, ax3) = plt.subplots(3, 1)
fig.suptitle('Mass-Spring-Damper system')
ax1.set_ylabel('Measured Position [m]')
ax1.plot(time, meas, 'b')
ax1.grid()
ax2.set_ylabel('Force [N]')
ax2.plot(time, cont, 'g')
ax2.grid()
ax3.set_xlabel('Time [s]')
ax3.set_ylabel('Derivative Term')
ax3.plot(time[1:], diff(meas)/diff(time), 'r')
ax3.grid()
plt.show()
As It can be seen in the figure, derivative term cannot be use without a filter:
Installation
To install, run:
pip3 install advanced-pid
Tests
To run tests, run:
python -m unittest tests.test_pid
License
Licensed under the MIT License.
Metadata
Release files for advanced-pid 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| advanced-pid-0.0.8.tar.gz | 5.2 kB | Without provenance | Details for advanced-pid-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| advanced_pid-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for advanced_pid-0.0.8-py3-none-any.whl |
Total release size: 11.3 kB
Release files / advanced-pid-0.0.8.tar.gz
| Download URL | advanced-pid-0.0.8.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9f51bccbdfbd129a782dfb0c42be45148c4c900a80c6e471b08c53c2638ab5b
|
|
BLAKE2b-256 checksum How to use checksums |
171c6ecdd637951c971edd7b8633142f8338f46fab3bb4eee1e2d7333f2f68ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / advanced_pid-0.0.8-py3-none-any.whl
| Download URL | advanced_pid-0.0.8-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
469fcff1b21bcd95fb40914d2424e180ec1ef308425608c7a200a4318800c8b3
|
|
BLAKE2b-256 checksum How to use checksums |
304ec58a27680c950635936c77ee5e0248d917281cec275f6456b05d5eb7cbae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for advanced-pid 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.