{"id":18266790,"url":"https://github.com/chentyra/discrete-timepid","last_synced_at":"2025-04-12T00:34:04.044Z","repository":{"id":148759180,"uuid":"620894738","full_name":"chentyra/Discrete-TimePID","owner":"chentyra","description":" A physically achievable PID controller (discrete-time PID) with noise filter.","archived":false,"fork":false,"pushed_at":"2024-07-03T12:57:56.000Z","size":48,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T20:21:14.857Z","etag":null,"topics":["control","control-systems","control-theory","controller","discrete-time","discrete-time-regulators","discrete-time-systems","filter","noise","noise-reduction","pid","pid-control","pid-controller","pidcontroller","pip","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chentyra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-29T15:22:35.000Z","updated_at":"2024-10-14T09:21:40.000Z","dependencies_parsed_at":"2024-12-22T08:34:12.437Z","dependency_job_id":"0d439c77-6697-4841-b572-cc9d6889da56","html_url":"https://github.com/chentyra/Discrete-TimePID","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"2d7b5a47d2858a56526b78fc4221a9575d31fb8c"},"previous_names":["chentyra/discrete-timepid","chentyra/realpid"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chentyra%2FDiscrete-TimePID","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chentyra%2FDiscrete-TimePID/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chentyra%2FDiscrete-TimePID/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chentyra%2FDiscrete-TimePID/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chentyra","download_url":"https://codeload.github.com/chentyra/Discrete-TimePID/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501701,"owners_count":21114676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["control","control-systems","control-theory","controller","discrete-time","discrete-time-regulators","discrete-time-systems","filter","noise","noise-reduction","pid","pid-control","pid-controller","pidcontroller","pip","python"],"created_at":"2024-11-05T11:24:54.308Z","updated_at":"2025-04-12T00:34:04.016Z","avatar_url":"https://github.com/chentyra.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Discrete-Time PID\n\nAn ideal PID is based on the sum of a proportional, integrative and derivative contribution.\n\n$u(t)= K_P(e(t) + \\frac{1}{T_I}\\int e(\\tau)d\\tau+ T_D \\frac{de}{dt})$\n\nController's transfer function $C(s)$ in Laplace domain is not physically achievable.\n\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} $\n\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.\n\n$C(s)=K_P (1+ \\frac{1}{T_I \\cdot s} + \\frac{T_D \\cdot s}{1+s \\cdot T_D/N})$\n\nA Python implementation of a discrete-time PID is provided.\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install the discrete-time PID.\n\n```bash\nsudo pip install git+https://github.com/chentyra/Discrete-TimePID.git#egg=discretepid\n```\n\n**If the Python package was helpful to you, please give this repository a star!** :star:\n\n## Usage\n### Basic Usage\n\nFirst of all, include the library:\n```\nfrom discretepid import PID\n```\nTo create PID object, call class's constructor where:\n* The first value is **proportional gain** $K_P$\n* The second value is **integrative time constant** $T_I$\n* The third value is **derivative time constant** $T_D$\n* The fourth value is **factor** $N$\n* The fifth value is **setpoint** or the value that the PID is trying to achieve\n```\npid = PID(1, 0.1, 0.05, 2, setpoint=1)\n```\nWith this definition, PID object uses a step change setpoint. The definition of an optional sixth parameter a ramp change setpoint is used by PID object. \n* The ```ramping_rate``` variable defines the time interval in seconds of the ramp duration.\n\n```\npid = PID(1, 0.1, 0.05, 2, setpoint=1, ramping_rate=1)\n```\n\nThe PID compute a new ```output_value```, on the basis of an ```input_value```, calling the object created.\n```\noutput_value= pid(input_value)\n```\n### An example\n\n```\nfrom discretepid import PID\npid = PID(0.2, 0.6, 0.02, 5, setpoint=1)\n\nwhile True:\n    control = pid(v)\n```\n### Setpoint\nThe controller setpoint can be changed dynamically:\n``` \npid.setpoint = 3 \n```\n\n### Ramp duration\nThe ramp duration can be changed dynamically:\n``` \npid.ramping_rate = 1 \n```\nand can be reset calling ```reset_ramping_rate``` method:\n``` \npid.reset_ramping_rate()\n```\n\u003e [!WARNING]\n\u003e Setting the ramping_rate variable to 0 is equivalent to using a step change setpoint.\n### Sample Time\n\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:\n```\npid.sample_time= 0.01\n```\n### Output Limit\nTo avoid integral windup and to limit output value, attribute ```output_limits``` can be set:\n```\npid.output_limits = (0, None)  # Output will always be positive, but with no upper bound\n```\n### Switching On And Off\nIn order to turn off PID controller, set attribute ```auto_mode``` to False:\n```\npid.auto_mode = False\n```\nIn the same way, to turn on PID controller, set attribute ```auto_mode``` to True:\n```\npid.auto_mode = True\n```\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```:\n```\npid.set_auto_mode(True, last_output=1)\n```\n## Reset PID controller\nThe PID controller can be reset calling the ```reset``` method.\n```\npid.reset()\n```\n## Other Features \nThe value of $K_P$,  $T_I$ , $T_D$ , $N$, $setpoint$ can be seen in this way:\n```\nKp, Ti, Td, N, setpoint, ramping_rate = pid.components\n```\nTheir values can be changed individually or all at once(setpoint is optional) when the PID is running:\n```\npid.Kp = 1.0\npid.tunings = (1.0, 0.3, 0.01, 10,2) #Kp,Ti,Td,N,setpoint\n```\n## Examples\nThe ```examples``` folder contains several simulations to help you understand how to use PID controller.\n## License\nLicensed under the [MIT][def]\n\n[def]: https://choosealicense.com/licenses/mit/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchentyra%2Fdiscrete-timepid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchentyra%2Fdiscrete-timepid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchentyra%2Fdiscrete-timepid/lists"}