realpid


Namerealpid JSON
Version 0.0.1 PyPI version JSON
download
home_pagehttps://github.com/chentyra/RealPID
SummaryA real PID
upload_time2023-03-29 15:09:20
maintainer
docs_urlNone
authorFederica Oliva
requires_python>=3.7
license
keywords pid pid control controller real
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RealPID

An ideal PID is based on the sum of a proportional, integrative and derivative contribution.

$u(t)= K_P(e(t) + \frac{1}{T_I}\int e(\tau)d\tau+ T_D \frac{de}{dt})$

Controller's transfer function $C(s)$ in Laplace domain is not physically achievable.

$C(s)= \frac{u(t)}{e(t)} = K_P (1+ \frac{1}{T_I \cdot s} + T_D \cdot s = \frac{T_IT_D \cdot s^2 + T_I \cdot s + 1}{T_I \cdot s} )$

Furthermore, an ideal PD amplifies measurement noise, and thus might lead to large control signals that can drive the actuator into saturation or might even cause damage. Therefore, it is necessary to filter of the derivative action in the high-frequency by defining a factor N. It usually takes on a value between 5 and 20.

$C(s)=K_P (1+ \frac{1}{T_I \cdot s} + \frac{T_D \cdot s}{1+s \cdot T_D/N})$

A Python implementation of a real PID is provided.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install foobar.

```bash
pip install realpid
```
## Usage
### Basic Usage

First of all, include the library:
```
from realpid import PID
```
To create PID object, call class's constructor where:
* The first value is **proportional gain** $K_P$
* The second value is **integrative time constant** $T_I$
* The third value is **derivative time constant** $T_D$
* The fourth value is **factor** $N$
* The fifth value is **setpoint** or the value that the PID is trying to achieve
```
pid = PID(1, 0.1, 0.05, 2, setpoint=1)
```
The PID compute a new ```output_value```, on the basis of an ```input_value```, calling the object created.
```
output_value= pid(input_value)
```
### An example

```
from realpid import PID
pid = PID(0.2, 0.6, 0.02, 5, setpoint=1)

while True:
    control = pid(v)
```
### Sample Time

Optionally, a ```sample_time``` can be definied  as last attribute of the instruction which represents the amount of time between one call to another of the updating method:
```
pid.sample_time= 0.01
```
### Output Limit
To avoid integral windup and to limit output value, attribute ```output_limits``` can be set:
```
pid.output_limits = (0, None)  # Output will always be positive, but with no upper bound
```
### Switching On And Off
In order to turn off PID controller, set attribute ```auto_mode``` to False:
```
pid.auto_mode = False
```
In the same way, to turn on PID controller, set attribute ```auto_mode``` to True:
```
pid.auto_mode = True
```
When controlling the system manually, it is useful to set the value of the integral term to the value indicated by the attribute ```last_output```:
```
pid.set_auto_mode(True, last_output=1)
```
## Reset 
The PID controller can be reset calling the ```reset``` method
```
pid.reset()
```
## Other Features 
The value of $K_P$,  $T_I$ , $T_D$ , $N$ can be seen in this way:
```
Kp, Ti, Td,N = pid.components
```
Their values can be changed individually or all at once when the PID is running:
```
pid.Kp = 1.0
pid.tunings = (1.0, 0.3, 0.01, 10)
```
## License
Licensed under the [MIT][def]

