wpi-32u4-library
src
PIDcontroller.cpp
Go to the documentation of this file.
1
#include <
PIDcontroller.h
>
2
#include <math.h>
3
8
float
PIDController::calcEffort
(
float
error)
9
{
10
currError
= error;
//store in case we want it later
11
sumError
+=
currError
;
12
13
if
(
errorBound
> 0)
//cap error; errorBound == 0 means don't cap
14
{
15
if
(fabs(
sumError
) >
errorBound
)
16
{
17
sumError
-=
currError
;
//if we exceeded the limit, just subtract it off again
18
}
19
}
20
21
float
derivError =
currError
-
prevError
;
22
prevError
=
currError
;
23
24
currEffort
=
Kp
*
currError
+
Ki
*
sumError
+
Kd
* derivError;
25
26
return
currEffort
;
27
}
PIDcontroller.h
PIDController::Kd
float Kd
Definition:
PIDcontroller.h:12
PIDController::currError
float currError
Definition:
PIDcontroller.h:13
PIDController::currEffort
float currEffort
Definition:
PIDcontroller.h:21
PIDController::Kp
float Kp
Definition:
PIDcontroller.h:12
PIDController::sumError
float sumError
Definition:
PIDcontroller.h:16
PIDController::calcEffort
float calcEffort(float error)
Used to calculate the effort from the error.
Definition:
PIDcontroller.cpp:8
PIDController::Ki
float Ki
Definition:
PIDcontroller.h:12
PIDController::prevError
float prevError
Definition:
PIDcontroller.h:14
PIDController::errorBound
float errorBound
Definition:
PIDcontroller.h:17
Generated by
1.9.3