{"id":23888445,"url":"https://github.com/usmanmehmood55/pid_controller","last_synced_at":"2025-07-17T14:33:43.661Z","repository":{"id":153230921,"uuid":"628367036","full_name":"usmanmehmood55/pid_controller","owner":"usmanmehmood55","description":"This is an implementation of a PID controller in C","archived":false,"fork":false,"pushed_at":"2023-04-30T07:44:10.000Z","size":38,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T04:41:43.889Z","etag":null,"topics":["c","control-systems","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/usmanmehmood55.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":"2023-04-15T18:14:15.000Z","updated_at":"2024-06-12T06:09:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"2c3e60b9-6d7a-4007-967e-e9fea3bf427a","html_url":"https://github.com/usmanmehmood55/pid_controller","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/usmanmehmood55/pid_controller","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fpid_controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fpid_controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fpid_controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fpid_controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usmanmehmood55","download_url":"https://codeload.github.com/usmanmehmood55/pid_controller/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usmanmehmood55%2Fpid_controller/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265616989,"owners_count":23798940,"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":["c","control-systems","pid-controller"],"created_at":"2025-01-04T09:00:25.818Z","updated_at":"2025-07-17T14:33:43.644Z","avatar_url":"https://github.com/usmanmehmood55.png","language":"C","readme":"# PID Controller\n\nThis repository contains an implementation of a PID (Proportional-Integral-Differential)\ncontroller in C.\n\nA PID controller is a closed loop control system that is widely used in engineering\napplications for controlling continuous-time dynamic systems. The PID controller\ncalculates an error value as the difference between a measured process variable and a\ndesired set-point, then applies a control action based on proportional, integral, and\nderivative terms (sometimes denoted as P, I, and D respectively) which are designed to\nadjust the output in order to minimize the error over time.\n\nThis code demonstrates a simple PID controller that can be used to control a system that\nis modeled by a mathematical function.\n\n\n## Setup\n\n\n### Pre Requisites\n\nThe required software to use this library are\n- [Git](https://git-scm.com/downloads)\n- [Make](https://gnuwin32.sourceforge.net/packages/make.htm)\n\n\n### Downloading and Compilation\n- Clone this repository using\n  ```bash\n  git clone https://github.com/usmanmehmood55/pid_controller.git\n  ```\n- Initialize the ring_buffer submodule by running\n  ```bash\n  git submodule init\n  git submodule update\n  ```\n- Compile the program by running `make` in the terminal. This will generate an\n  executable file called `pid_controller.exe`.\n  ```bash\n  make\n  ```\n\n\n### Execution\n- Run the executable using\n  ```bash\n  ./pid_controller.exe\n  ```\n\n### Updating\n- Before updating be sure to save any changes that were made to the PID code as they\n  might get overwritten.\n- To get the latest code from this repository, simply `pull` from Git. \n  ```bash\n  git pull\n  ```\n\n\n## Implementation\nAll the PID related code in in [`pid_control.c`](pid_control/pid_control.c) and \n[`pid_control.h`](pid_control/pid_control.h). The PID controller is implemented\nas a struct named `pid_controller_t`. This struct contains the PID weights \n(proportional, integral, and differential response weight constants), the constant\ndata sampling rate, a ring buffer for holding previous errors, a function for giving\ninput to the PID controller, and a function to act as the transfer function of the\nsystem.\n```c\ntypedef struct\n{\n    const double  kP;               // proportional response weight constant\n    const double  kI;               // integral response weight constant\n    const double  kD;               // differential response weight constant\n    const double  time;             // constant data sampling rate in milliseconds\n    const double  goal;             // goal / set-point for PID controller\n    ring_buffer_t * p_error_buffer; // buffer for holding previous errors\n\n    double (*get_input)(double previous_input); // input function's pointer\n    double (*transfer_function)(double input);  // transfer function's pointer\n\n} pid_controller_t;\n```\n\nThe following functions are used for PID computation:\n\n- `proportional`: calculates the proportional response\n- `integral`: calculates the integral response\n- `differential`: calculates the differential response\n- `pid_compute`: calculates the PID response based on those responses\n\nIn the function named `transfer_function`, a mathematical function is used to simulate \na system. The goal is to achieve a certain output value, and the PID controller is used\nto adjust the input value to the system to reach that goal.\n\n```\n+-------+                 +----------------+      +-------------------+              +--------+\n|       |                 |                |      |                   |              |        |\n| input |------\u003e(+)------\u003e| PID controller |-----\u003e| transfer_function |------o------\u003e| output |\n|       |        ^        |                |      |                   |      |       |        |\n+-------+        |        +----------------+      +-------------------+      |       +--------+\n                 |                                                           |\n                 |                                                           |\n                 |                         +-------+                         |\n                 |                         |       |                         |\n                 +-------------------------| error |\u003c------------------------+\n                                           |       |\n                                           +-------+\n```\n\nThe PID weights and other parameters can be adjusted to control the behavior of the system.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusmanmehmood55%2Fpid_controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusmanmehmood55%2Fpid_controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusmanmehmood55%2Fpid_controller/lists"}