明石高専ロボ研 mbedライブラリ
Dependencies: mbed
Revision 14:7ea663f79c81, committed 2022-03-05
- Comitter:
- darkumatar
- Date:
- Sat Mar 05 05:00:50 2022 +0000
- Parent:
- 13:77c13e86ad12
- Commit message:
- a
Changed in this revision
pid.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 77c13e86ad12 -r 7ea663f79c81 pid.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pid.h Sat Mar 05 05:00:50 2022 +0000 @@ -0,0 +1,21 @@ + + +class pid{ +public: +pid(double kp,double ki,double kd,int pulse,double interval_s); +private: +double pidanswer(int target,int now_pulse); +double integral=0.0; +double ca=0.0; +int before_pulse=0; +} + +double pidanswer(int target,int now_pulse){ + integral+=((((target-now_puls)+before_pulse)*interval_s)/2.0) + double p=kp*(target-now_puls); + double d=kd*(((target-now_puls)-before_pulse)/interval_s); + double i=ki*integral; + ca=ca+p+i+d; + before_pulse=now_pluse; + return ca; +} \ No newline at end of file