00001
00010 #include "jwalkincludes.h"
00011 #include "sensors.h"
00012 #ifndef PIDCONTROLLER_H
00013 #define PIDCONTROLLER_H
00014
00015 #define PIDCONTROLLER_DEBUG 1
00016
00017 class PIDController
00018 {
00019 public:
00020 PIDController(std::string name, float Kp, float Ki, float Kd, float period, float outputlowerlimit, float outputupperlimit);
00021 ~PIDController();
00022
00023 float doControl(float input);
00024 void setTarget(float target);
00025
00026 void clearState();
00027
00028 private:
00029 std::string name;
00030
00031
00032 float Kp, Ki, Kd;
00033 float period;
00034 float outputupperlimit, outputlowerlimit;
00035 float d_constant, a_constant;
00036
00037
00038 float target;
00039 float error, previouserror;
00040 float proportional, previousproportional;
00041 double integral, previousintegral;
00042 float derivative, previousderivative;
00043
00044 float limitOutput(float unlimitedoutput);
00045
00046 #if PIDCONTROLLER_DEBUG > 0
00047 ofstream pidLog;
00048 #endif
00049 };
00050
00051
00052 #endif