[def]: https://choosealicense.com/licenses/mit/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/chentyra/RealPID",
    "name": "realpid",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "pid,PID,control,controller,real",
    "author": "Federica Oliva",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/33/5f/57c38b3d435419adcbb5867f2e860f0b5d631f3b186dc840ef42f871d218/realpid-0.0.1.tar.gz",
    "platform": null,
    "description": "# RealPID\r\n\r\nAn ideal PID is based on the sum of a proportional, integrative and derivative contribution.\r\n\r\n$u(t)= K_P(e(t) + \\frac{1}{T_I}\\int e(\\tau)d\\tau+ T_D \\frac{de}{dt})$\r\n\r\nController's transfer function $C(s)$ in Laplace domain is not physically achievable.\r\n\r\n$C(s)= \\frac{u(t)}{e(t)} = K_P (1+ \\frac{1}{T_I \\cdot s} + T_D \\cdot s = \\frac{T_IT_D \\cdot s^2 + T_I \\cdot s + 1}{T_I \\cdot s} )$\r\n\r\nFurthermore, an ideal PD amplifies measurement noise, and thus might lead to large control signals that can drive the actuator into saturation or might even cause damage. Therefore, it is necessary to filter of the derivative action in the high-frequency by defining a factor N. It usually takes on a value between 5 and 20.\r\n\r\n$C(s)=K_P (1+ \\frac{1}{T_I \\cdot s} + \\frac{T_D \\cdot s}{1+s \\cdot T_D/N})$\r\n\r\nA Python implementation of a real PID is provided.\r\n\r\n## Installation\r\n\r\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install foobar.\r\n\r\n```bash\r\npip install realpid\r\n```\r\n## Usage\r\n### Basic Usage\r\n\r\nFirst of all, include the library:\r\n```\r\nfrom realpid import PID\r\n```\r\nTo create PID object, call class's constructor where:\r\n* The first value is **proportional gain** $K_P$\r\n* The second value is **integrative time constant** $T_I$\r\n* The third value is **derivative time constant** $T_D$\r\n* The fourth value is **factor** $N$\r\n* The fifth value is **setpoint** or the value that the PID is trying to achieve\r\n```\r\npid = PID(1, 0.1, 0.05, 2, setpoint=1)\r\n```\r\nThe PID compute a new ```output_value```, on the basis of an ```input_value```, calling the object created.\r\n```\r\noutput_value= pid(input_value)\r\n```\r\n### An example\r\n\r\n```\r\nfrom realpid import PID\r\npid = PID(0.2, 0.6, 0.02, 5, setpoint=1)\r\n\r\nwhile True:\r\n    control = pid(v)\r\n```\r\n### Sample Time\r\n\r\nOptionally, a ```sample_time``` can be definied  as last attribute of the instruction which represents the amount of time between one call to another of the updating method:\r\n```\r\npid.sample_time= 0.01\r\n```\r\n### Output Limit\r\nTo avoid integral windup and to limit output value, attribute ```output_limits``` can be set:\r\n```\r\npid.output_limits = (0, None)  # Output will always be positive, but with no upper bound\r\n```\r\n### Switching On And Off\r\nIn order to turn off PID controller, set attribute ```auto_mode``` to False:\r\n```\r\npid.auto_mode = False\r\n```\r\nIn the same way, to turn on PID controller, set attribute ```auto_mode``` to True:\r\n```\r\npid.auto_mode = True\r\n```\r\nWhen controlling the system manually, it is useful to set the value of the integral term to the value indicated by the attribute ```last_output```:\r\n```\r\npid.set_auto_mode(True, last_output=1)\r\n```\r\n## Reset \r\nThe PID controller can be reset calling the ```reset``` method\r\n```\r\npid.reset()\r\n```\r\n## Other Features \r\nThe value of $K_P$,  $T_I$ , $T_D$ , $N$ can be seen in this way:\r\n```\r\nKp, Ti, Td,N = pid.components\r\n```\r\nTheir values can be changed individually or all at once when the PID is running:\r\n```\r\npid.Kp = 1.0\r\npid.tunings = (1.0, 0.3, 0.01, 10)\r\n```\r\n## License\r\nLicensed under the [MIT][def]\r\n\r\n[def]: https://choosealicense.com/licenses/mit/\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A real PID",
    "version": "0.0.1",
    "split_keywords": [
        "pid",
        "pid",
        "control",
        "controller",
        "real"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6a32154cf5b34dea64d8e02337fa32fabc8d0548c0d9f4c11b8a8d6eacd3b5d",
                "md5": "2697e6d4abfde39a1a877b7dbcd107d8",
                "sha256": "9c2d00fb595ada9ee8e7424e2c9e637eddcaaebff9dd185cffda945b200e8204"
            },
            "downloads": -1,
            "filename": "realpid-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2697e6d4abfde39a1a877b7dbcd107d8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5678,
            "upload_time": "2023-03-29T15:09:18",
            "upload_time_iso_8601": "2023-03-29T15:09:18.570958Z",
            "url": "https://files.pythonhosted.org/packages/c6/a3/2154cf5b34dea64d8e02337fa32fabc8d0548c0d9f4c11b8a8d6eacd3b5d/realpid-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "335f57c38b3d435419adcbb5867f2e860f0b5d631f3b186dc840ef42f871d218",
                "md5": "aaba47f93639bc6221294a073c0019c0",
                "sha256": "ff50989aecd14d7376de804afcf4cf3b8a4da3c10f3560f9d458b6fba1ae686b"
            },
            "downloads": -1,
            "filename": "realpid-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "aaba47f93639bc6221294a073c0019c0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5073,
            "upload_time": "2023-03-29T15:09:20",
            "upload_time_iso_8601": "2023-03-29T15:09:20.708226Z",
            "url": "https://files.pythonhosted.org/packages/33/5f/57c38b3d435419adcbb5867f2e860f0b5d631f3b186dc840ef42f871d218/realpid-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-29 15:09:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "chentyra",
    "github_project": "RealPID",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "realpid"
}
        
Elapsed time: 0.05043s