{"id":20526314,"url":"https://github.com/powerbroker2/ardupid","last_synced_at":"2025-04-12T11:52:18.905Z","repository":{"id":55067639,"uuid":"398049954","full_name":"PowerBroker2/ArduPID","owner":"PowerBroker2","description":"PID library for Arduinos with greater accuracy than the legacy Arduino PID library","archived":false,"fork":false,"pushed_at":"2025-04-09T01:28:43.000Z","size":31,"stargazers_count":100,"open_issues_count":7,"forks_count":26,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-09T02:28:45.807Z","etag":null,"topics":["control","control-systems","control-theory","controller","pid","pid-control","pid-controller"],"latest_commit_sha":null,"homepage":"","language":"C++","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/PowerBroker2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-08-19T19:13:03.000Z","updated_at":"2025-04-09T01:28:47.000Z","dependencies_parsed_at":"2024-02-08T06:28:15.269Z","dependency_job_id":"460cdbeb-bc9b-4061-ab42-9252e366bcfa","html_url":"https://github.com/PowerBroker2/ArduPID","commit_stats":{"total_commits":25,"total_committers":6,"mean_commits":4.166666666666667,"dds":0.24,"last_synced_commit":"7d29155661e2966b6391609a265f7ba8e190bec2"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerBroker2%2FArduPID","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerBroker2%2FArduPID/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerBroker2%2FArduPID/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerBroker2%2FArduPID/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PowerBroker2","download_url":"https://codeload.github.com/PowerBroker2/ArduPID/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248565021,"owners_count":21125414,"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","pid","pid-control","pid-controller"],"created_at":"2024-11-15T23:13:38.201Z","updated_at":"2025-04-12T11:52:18.885Z","avatar_url":"https://github.com/PowerBroker2.png","language":"C++","readme":"# ArduPID\r\n[![GitHub version](https://badge.fury.io/gh/PowerBroker2%2FArduPID.svg)](https://badge.fury.io/gh/PowerBroker2%2FArduPID) [![arduino-library-badge](https://www.ardu-badge.com/badge/ArduPID.svg?)](https://www.ardu-badge.com/ArduPID)\u003cbr /\u003e\u003cbr /\u003e\r\nPID library for Arduinos with greater accuracy than the legacy Arduino PID library.\r\n\r\n# Why Use PID?\r\nPID stands for Proportional, Integral, and Derivative and is a simple type of controller. PID controllers can provide stable control of nearly any system such as the speed of a motor, position of a servo, speed of a car (cruise control), and much more.\r\n\r\n# How Does it Work?\r\nSee the explanation video [here](https://www.youtube.com/watch?v=OqvrYNJvtaU)\r\n\r\n# How to Tune a PID:\r\nSee [here](https://pidexplained.com/how-to-tune-a-pid-controller/)\r\n\r\n# How to Use the Library:\r\nFirst import the library, instantiate an ArduPID class, and create 6 doubles:\r\n- Setpoint\r\n- Input\r\n- Output\r\n- P Gain\r\n- I Gain\r\n- D Gain\r\n\r\n```C++\r\n#include \"ArduPID.h\"\r\n\r\nArduPID myController;\r\n\r\ndouble setpoint = 512;\r\ndouble input;\r\ndouble output;\r\ndouble p = 1;\r\ndouble i = 0;\r\ndouble d = 0;\r\n```\r\n\r\nNext, within the `setup()` function, initialize the controller with the references to the input, output, and setpoint variables. Also pass the values of the PID gains. After initializing the controller within `setup()`, you can change the settings/configuration of the controller.\r\n\r\n```C++\r\nvoid setup()\r\n{\r\n  Serial.begin(115200);\r\n  myController.begin(\u0026input, \u0026output, \u0026setpoint, p, i, d);\r\n  \r\n  // ADD MORE CONFIGURATION COMMANDS HERE \u003c--------------------\r\n}\r\n```\r\n\r\nHere are the different examples of configuration commands available via the library:\r\n\r\n- `reverse()`\r\n  - Reverse direction of output\r\n- `setSampleTime(const unsigned int\u0026 _minSamplePeriodMs)`\r\n  - Will ensure at least `_minSamplePeriodMs` have past between successful compute() calls - *this function is not necessary, but is included for convenience*\r\n- `setOutputLimits(const double\u0026 min, const double\u0026 max)`\r\n  - Clip output to values to `min` and `max`\r\n- `setBias(const double\u0026 _bias)`\r\n  - Output will have a constant offset of `_bias`, usually used in conjunction with `setOutputLimits()`\r\n- `setWindUpLimits(const double\u0026 min, const double\u0026 max)`\r\n  - Clip integral term values to `min` and `max`to prevent [integral wind-up](https://www.youtube.com/watch?v=H4YlL3rZaNw)\r\n- `start()`\r\n  - Enable/turns on the controller\r\n- `reset()`\r\n  - Used for resetting the I and D terms - *only use this if you know what you're doing*\r\n- `stop()`\r\n  - Disable/turn off the PID controller (`compute()` will not do anything until `start()` is called)\r\n\r\nWithin the `loop()`, update the input variable via your sensor and then call `compute()`. The output variable will then be automatically updated and you can use that updated value to send an updated command to your actuator. You can also use the `debug()` command to print various status information about your controller to the serial plottor/monitor:\r\n\r\n```C++\r\nvoid loop()\r\n{\r\n  input = analogRead(A0); // Replace with sensor feedback\r\n\r\n  myController.compute();\r\n  myController.debug(\u0026Serial, \"myController\", PRINT_INPUT    | // Can include or comment out any of these terms to print\r\n                                              PRINT_OUTPUT   | // in the Serial plotter\r\n                                              PRINT_SETPOINT |\r\n                                              PRINT_BIAS     |\r\n                                              PRINT_P        |\r\n                                              PRINT_I        |\r\n                                              PRINT_D);\r\n  \r\n  analogWrite(3, output); // Replace with plant control signal\r\n}\r\n```\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowerbroker2%2Fardupid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowerbroker2%2Fardupid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowerbroker2%2Fardupid/lists"}