-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPID.h
More file actions
117 lines (100 loc) · 4.62 KB
/
Copy pathPID.h
File metadata and controls
117 lines (100 loc) · 4.62 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef __PID_H
#define __PID_H
typedef float (*PIDDecayFun)(float);
#define PID_DECAY_FUNC_NULL ((PIDDecayFun)0)
typedef struct PID
{
float Target;
float iSampling;//系统关测值/采样值
float P;
float I;
float D;
float iError;
float LastError;
float PrevError;
float Integral; //Just using in the position type PID.
float F;
float Fmax;
float Fmin;
float dt;
float Step;
float sysArg;//因为这个值会用于每次反馈中系统参数的更新,所以可能选择直接用得到的调制度去乘以一个整数。
PIDDecayFun pidDecayByAbsErrorFunc; //PID参数随误差减小而减小的衰减函数,为NULL时表明不使用衰减。
} PID, *pPID;
void IncPIDInit(pPID self);
/**
* @brief Position type PID. Have no decay function.
* @return None
*/
void PosPIDCalc_NormalizedF(pPID self);
/**
* @brief incremental PID. Have no decay function.
* when Target minus SamplingValue equals is negitive,the Normalizedized
system parameter, F , will increase, and if Target minus SamplingValue
equals is positive, then F will decrease.
--> Target > iSampling -> F ↑, Target < iSampling -> F ↓
* @return None
*/
void IncPIDCalc_NormalizedF(pPID self);
/**
* @brief incremental PID. Have no decay function.
* 1. When Target minus SamplingValue equals is negitive,the Normalizedized
* system parameter, F , will increase, and if Target minus SamplingValue
* equals is positive, then F will decrease.
* 2. And the P,I,D parameter will multiply by FirstContrlScale when
* LasttContrlPoint < absError < FirstContrlPoint.
* 3. --> Target > iSampling -> F ↑, Target < iSampling -> F ↓
* @return None
*/
void IncPIDCalcDelta_NormalizedF_TwoStage(pPID self, float FirstContrlPoint, float LasttContrlPoint, float FirstContrlScale);
/**
* @brief incremental PID. F is normalized modulation degree. PID parameter decay
* function input is error.
* 1. When Target minus SamplingValue equals is negitive,the Normalizedized
* system parameter, F , will increase, and if Target minus SamplingValue
* equals is positive, then F will decrease.
* 2. And the P,I,D parameter will multiply by decayfun(iError).
* 3. --> Target > iSampling -> F ↑, Target < iSampling -> F ↓
* @return None
* @note please sure the deacyfun is not NULL.
*/
void IncPIDCalcDelta_NormalizedF_Decay(pPID self,PIDDecayFun deacyfun);
/**
* @brief incremental PID. F is normalized modulation degree. PID parameter decay
* function input is normalized error.deacyfun(self->iError / self->sysArg).
* Not recommend to use this function.Beacuse
* the self->sysArg is system's modulation degree max, not the system's output max.
* 1. When Target minus SamplingValue equals is negitive,the Normalizedized
* system parameter, F , will increase, and if Target minus SamplingValue
* equals is positive, then F will decrease.
* 2. And the P,I,D parameter will multiply by decayfun(iError).
* 3. --> Target > iSampling -> F ↑, Target < iSampling -> F ↓
* 4. self->iError Normalizedized.
* @return None
* @note please sure the deacyfun is not NULL.
*/
void IncPIDCalcDelta_NormalizedFAndDecayFunInput_Decay(pPID self,PIDDecayFun deacyfun);
/**
* @brief incremental PID. F is normalized modulation degree. PID parameter decay
* function input is normalized error.The PID.pidDecayByAbsErrorFunc need to
* be choose by yourself.If PID.pidDecayByAbsErrorFunc is NULL, then PID parameter
* will not decay.Recommend to use this function.
* 1. When Target minus SamplingValue equals is negitive,the Normalizedized
* system parameter, F , will increase, and if Target minus SamplingValue
* equals is positive, then F will decrease.
* 2. And the P,I,D parameter will multiply by decayfun(iError).
* 3. --> Target > iSampling -> F ↑, Target < iSampling -> F ↓
* 4. self->iError Normalizedized.
* @return None
*/
void IncPIDCalcDeltaAutoDecay(pPID self);
#define PIDUpdateValue_P(self) ((self)->sysArg * (self)->F)
#define PIDUpdateValue_N(self) ((self)->sysArg * (1.0f - (self)->F))
#define PIDSetSampleValue(self,value) ((self)->iSampling = (value))
float dsigmoidn(float z,float a);
float sigmoidabsx(float z,float a,float b);
float tanhabsx(float z,float a);
float px1(float z,float a);
float obliquestepfun(float z,float x);
void UserPIDInit(void);
#endif