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

Dependencies:   mbed

pid.h

Committer:
darkumatar
Date:
2022-03-05
Revision:
14:7ea663f79c81

File content as of revision 14:7ea663f79c81:



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;
}