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.
pid.h@1:45f1f67eab62, 2015-12-02 (annotated)
- Committer:
- ahmedallibhoy
- Date:
- Wed Dec 02 16:47:26 2015 +0000
- Revision:
- 1:45f1f67eab62
- Child:
- 4:d59328f14363
updates;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ahmedallibhoy | 1:45f1f67eab62 | 1 | #ifndef PID_H |
ahmedallibhoy | 1:45f1f67eab62 | 2 | #define PID_H |
ahmedallibhoy | 1:45f1f67eab62 | 3 | |
ahmedallibhoy | 1:45f1f67eab62 | 4 | #include "mbed.h" |
ahmedallibhoy | 1:45f1f67eab62 | 5 | |
ahmedallibhoy | 1:45f1f67eab62 | 6 | class PIDController |
ahmedallibhoy | 1:45f1f67eab62 | 7 | { |
ahmedallibhoy | 1:45f1f67eab62 | 8 | public: |
ahmedallibhoy | 1:45f1f67eab62 | 9 | PIDController(void (*output)(float), float (*error)(void), |
ahmedallibhoy | 1:45f1f67eab62 | 10 | float Kp, float Ki, float Kd, |
ahmedallibhoy | 1:45f1f67eab62 | 11 | float dt = .1) : |
ahmedallibhoy | 1:45f1f67eab62 | 12 | m_Kp(Kp), m_Ki(Ki), m_Kd(Kd), |
ahmedallibhoy | 1:45f1f67eab62 | 13 | m_dt(dt), m_integral(0), m_pError(0) |
ahmedallibhoy | 1:45f1f67eab62 | 14 | { |
ahmedallibhoy | 1:45f1f67eab62 | 15 | m_out = output; |
ahmedallibhoy | 1:45f1f67eab62 | 16 | m_error = error; |
ahmedallibhoy | 1:45f1f67eab62 | 17 | }; |
ahmedallibhoy | 1:45f1f67eab62 | 18 | |
ahmedallibhoy | 1:45f1f67eab62 | 19 | void onLoop(); |
ahmedallibhoy | 1:45f1f67eab62 | 20 | void reset(); |
ahmedallibhoy | 1:45f1f67eab62 | 21 | private: |
ahmedallibhoy | 1:45f1f67eab62 | 22 | float iController(float error); |
ahmedallibhoy | 1:45f1f67eab62 | 23 | float dController(float error); |
ahmedallibhoy | 1:45f1f67eab62 | 24 | |
ahmedallibhoy | 1:45f1f67eab62 | 25 | float m_integral; |
ahmedallibhoy | 1:45f1f67eab62 | 26 | float m_pError; |
ahmedallibhoy | 1:45f1f67eab62 | 27 | |
ahmedallibhoy | 1:45f1f67eab62 | 28 | float m_dt; |
ahmedallibhoy | 1:45f1f67eab62 | 29 | |
ahmedallibhoy | 1:45f1f67eab62 | 30 | float m_Kp, m_Ki, m_Kd; |
ahmedallibhoy | 1:45f1f67eab62 | 31 | void (*m_out)(float); |
ahmedallibhoy | 1:45f1f67eab62 | 32 | float (*m_error)(void); |
ahmedallibhoy | 1:45f1f67eab62 | 33 | }; |
ahmedallibhoy | 1:45f1f67eab62 | 34 | |
ahmedallibhoy | 1:45f1f67eab62 | 35 | |
ahmedallibhoy | 1:45f1f67eab62 | 36 | #endif //PID_H |