-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPID.h
More file actions
64 lines (52 loc) · 934 Bytes
/
PID.h
File metadata and controls
64 lines (52 loc) · 934 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
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
#ifndef PID_h
#define PID_h
class PID {
public:
double error;
double sample;
double lastSample;
double kp, ki, kd;
double p, i, d;
double pid;
double setPoint;
long lastProcess;
PID(double kp, double ki, double kd){
this->kp = kp;
this->ki = ki;
this->kd = kd;
}
void addNewSample(double sample){
this->sample = sample;
}
void setSetPoint(double setPoint){
this->setPoint = setPoint;
}
void setKp(double kp){
this->kp = kp;
}
void setKi(double ki){
this->ki = ki;
}
void setKd(double kd){
this->kd = kd;
}
double getKp(){
return kp;
}
double getKi(){
return ki;
}
double getKd(){
return kd;
}
double process(){
error = setPoint - sample;
p = error * kp;
i = i + (error * ki);
d = (sample - lastSample) * kd ;
lastSample = sample;
pid = p + i + d;
return pid;
}
};
#endif