6#include "cycle_value.hpp"
7#include "libxr_def.hpp"
11using DefaultScalar = LIBXR_DEFAULT_SCALAR;
13constexpr DefaultScalar PID_SIGMA = 1e-6f;
25template <
typename Scalar = DefaultScalar>
60 template <
typename Param>
78 if (!std::isfinite(sp) || !std::isfinite(fb) || !std::isfinite(dt))
90 if (!std::isfinite(d))
99 Scalar i_term =
i_ + k_err * dt;
100 Scalar i_out = i_term *
param_.
i;
102 if (
param_.
i > PID_SIGMA && std::isfinite(i_term))
138 Scalar
Calculate(Scalar sp, Scalar fb, Scalar fb_dot, Scalar dt)
140 if (!std::isfinite(sp) || !std::isfinite(fb) || !std::isfinite(fb_dot) ||
152 if (!std::isfinite(d))
161 Scalar i_term =
i_ + k_err * dt;
162 Scalar i_out = i_term *
param_.
i;
164 if (
param_.
i > PID_SIGMA && std::isfinite(i_term))
角度循环处理类,用于处理周期性角度计算。 A cyclic angle handling class for periodic angle calculations.
通用 PID 控制器类。 Generic PID controller.
Scalar D() const
获取 D 项系数 Get derivative gain
void SetOutLimit(Scalar limit)
设置输出限幅 Set output limit
Scalar ILimit() const
获取积分限幅 Get integral limit
Scalar LastFeedback() const
获取上一次反馈值 Get last feedback
Scalar last_err_
上次误差 Last error
Scalar GetFeedForward() const
获取前馈项 Get feedforward
Scalar P() const
获取 P 项系数 Get proportional gain
Scalar LastDerivative() const
获取上一次导数 Get last derivative
Scalar LastOutput() const
获取上一次输出 Get last output
void SetD(Scalar d)
设置 D 项系数 Set derivative gain
void Reset()
重置控制器状态。 Reset all internal states.
Scalar last_fb_
上次反馈 Last feedback
void SetP(Scalar p)
设置 P 项系数 Set proportional gain
Scalar last_der_
上次导数 Last derivative
Scalar Calculate(Scalar sp, Scalar fb, Scalar dt)
使用反馈值计算 PID 输出。 Compute output from feedback only. out = k(p*err + i*∫err*dt - d*(fb-last_fb)/dt)
void SetILimit(Scalar limit)
设置积分限幅 Set integral limit
Scalar I() const
获取 I 项系数 Get integral gain
Scalar OutLimit() const
获取输出限幅 Get output limit
Scalar Calculate(Scalar sp, Scalar fb, Scalar fb_dot, Scalar dt)
使用外部导数计算 PID 输出。 Compute output using external feedback derivative. out = k(p*err + i*∫err*dt - d*fb_...
Scalar last_out_
上次输出 Last output
void SetIntegralError(Scalar err)
设置累计误差 Set integral error
Scalar GetIntegralError() const
获取累计误差 Get integral error
void SetI(Scalar i)
设置 I 项系数 Set integral gain
void SetK(Scalar k)
设置全局比例系数 Set global proportional gain
Scalar i_
积分状态 Integral state
Param param_
PID 参数 PID parameter set.
Scalar feed_forward_
前馈项 Feedforward term
Scalar LastError() const
获取上一次误差 Get last error
Scalar K() const
获取全局比例系数 Get global proportional gain
PID(Param &&PARAM)
构造 PID 控制器。 Construct a PID controller.
void SetFeedForward(Scalar feed_forward)
设置前馈项 Set feedforward
PID 参数结构体。 Structure holding PID parameters.
Scalar i_limit
积分限幅 Integral limit
Scalar out_limit
输出限幅 Output limit
Scalar p
比例项 Proportional gain
bool cycle
是否处理周期误差 Whether input is cyclic
Scalar k
全局比例因子 Global gain
Scalar i
积分项 Integral gain
Scalar d
微分项 Derivative gain