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.cpp
- Revision:
- 1:45f1f67eab62
- Child:
- 4:d59328f14363
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pid.cpp Wed Dec 02 16:47:26 2015 +0000 @@ -0,0 +1,26 @@ +#include "pid.h" + +void PIDController::onLoop() +{ + float error = (m_error)(); + (m_out)(m_Kp * error + m_Ki * iController(error) + m_Kd * dController(error)); + wait(m_dt); +} + +float PIDController::iController(float error) +{ + m_integral += error; + return m_integral; +} + +float PIDController::dController(float error) +{ + float derivative = error - m_pError; + m_pError = error; + return derivative; +} + +void PIDController::reset() +{ + m_integral = 0; +} \ No newline at end of file