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
00001 #include "PID.hpp" 00002 PID::PID(double kp,double ki,double kd,double dt) : Kp(kp),Ki(ki),Kd(kd),dt(dt) 00003 { 00004 pwm = 0; 00005 e[0] = 0; 00006 e[1] = 0; 00007 integral = 0; 00008 } 00009 00010 double PID::set(double nowvalue,double tar) 00011 { 00012 e[1] = tar - nowvalue; 00013 integral += (e[0] + e[1]) * dt / 2; 00014 getP = e[1]; 00015 getI = integral; 00016 getD = (e[1] - e[0]) / dt; 00017 pwm += (getP * Kp) + (getI * Ki) + (getD * Kd); 00018 e[0] = e[1]; 00019 return pwm; 00020 } 00021 00022 void PID::safety(double max,double min) 00023 { 00024 pwm >= max ? pwm = max : pwm = pwm; 00025 pwm <= min ? pwm = min : pwm = pwm; 00026 } 00027 00028 void PID::reset() 00029 { 00030 pwm = 0; 00031 } 00032 00033 PID::~PID(){};
Generated on Sat Oct 8 2022 11:15:36 by
1.7.2