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.cpp@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 | #include "pid.h" |
ahmedallibhoy | 1:45f1f67eab62 | 2 | |
ahmedallibhoy | 1:45f1f67eab62 | 3 | void PIDController::onLoop() |
ahmedallibhoy | 1:45f1f67eab62 | 4 | { |
ahmedallibhoy | 1:45f1f67eab62 | 5 | float error = (m_error)(); |
ahmedallibhoy | 1:45f1f67eab62 | 6 | (m_out)(m_Kp * error + m_Ki * iController(error) + m_Kd * dController(error)); |
ahmedallibhoy | 1:45f1f67eab62 | 7 | wait(m_dt); |
ahmedallibhoy | 1:45f1f67eab62 | 8 | } |
ahmedallibhoy | 1:45f1f67eab62 | 9 | |
ahmedallibhoy | 1:45f1f67eab62 | 10 | float PIDController::iController(float error) |
ahmedallibhoy | 1:45f1f67eab62 | 11 | { |
ahmedallibhoy | 1:45f1f67eab62 | 12 | m_integral += error; |
ahmedallibhoy | 1:45f1f67eab62 | 13 | return m_integral; |
ahmedallibhoy | 1:45f1f67eab62 | 14 | } |
ahmedallibhoy | 1:45f1f67eab62 | 15 | |
ahmedallibhoy | 1:45f1f67eab62 | 16 | float PIDController::dController(float error) |
ahmedallibhoy | 1:45f1f67eab62 | 17 | { |
ahmedallibhoy | 1:45f1f67eab62 | 18 | float derivative = error - m_pError; |
ahmedallibhoy | 1:45f1f67eab62 | 19 | m_pError = error; |
ahmedallibhoy | 1:45f1f67eab62 | 20 | return derivative; |
ahmedallibhoy | 1:45f1f67eab62 | 21 | } |
ahmedallibhoy | 1:45f1f67eab62 | 22 | |
ahmedallibhoy | 1:45f1f67eab62 | 23 | void PIDController::reset() |
ahmedallibhoy | 1:45f1f67eab62 | 24 | { |
ahmedallibhoy | 1:45f1f67eab62 | 25 | m_integral = 0; |
ahmedallibhoy | 1:45f1f67eab62 | 26 | } |