etrobocon2018 feat.KatLab  770af34cce41ae9c30c41303275e1add2daae0c3 (with uncommitted changes)
 全て クラス 名前空間 ファイル 関数 変数 列挙型 列挙値 フレンド マクロ定義 ページ
LPF.cpp
[詳解]
1 #include "LPF.h"
2 
9 float LPF::sensor(std::int32_t current_sensor)
10 {
11  // pre_sensorの初期化
12  if(pre_sensor == 0) {
13  pre_sensor = current_sensor;
14  return static_cast<double>(current_sensor);
15  }
16 
17  // RCフィルタ処理
18  return RCFilter(current_sensor);
19 }
20 
27 float LPF::RCFilter(std::int32_t current_sensor)
28 {
29  // RCフィルタにおける係数(通常、0.8 or 0.9)
30  constexpr double coefficient = 0.9;
31  auto filtered = coefficient * pre_sensor + (1 - coefficient) * current_sensor;
32 
33  // センサ値の上書き
34  pre_sensor = current_sensor;
35 
36  return filtered;
37 }
float RCFilter(std::int32_t current_sensor)
RCフィルタ(ローパスフィルタ)処理
Definition: LPF.cpp:27
float sensor(std::int32_t current_sensor)
現在のセンサ値にフィルタ処理を実行する
Definition: LPF.cpp:9
std::int32_t pre_sensor
Definition: LPF.h:16
LPF(Low-Pass Filter)をまとめたクラス