-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpid.ino
37 lines (26 loc) · 829 Bytes
/
pid.ino
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
//--------------------------------------------------------
// Evil Minion 5 Axis robot firmware
// 2015 September 3
// see http://evilminion.info/ for more information.
//--------------------------------------------------------
#include "pid.h"
void PID_init(PIDobject &o) {
o.integral=0;
o.last_error=0;
}
float PID_step(PIDobject &o, float wanted,float actual,float dt) {
float error = wanted - actual;
if( fabs(error) > PID_EPSILON ) {
o.integral += error * dt;
}
float derivative = ( error - o.last_error ) / dt;
o.last_error = error;
// Serial.print("P=");
// Serial.print(error);
// Serial.print("I=");
// Serial.print(o.integral);
// Serial.print("D=");
// Serial.println(derivative);
return PID_KP * error + PID_KI * o.integral + PID_KD * derivative;
}