etrobocon2019 feat.KatLab  ece30a9a007fff7d3ad48592c0d09a74643377bb
TurnControl.cpp
[詳解]
1 
6 #include "TurnControl.h"
7 
15 TurnControl::TurnControl(int targetBrightness, double Kp, double Ki, double Kd)
16  : filter(), pid(static_cast<double>(targetBrightness), Kp, Ki, Kd)
17 {
18 }
19 
30 double TurnControl::calculateTurn(int forward, int currentBrightness, int targetBrightness,
31  double Kp, double Ki, double Kd)
32 {
33  double filteredBrightness = filter.lowPassFilter(currentBrightness);
34 
35  // pidの値を更新(パラメータに変更がなくても更新する)
36  pid.setParameter(static_cast<double>(targetBrightness), Kp, Ki, Kd);
37 
38  auto pidValue = pid.control(filteredBrightness);
39 
40  double forwardPercent = forward / 100.0;
41  return pidValue * forwardPercent;
42 }
double calculateTurn(int forward, int currentBrightness, int targetBrightness, double Kp, double Ki, double Kd)
旋回値を計算する関数
Definition: TurnControl.cpp:30
const double setParameter(double target_, double Kp_, double Ki_=0.0, double Kd_=0.0)
目標値とPIDゲインの設定をする関数
Definition: Pid.cpp:58
旋回値制御クラス
TurnControl(int targetBrightness, double Kp, double Ki, double Kd)
Definition: TurnControl.cpp:15
double control(double value, double delta=0.004)
Definition: Pid.cpp:28
double lowPassFilter(T value, double rate=0.9)
ローパスフィルター(現在値と前回値を参考にして値を決定する)
Definition: Filter.cpp:28