{"id":24993998,"url":"https://github.com/mbedlab/pid-library","last_synced_at":"2025-04-19T23:49:32.447Z","repository":{"id":249831332,"uuid":"379340033","full_name":"mbedlab/PID-Library","owner":"mbedlab","description":"C/C++ PID Controller library for ARM Cortex M (STM32)","archived":false,"fork":false,"pushed_at":"2021-11-27T23:22:07.000Z","size":5568,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-19T23:49:28.909Z","etag":null,"topics":["mbedlab","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/mbedlab.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-06-22T16:50:05.000Z","updated_at":"2024-07-24T09:52:12.000Z","dependencies_parsed_at":"2024-07-23T16:44:10.307Z","dependency_job_id":"1b17d67b-0f7a-4007-bf32-0939ed8d4391","html_url":"https://github.com/mbedlab/PID-Library","commit_stats":null,"previous_names":["mbedlab/pid-library"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbedlab%2FPID-Library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbedlab%2FPID-Library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbedlab%2FPID-Library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbedlab%2FPID-Library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbedlab","download_url":"https://codeload.github.com/mbedlab/PID-Library/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249830846,"owners_count":21331357,"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":["mbedlab","pid-control","pid-controller"],"created_at":"2025-02-04T14:38:07.297Z","updated_at":"2025-04-19T23:49:32.430Z","avatar_url":"https://github.com/mbedlab.png","language":"C++","readme":"![Banner](Banner.png)\n\n# PID-Library (C Version)\nPID Controller library for ARM Cortex M (STM32)\n\n\u003e #### Download Arduino Library : [Arduino-PID-Library](https://github.com/br3ttb/Arduino-PID-Library)  \n\n## Release\n- #### Version : 1.0.0\n\n- #### Type : Embedded Software.\n\n- #### Support :  \n               - ARM STM32 series  \n\n- #### Program Language : C/C++\n\n- #### Properties :\n\n- #### Changes :  \n\n- #### Required Library/Driver :\n\n\n## Overview \n### Initialization and de-initialization functions:\n```c++\nvoid PID(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, double Kp, double Ki, double Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection);\nvoid PID2(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, double Kp, double Ki, double Kd, PIDCD_TypeDef ControllerDirection);\n``` \n\n### Operation functions:\n```c++\n/* ::::::::::: Computing ::::::::::: */\nuint8_t PID_Compute(PID_TypeDef *uPID);\n\n/* ::::::::::: PID Mode :::::::::::: */\nvoid            PID_SetMode(PID_TypeDef *uPID, PIDMode_TypeDef Mode);\nPIDMode_TypeDef PID_GetMode(PID_TypeDef *uPID);\n\n/* :::::::::: PID Limits ::::::::::: */\nvoid PID_SetOutputLimits(PID_TypeDef *uPID, double Min, double Max);\n\n/* :::::::::: PID Tunings :::::::::: */\nvoid PID_SetTunings(PID_TypeDef *uPID, double Kp, double Ki, double Kd);\nvoid PID_SetTunings2(PID_TypeDef *uPID, double Kp, double Ki, double Kd, PIDPON_TypeDef POn);\n\n/* ::::::::: PID Direction ::::::::: */\nvoid          PID_SetControllerDirection(PID_TypeDef *uPID, PIDCD_TypeDef Direction);\nPIDCD_TypeDef PID_GetDirection(PID_TypeDef *uPID);\n\n/* ::::::::: PID Sampling :::::::::: */\nvoid PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime);\n\n/* ::::::: Get Tunings Param ::::::: */\ndouble PID_GetKp(PID_TypeDef *uPID);\ndouble PID_GetKi(PID_TypeDef *uPID);\ndouble PID_GetKd(PID_TypeDef *uPID);\n``` \n\n### Macros:\n```diff  \nnon   \n```\n\n## Guide\n\n#### This library can be used as follows:\n#### 1.  Add pid.h header  \n#### 2.  Create PID struct and initialize it, for example:      \n* Initializer:\n  ```c++\n  PID(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, double Kp, double Ki, double Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection);\n  ``` \n* Parameters:  \n     * uPID : Pointer to pid struct \n     * Input : The variable we're trying to control (double) \n     * Output : The variable that will be adjusted by the pid (double) \n     * Setpoint : The value we want to Input to maintain (double) \n     * Kp,Ki,Kd : Tuning Parameters. these affect how the pid will change the output (double\u003e=0) \n     * POn : Either P_ON_E (Default) or P_ON_M. Allows Proportional on Measurement to be specified.  \n     * ControllerDirection : Either DIRECT or REVERSE. determines which direction the output will move when faced with a given error. DIRECT is most common  \n          \n          \n* Example:\n  ```c++  \n  PID_TypeDef TPID;\n\n  double Temp, PIDOut, TempSetpoint;\n\n  PID(\u0026TPID, \u0026Temp, \u0026PIDOut, \u0026TempSetpoint, 2, 5, 1, _PID_P_ON_E, _PID_CD_DIRECT);\n  ``` \n#### 3.  Set 'mode', 'sample time' and 'output limit', for example:  \n* Functions:\n  ```c++\n  void PID_SetMode(PID_TypeDef *uPID, PIDMode_TypeDef Mode);\n  void PID_SetOutputLimits(PID_TypeDef *uPID, double Min, double Max);\n  void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime);\n  ``` \n* Parameters:  \n     * uPID : Pointer to pid struct \n     * Mode : _PID_MODE_AUTOMATIC or _PID_MODE_MANUAL\n     * Min : Low end of the range. must be \u003c max (double) \n     * Max : High end of the range. must be \u003e min (double) \n     * NewSampleTime : How often, in milliseconds, the PID will be evaluated. (int\u003e0)  \n          \n* Example:\n  ```c++  \n  PID_SetMode(\u0026TPID, _PID_MODE_AUTOMATIC);\n  PID_SetSampleTime(\u0026TPID, 500);\n  PID_SetOutputLimits(\u0026TPID, 1, 100);\n  ``` \n  \n#### 4.  Using Compute function, for example:  \n        \n```c++\nPID_Compute(\u0026TPID);\n```  \n      \n## Examples  \n\n#### Example 1: PID Compute for temperature\n```c++  \n#include \"main.h\"\n#include \"pid.h\"\n\nPID_TypeDef TPID;\n\nchar OutBuf[50];\ndouble Temp, PIDOut, TempSetpoint;\n\nint main(void)\n{\n\t\n  HW_Init();\n  \n  PID(\u0026TPID, \u0026Temp, \u0026PIDOut, \u0026TempSetpoint, 2, 5, 1, _PID_P_ON_E, _PID_CD_DIRECT);\n\t\n  PID_SetMode(\u0026TPID, _PID_MODE_AUTOMATIC);\n  PID_SetSampleTime(\u0026TPID, 500);\n  PID_SetOutputLimits(\u0026TPID, 1, 100);\n  \n    while (1) \n    {\n  \n      Temp = GetTemp();\n      PID_Compute(\u0026TPID);\n      \n      sprintf(OutBuf, \"Temp%3.2f : %u\\n\", Temp, (uint16_t)PIDOut);\n      UART_Transmit((uint8_t *)OutBuf, strlen(OutBuf));\n      \n      Delay_ms(500);\n    \n    }\n}\n   \n``` \n\n## Tests performed:\n- [x] Run on STM32 Fx cores \n\n## Developers: \n- ### Majid Derhambakhsh\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbedlab%2Fpid-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbedlab%2Fpid-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbedlab%2Fpid-library/lists"}