forked from WPIRoboticsEngineering/RBE2002_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRBEPID.cpp
55 lines (48 loc) · 1.11 KB
/
RBEPID.cpp
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
/*
* Messages.h
*
* Created on: 10/1/16
* Author: joest
*/
#include "Arduino.h"
#include "RBEPID.h"
//Class constructor
RBEPID::RBEPID() {
}
//Function to set PID gain values
void RBEPID::setpid(float P, float I, float D) {
kp = P;
ki = I;
kd = D;
}
/**
* calc the PID control signel
*
* @param setPoint is the setpoint of the PID system
* @param curPosition the current position of the plan
* @return a value from -1.0 to 1.0 representing the PID control signel
*/
float RBEPID::calc(double setPoint, double curPosition) {
// calculate error
float err = setPoint - curPosition;
// calculate derivative of error
//TODO
// calculate integral error. Running average is best but hard to implement
//TODO
// sum up the error value to send to the motor based off gain values.
//TODO
float out = err * kp; // simple P controller
//return the control signal from -1 to 1
if (out > 1)
out = 1;
if (out < -1)
out = -1;
return out;
}
/**
* Clear the internal representation fo the integral term.
*
*/
void RBEPID::clearIntegralBuffer() {
//TODO implement this when implementing the integral term
}