Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Majid-Derhambakhsh authored Jun 22, 2021
1 parent 3d37002 commit 028bf42
Showing 1 changed file with 61 additions and 25 deletions.
86 changes: 61 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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);
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -121,8 +157,8 @@ int main(void)
```

## Tests performed:
- [ ] Run on AVR
- [x] Run on STM32 Fx cores

#### Developer: Majid Derhambakhsh
## Developers:
- ### Majid Derhambakhsh

0 comments on commit 028bf42

Please sign in to comment.