{"id":17843257,"url":"https://github.com/philmod/node-pid-controller","last_synced_at":"2025-05-16T02:07:16.729Z","repository":{"id":65411414,"uuid":"10683174","full_name":"Philmod/node-pid-controller","owner":"Philmod","description":"Node.js PID controller","archived":false,"fork":false,"pushed_at":"2025-02-19T16:31:08.000Z","size":46,"stargazers_count":127,"open_issues_count":6,"forks_count":26,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-05-16T02:06:44.333Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Philmod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2013-06-14T06:29:12.000Z","updated_at":"2025-03-18T08:43:50.000Z","dependencies_parsed_at":"2023-01-23T10:54:58.316Z","dependency_job_id":"5bae416f-5310-48fe-8131-d6b785016597","html_url":"https://github.com/Philmod/node-pid-controller","commit_stats":{"total_commits":31,"total_committers":7,"mean_commits":4.428571428571429,"dds":0.5806451612903225,"last_synced_commit":"8349fd85fc52950dad61a74930ed40ae11374983"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philmod%2Fnode-pid-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philmod%2Fnode-pid-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philmod%2Fnode-pid-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Philmod%2Fnode-pid-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Philmod","download_url":"https://codeload.github.com/Philmod/node-pid-controller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453652,"owners_count":22073617,"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":[],"created_at":"2024-10-27T21:23:18.763Z","updated_at":"2025-05-16T02:07:16.670Z","avatar_url":"https://github.com/Philmod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-pid-controller\r\n\r\nSimple Node.js PID controller.\r\n\r\n![pid](http://upload.wikimedia.org/wikipedia/commons/9/91/PID_en_updated_feedback.svg)\r\n\r\n## Installation\r\n\r\n```\r\n$ npm install node-pid-controller\r\n```\r\n\r\n## Example\r\n\r\nLet's take the example of a car cruise control. We want the car driving at 120km/h.\r\n\r\n### Create a Controller instance\r\n\r\n`k_p`, `k_i` and `k_d` are the proportional, integral and derivative terms. `dt` is the interval of time between two measures. If not set, it will be automatically calculated.\r\n\r\n```js\r\nlet Controller = require('node-pid-controller');\r\n\r\nlet ctr = new Controller({\r\n  k_p: 0.25,\r\n  k_i: 0.01,\r\n  k_d: 0.01,\r\n  dt: 1\r\n});\r\n```\r\n\r\nYou can also pass options as arguments:\r\n```js\r\nlet ctr = new Controller(0.25, 0.01, 0.01, 1); // k_p, k_i, k_d, dt\r\n```\r\n\r\n### Set the target\r\n\r\n```js\r\nctr.setTarget(120); // 120km/h\r\n```\r\n\r\n### Get the correction\r\n\r\n```js\r\nlet correction = ctr.update(110); // 110km/h is the current speed\r\n```\r\n\r\n### Real example\r\n\r\nNormally, you use the correction to a measure, in a closed loop.\r\n\r\n```js\r\nlet goalReached = false\r\nwhile (!goalReached) {\r\n  let output = measureFromSomeSensor();\r\n  let input  = ctr.update(output);\r\n  applyInputToActuator(input);\r\n  goalReached = (input === 0); // in the case of continuous control, you let this variable 'false'\r\n}\r\n```\r\n\r\n## Options\r\n\r\n* `k_p`, `k_i`, `k_d`: the PID's coefficients\r\n* `dt`: interval of time (in seconds) between two measures. If not provided, it will be automatically calculated.\r\n* `i_max`: the maximum absolute value of the integral term (optional)\r\n\r\n## Test\r\n\r\n```js\r\nmocha test\r\n```\r\n\r\n## Author\r\n\r\nPhilmod \u0026lt;philippe.modard@gmail.com\u0026gt;\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilmod%2Fnode-pid-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilmod%2Fnode-pid-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilmod%2Fnode-pid-controller/lists"}