8#ifndef DEF_PidController_H
9#define DEF_PidController_H
37 const double MAX_INT_POWER;
38 const double INTERVAL_S;
47 PidController(
double kPro,
double kInt,
double kDif,
unsigned long callInterval_us,
double maxIntPower = 1023.0) noexcept
48 : constant{ kPro, kInt, kDif }
52 , MAX_INT_POWER(maxIntPower)
53 , INTERVAL_S(callInterval_us / 1000000.0)
61 void update(
double controlValue,
double targetValue)
noexcept
64 const auto coefficient = requestConstant ? *requestConstant : constant;
65 requestConstant.
reset();
68 const double error = targetValue - controlValue;
71 power.
p = coefficient.p * error;
74 power.
i += coefficient.i * error * INTERVAL_S;
78 power.
d = coefficient.d * (error - lastError) / INTERVAL_S;
88 return power.
p + power.
i + power.
d;
95 double getPower(
double min,
double max)
const noexcept
104 double operator()(
double controlValue,
double targetValue)
noexcept
106 update(controlValue, targetValue);
116 double operator()(
double controlValue,
double targetValue,
double min,
double max)
noexcept
118 update(controlValue, targetValue);
139 requestConstant->p = value;
143 requestConstant =
Parameter{ value, constant.
i, constant.
d };
153 requestConstant->i = value;
157 requestConstant =
Parameter{ constant.
p, value, constant.
d };
167 requestConstant->d = value;
171 requestConstant =
Parameter{ constant.
p, constant.
i, value };
オプショナル型
Definition Optional.hpp:62
void reset() noexcept(std::is_nothrow_destructible< ValueType >::value)
無効状態にする (トリビアルな型)
Definition Optional.hpp:457
PID制御器
Definition PidController.hpp:19
double operator()(double controlValue, double targetValue, double min, double max) noexcept
更新、操作量の取得
Definition PidController.hpp:116
void clearIntegral() noexcept
Definition PidController.hpp:129
double getPowerPro() const noexcept
比例量の取得
Definition PidController.hpp:213
double getPower() const noexcept
操作量の取得
Definition PidController.hpp:86
PidController(double kPro, double kInt, double kDif, unsigned long callInterval_us, double maxIntPower=1023.0) noexcept
コンストラクタ
Definition PidController.hpp:47
double getPowerDif() const noexcept
微分量の取得
Definition PidController.hpp:221
void setParamInt(double value) noexcept
積分係数の設定
Definition PidController.hpp:185
void setParamDif(double value) noexcept
微分係数の設定
Definition PidController.hpp:189
const Parameter & getParam() const noexcept
係数の取得
Definition PidController.hpp:209
void update(double controlValue, double targetValue) noexcept
データ更新
Definition PidController.hpp:61
void setParamPro(double value) noexcept
比例係数の設定
Definition PidController.hpp:181
double getParamDif() const noexcept
微分係数の取得
Definition PidController.hpp:205
double getPowerInt() const noexcept
積分量の取得
Definition PidController.hpp:217
void setParam(const Parameter &value) noexcept
係数の設定
Definition PidController.hpp:193
void requestParamPro(double value) noexcept
一周期のみ適用する比例係数の設定
Definition PidController.hpp:135
double operator()(double controlValue, double targetValue) noexcept
更新、操作量の取得
Definition PidController.hpp:104
void requestParamDif(double value) noexcept
一周期のみ適用する微分係数の設定
Definition PidController.hpp:163
double getPower(double min, double max) const noexcept
操作量の取得
Definition PidController.hpp:95
void clearPower() noexcept
操作量のクリア
Definition PidController.hpp:124
void requestParam(const Parameter &value) noexcept
一周期のみ適用する係数の設定
Definition PidController.hpp:177
void requestParamInt(double value) noexcept
一周期のみ適用する積分係数の設定
Definition PidController.hpp:149
double getParamPro() const noexcept
比例係数の取得
Definition PidController.hpp:197
double getParamInt() const noexcept
積分係数の取得
Definition PidController.hpp:201
constexpr A Constrain(const A &amt, const B &low, const C &high)
値を指定された範囲内に収める (std::clamp)
Definition Math.hpp:68
Definition PidController.hpp:22
double d
Definition PidController.hpp:25
double i
Definition PidController.hpp:24
double p
Definition PidController.hpp:23