明石高専ロボ研 mbedライブラリ

Dependencies:   mbed

Committer:
darkumatar
Date:
Sat Mar 05 05:00:50 2022 +0000
Revision:
14:7ea663f79c81
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darkumatar 14:7ea663f79c81 1
darkumatar 14:7ea663f79c81 2
darkumatar 14:7ea663f79c81 3 class pid{
darkumatar 14:7ea663f79c81 4 public:
darkumatar 14:7ea663f79c81 5 pid(double kp,double ki,double kd,int pulse,double interval_s);
darkumatar 14:7ea663f79c81 6 private:
darkumatar 14:7ea663f79c81 7 double pidanswer(int target,int now_pulse);
darkumatar 14:7ea663f79c81 8 double integral=0.0;
darkumatar 14:7ea663f79c81 9 double ca=0.0;
darkumatar 14:7ea663f79c81 10 int before_pulse=0;
darkumatar 14:7ea663f79c81 11 }
darkumatar 14:7ea663f79c81 12
darkumatar 14:7ea663f79c81 13 double pidanswer(int target,int now_pulse){
darkumatar 14:7ea663f79c81 14 integral+=((((target-now_puls)+before_pulse)*interval_s)/2.0)
darkumatar 14:7ea663f79c81 15 double p=kp*(target-now_puls);
darkumatar 14:7ea663f79c81 16 double d=kd*(((target-now_puls)-before_pulse)/interval_s);
darkumatar 14:7ea663f79c81 17 double i=ki*integral;
darkumatar 14:7ea663f79c81 18 ca=ca+p+i+d;
darkumatar 14:7ea663f79c81 19 before_pulse=now_pluse;
darkumatar 14:7ea663f79c81 20 return ca;
darkumatar 14:7ea663f79c81 21 }