wpi-32u4-library
PIDcontroller.h
Go to the documentation of this file.
1#pragma once
2
3#include <Arduino.h>
4
10{
11protected:
12 float Kp, Ki, Kd;
13 float currError = 0;
14 float prevError = 0;
15
16 float sumError = 0;
17 float errorBound = 0;
18
19 float deltaT = 0; //not used for now; could be useful
20
21 float currEffort = 0;
22
23public:
25 PIDController(float p, float i = 0, float d = 0, float bound = 0)
26 : Kp(p), Ki(i), Kd(d), errorBound(bound) {}
27
28 float calcEffort(float error);
29
30 float setKp(float k) {return Kp = k;}
31 float setKi(float k) {sumError = 0; return Ki = k;}
32 float setKd(float k) {return Kd = k;}
33 float setCap(float cap) {return errorBound = cap;}
34 void resetSum(void) {sumError = 0;}
35};
A generic PID controller.
Definition: PIDcontroller.h:10
float setKp(float k)
Definition: PIDcontroller.h:30
void resetSum(void)
Definition: PIDcontroller.h:34
float setKd(float k)
Definition: PIDcontroller.h:32
float calcEffort(float error)
Used to calculate the effort from the error.
PIDController(float p, float i=0, float d=0, float bound=0)
Constructor defaults to proportional only.
Definition: PIDcontroller.h:25
float setCap(float cap)
Definition: PIDcontroller.h:33
float setKi(float k)
Definition: PIDcontroller.h:31