Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: pid.h
- Revision:
- 4:d59328f14363
- Parent:
- 1:45f1f67eab62
- Child:
- 5:0975b797bf54
--- a/pid.h Fri Dec 04 05:07:51 2015 +0000 +++ b/pid.h Fri Dec 04 05:12:57 2015 +0000 @@ -1,36 +1,70 @@ +//#ifndef PID_H +//#define PID_H +// +//#include "mbed.h" +// +//class PIDController +//{ +//public: +// PIDController(void (*output)(float), float (*error)(void), +// float Kp, float Ki, float Kd, +// float dt = .1) : +// m_Kp(Kp), m_Ki(Ki), m_Kd(Kd), +// m_dt(dt), m_integral(0), m_pError(0) +// { +// m_out = output; +// m_error = error; +// }; +// +// void onLoop(); +// void reset(); +//private: +// float iController(float error); +// float dController(float error); +// +// float m_integral; +// float m_pError; +// +// float m_dt; +// +// float m_Kp, m_Ki, m_Kd; +// void (*m_out)(float); +// float (*m_error)(void); +//}; +// +// + + #ifndef PID_H #define PID_H +#include"mbed.h" -#include "mbed.h" -class PIDController -{ -public: - PIDController(void (*output)(float), float (*error)(void), - float Kp, float Ki, float Kd, - float dt = .1) : - m_Kp(Kp), m_Ki(Ki), m_Kd(Kd), - m_dt(dt), m_integral(0), m_pError(0) - { - m_out = output; - m_error = error; - }; +class ctrl{ + public: - void onLoop(); - void reset(); -private: - float iController(float error); - float dController(float error); - - float m_integral; - float m_pError; + void setKp(double num); + void setKi(double num); + void setKd(double num); + void setprevErr(double num); + void setErr(double num); + void setCorrection(double num); + double pctrl(); + double ictrl(); + double dctrl(); + double total(); + void adjust(double xSpeed,double ySpeed,double k1, double k2); - float m_dt; - - float m_Kp, m_Ki, m_Kd; - void (*m_out)(float); - float (*m_error)(void); + private: + double error; + double ki; + double kd; + double kp; + double prevErr; + double correction; + double doubleegrater; + double decay; + }; - -#endif //PID_H \ No newline at end of file +#endif //PID_H