8 PidGain::PidGain(
double Kp_,
double Ki_,
double Kd_) : Kp(Kp_), Ki(Ki_), Kd(Kd_) {}
10 Pid::Pid(
double target_,
double Kp_,
double Ki_,
double Kd_)
11 : target(target_), gain(Kp_, Ki_, Kd_), integral(0.0f), preError(0.0f)
31 double error = target - value;
33 integral += error * delta;
35 double diff = (error - preError) / delta;
41 double p = gain.
Kp * error;
43 double i = gain.
Ki * integral;
45 double d = gain.
Kd * diff;
47 return limit(p + i + d);
86 if(value > 100.0)
return 100.0;
87 if(value < -100.0)
return -100.0;
const double setParameter(double target_, double Kp_, double Ki_=0.0, double Kd_=0.0)
目標値とPIDゲインの設定をする関数
void setPidGain(double Kp_, double Ki_, double Kd_)
double limit(double value)
PidGain(double Kp_, double Ki_, double Kd_)
double control(double value, double delta=0.004)
Pid(double target_, double Kp_, double Ki_=0.0, double Kd_=0.0)
const PidGain & setPidGain(double Kp_, double Ki_=0.0, double Kd_=0.0)
PIDゲインの設定をする関数