5#ifndef DEF_SpeedPidController_H
6#define DEF_SpeedPidController_H
35 const double MAX_POWER;
36 const double INTERVAL_S;
45 unsigned long callInterval_us,
46 double maxPower = 10000) noexcept
47 : constant{ kPro, kInt, kDif }
55 , INTERVAL_S(callInterval_us / 1000000.0)
63 void update(
double controlValue,
double targetValue)
noexcept
66 const auto coefficient = requestConstant ? *requestConstant : constant;
67 requestConstant.
reset();
70 const double error = targetValue - controlValue;
73 power.
p = (error - lastError) / INTERVAL_S * coefficient.p;
76 power.
i = error * coefficient.i;
79 power.
d = (power.
p - lastPowerPro) / INTERVAL_S;
82 rowPassDif += (power.
d - rowPassDif) / 8 * coefficient.d;
84 const double deltaPower = power.
p + power.
i + rowPassDif;
89 lastPowerPro = power.
p;
104 double getPower(
double min,
double max)
const noexcept
113 double operator()(
double controlValue,
double targetValue)
noexcept
115 update(controlValue, targetValue);
125 double operator()(
double controlValue,
double targetValue,
double min,
128 update(controlValue, targetValue);
148 requestConstant->p = value;
152 requestConstant =
Parameter{ value, constant.
i, constant.
d };
162 requestConstant->i = value;
166 requestConstant =
Parameter{ constant.
p, value, constant.
d };
176 requestConstant->d = value;
180 requestConstant =
Parameter{ constant.
p, constant.
i, value };
188 requestConstant = value;
オプショナル型
Definition Optional.hpp:62
void reset() noexcept(std::is_nothrow_destructible< ValueType >::value)
無効状態にする (トリビアルな型)
Definition Optional.hpp:491
速度型PID制御器
Definition SpeedPid.hpp:15
double getPowerInt() const noexcept
積分量の取得
Definition SpeedPid.hpp:229
void requestParamDif(double value) noexcept
一周期のみ適用する微分係数の設定
Definition SpeedPid.hpp:172
double getPowerDif() const noexcept
微分量の取得
Definition SpeedPid.hpp:233
void requestParam(const Parameter &value) noexcept
一周期のみ適用する係数の設定
Definition SpeedPid.hpp:186
void clearPower() noexcept
操作量のクリア
Definition SpeedPid.hpp:134
SpeedPidController(double kPro, double kInt, double kDif, unsigned long callInterval_us, double maxPower=10000) noexcept
コンストラクタ
Definition SpeedPid.hpp:44
const Parameter & getParam() const noexcept
係数の取得
Definition SpeedPid.hpp:221
double getParamPro() const noexcept
比例係数の取得
Definition SpeedPid.hpp:209
double operator()(double controlValue, double targetValue) noexcept
更新、操作量の取得
Definition SpeedPid.hpp:113
void setParamPro(double value) noexcept
比例係数の設定
Definition SpeedPid.hpp:193
void requestParamInt(double value) noexcept
一周期のみ適用する積分係数の設定
Definition SpeedPid.hpp:158
double getPowerPro() const noexcept
比例量の取得
Definition SpeedPid.hpp:225
double getParamInt() const noexcept
積分係数の取得
Definition SpeedPid.hpp:213
double operator()(double controlValue, double targetValue, double min, double max) noexcept
更新、操作量の取得
Definition SpeedPid.hpp:125
double getPower() const noexcept
操作量の取得
Definition SpeedPid.hpp:95
void update(double controlValue, double targetValue) noexcept
データ更新
Definition SpeedPid.hpp:63
void setParam(const Parameter &value) noexcept
係数の設定
Definition SpeedPid.hpp:205
void requestParamPro(double value) noexcept
一周期のみ適用する比例係数の設定
Definition SpeedPid.hpp:144
double getPower(double min, double max) const noexcept
操作量の取得
Definition SpeedPid.hpp:104
void setParamInt(double value) noexcept
積分係数の設定
Definition SpeedPid.hpp:197
void setParamDif(double value) noexcept
微分係数の設定
Definition SpeedPid.hpp:201
double getParamDif() const noexcept
微分係数の取得
Definition SpeedPid.hpp:217
constexpr A Constrain(const A &amt, const B &low, const C &high)
値を指定された範囲内に収める (std::clamp)
Definition Math.hpp:68
Definition SpeedPid.hpp:18
double d
Definition SpeedPid.hpp:21
double p
Definition SpeedPid.hpp:19
double i
Definition SpeedPid.hpp:20