8#ifndef DEF_PidController_H
9#define DEF_PidController_H
38 const double MAX_INT_POWER;
39 const double INTERVAL_S;
48 PidController(
double kPro,
double kInt,
double kDif,
unsigned long callInterval_us,
double maxIntPower = 1023.0) noexcept
49 : constant{ kPro, kInt, kDif }
53 , MAX_INT_POWER(maxIntPower)
54 , INTERVAL_S(callInterval_us / 1000000.0)
62 void update(
double controlValue,
double targetValue)
noexcept
65 const auto coefficient = requestConstant ? *requestConstant : constant;
66 requestConstant.reset();
69 const double error = targetValue - controlValue;
72 power.p = coefficient.p * error;
75 power.i += coefficient.i * error * INTERVAL_S;
79 power.d = coefficient.d * (error - lastError) / INTERVAL_S;
89 return power.p + power.i + power.d;
96 double getPower(
double min,
double max)
const noexcept
106 return getPower(range.min, range.max);
113 double operator()(
double controlValue,
double targetValue)
noexcept
115 update(controlValue, targetValue);
125 double operator()(
double controlValue,
double targetValue,
double min,
double max)
noexcept
127 update(controlValue, targetValue);
138 return operator()(controlValue, targetValue, range.min, range.max);
158 requestConstant->p = value;
162 requestConstant =
Parameter{ value, constant.i, constant.d };
172 requestConstant->i = value;
176 requestConstant =
Parameter{ constant.p, value, constant.d };
186 requestConstant->d = value;
190 requestConstant =
Parameter{ constant.p, constant.i, value };
オプショナル型
Definition Optional.hpp:62
double operator()(double controlValue, double targetValue, double min, double max) noexcept
更新、操作量の取得
Definition PidController.hpp:125
void clearIntegral() noexcept
Definition PidController.hpp:148
double getPowerPro() const noexcept
比例量の取得
Definition PidController.hpp:232
double getPower() const noexcept
操作量の取得 (操作量の範囲制限なし)
Definition PidController.hpp:87
PidController(double kPro, double kInt, double kDif, unsigned long callInterval_us, double maxIntPower=1023.0) noexcept
コンストラクタ
Definition PidController.hpp:48
double getPowerDif() const noexcept
微分量の取得
Definition PidController.hpp:240
void setParamInt(double value) noexcept
積分係数の設定
Definition PidController.hpp:204
void setParamDif(double value) noexcept
微分係数の設定
Definition PidController.hpp:208
double getPower(const Udon::Range< double > &range) const noexcept
操作量の取得
Definition PidController.hpp:104
const Parameter & getParam() const noexcept
係数の取得
Definition PidController.hpp:228
void update(double controlValue, double targetValue) noexcept
データ更新
Definition PidController.hpp:62
void setParamPro(double value) noexcept
比例係数の設定
Definition PidController.hpp:200
double getParamDif() const noexcept
微分係数の取得
Definition PidController.hpp:224
double getPowerInt() const noexcept
積分量の取得
Definition PidController.hpp:236
void setParam(const Parameter &value) noexcept
係数の設定
Definition PidController.hpp:212
void requestParamPro(double value) noexcept
一周期のみ適用する比例係数の設定
Definition PidController.hpp:154
double operator()(double controlValue, double targetValue) noexcept
更新、操作量の取得 (操作量の範囲制限なし)
Definition PidController.hpp:113
void requestParamDif(double value) noexcept
一周期のみ適用する微分係数の設定
Definition PidController.hpp:182
double operator()(double controlValue, double targetValue, const Udon::Range< double > &range) noexcept
更新、操作量の取得
Definition PidController.hpp:136
double getPower(double min, double max) const noexcept
操作量の取得
Definition PidController.hpp:96
void clearPower() noexcept
操作量のクリア
Definition PidController.hpp:143
void requestParam(const Parameter &value) noexcept
一周期のみ適用する係数の設定
Definition PidController.hpp:196
void requestParamInt(double value) noexcept
一周期のみ適用する積分係数の設定
Definition PidController.hpp:168
double getParamPro() const noexcept
比例係数の取得
Definition PidController.hpp:216
double getParamInt() const noexcept
積分係数の取得
Definition PidController.hpp:220
constexpr A Constrain(const A &amt, const B &low, const C &high)
値を指定された範囲内に収める (std::clamp)
Definition Math.hpp:69
Definition PidController.hpp:23
double d
Definition PidController.hpp:26
double i
Definition PidController.hpp:25
double p
Definition PidController.hpp:24
範囲を表す型
Definition Range.hpp:8