-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPID.c
More file actions
30 lines (25 loc) · 739 Bytes
/
PID.c
File metadata and controls
30 lines (25 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* PID.c
*
* Created: 2017/7/28 下午 8:24:05
* Author: schummacher
*/
#include "PID.h"
int16_t IncPIDCalc(int16_t NextPoint, PID *sptr)
{
int16_t iError, iIncpid;
iError = sptr->SetPoint - NextPoint;
iIncpid = sptr->Proportion * iError - sptr->Integral * sptr->LastError + sptr->Derivative * sptr->PrevError;
sptr->PrevError = sptr->LastError;
sptr->LastError = iError;
return(iIncpid);
}
int16_t LocPIDCalc(int16_t NextPoint, PID *sptr)
{
int16_t iError, dError;
iError = sptr->SetPoint - NextPoint;
sptr->SumError += iError;
dError = iError - sptr->LastError;
sptr->LastError = iError;
return(sptr->Proportion * iError + sptr->Integral * sptr->SumError + sptr->Derivative * dError); //微分项
}