From 028bf42b1260366254fdb1a3b03a9b0e5b96412b Mon Sep 17 00:00:00 2001 From: Majid Derhambakhsh Date: Tue, 22 Jun 2021 22:00:23 +0430 Subject: [PATCH] Update README.md --- README.md | 86 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 0a66466..e9cc74f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ PID Controller library for ARM Cortex M (STM32) > #### Download Arduino Library : [Arduino-PID-Library](https://github.com/br3ttb/Arduino-PID-Library) -### Version : 1.0.0 +## Release +- #### Version : 1.0.0 - #### Type : Embedded Software. @@ -21,13 +22,14 @@ PID Controller library for ARM Cortex M (STM32) - #### Required Library/Driver : +## Overview ### Initialization and de-initialization functions: ```c++ void PID(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, double Kp, double Ki, double Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection); void PID2(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, double Kp, double Ki, double Kd, PIDCD_TypeDef ControllerDirection); ``` -### PID operation functions: +### Operation functions: ```c++ /* ::::::::::: Computing ::::::::::: */ uint8_t PID_Compute(PID_TypeDef *uPID); @@ -57,33 +59,67 @@ double PID_GetKd(PID_TypeDef *uPID); ``` ### Macros: +```diff +non +``` + +## Guide + +#### This library can be used as follows: +#### 1. Add pid.h header +#### 2. Create PID struct and initialize it, for example: +* Initializer: + ```c++ + PID(PID_TypeDef *uPID, double *Input, double *Output, double *Setpoint, double Kp, double Ki, double Kd, PIDPON_TypeDef POn, PIDCD_TypeDef ControllerDirection); + ``` +* Parameters: + * uPID : Pointer to pid struct + * Input : The variable we're trying to control (double) + * Output : The variable that will be adjusted by the pid (double) + * Setpoint : The value we want to Input to maintain (double) + * Kp,Ki,Kd : Tuning Parameters. these affect how the pid will change the output (double>=0) + * POn : Either P_ON_E (Default) or P_ON_M. Allows Proportional on Measurement to be specified. + * ControllerDirection : Either DIRECT or REVERSE. determines which direction the output will move when faced with a given error. DIRECT is most common + + +* Example: + ```c++ + PID_TypeDef TPID; + + double Temp, PIDOut, TempSetpoint; -## How to use this library - -### The PID library can be used as follows: -1.1 Add pid.h header - -2.1 Initialize: - -```c++ -PID_TypeDef TPID; - -double Temp, PIDOut, TempSetpoint; - -PID(&TPID, &Temp, &PIDOut, &TempSetpoint, 2, 5, 1, _PID_P_ON_E, _PID_CD_DIRECT); - -PID_SetMode(&TPID, _PID_MODE_AUTOMATIC); -PID_SetSampleTime(&TPID, 500); -PID_SetOutputLimits(&TPID, 1, 100); -``` - -3.1 Using Compute function, for example: + PID(&TPID, &Temp, &PIDOut, &TempSetpoint, 2, 5, 1, _PID_P_ON_E, _PID_CD_DIRECT); + ``` +#### 3. Set 'mode', 'sample time' and 'output limit', for example: +* Functions: + ```c++ + void PID_SetMode(PID_TypeDef *uPID, PIDMode_TypeDef Mode); + void PID_SetOutputLimits(PID_TypeDef *uPID, double Min, double Max); + void PID_SetSampleTime(PID_TypeDef *uPID, int32_t NewSampleTime); + ``` +* Parameters: + * uPID : Pointer to pid struct + * Mode : _PID_MODE_AUTOMATIC or _PID_MODE_MANUAL + * Min : Low end of the range. must be < max (double) + * Max : High end of the range. must be > min (double) + * NewSampleTime : How often, in milliseconds, the PID will be evaluated. (int>0) + +* Example: + ```c++ + PID_SetMode(&TPID, _PID_MODE_AUTOMATIC); + PID_SetSampleTime(&TPID, 500); + PID_SetOutputLimits(&TPID, 1, 100); + ``` + +#### 4. Using Compute function, for example: ```c++ PID_Compute(&TPID); ``` -##### Example 1: +## Examples + +#### Example 1: PID Compute for temperature ```c++ #include "main.h" #include "pid.h" @@ -121,8 +157,8 @@ int main(void) ``` ## Tests performed: -- [ ] Run on AVR - [x] Run on STM32 Fx cores -#### Developer: Majid Derhambakhsh +## Developers: +- ### Majid Derhambakhsh