GKD.RoboCtrl
载入中...
搜索中...
未找到
pid.h 文件参考

通用 PID 控制器实现。 更多...

详细描述

通用 PID 控制器实现。

提供可配置的 PID 基类以及基于线性误差与角度误差的具体别名,支持与 controlled_motor 组合使用。

在文件 pid.h 中定义.

#include <cmath>
#include <algorithm>
#include "device/motor/base.hpp"
#include "controller.hpp"

浏览源代码.

struct  roboctrl::utils::pid_base< T, error_measurer >
 PID 控制器基础模板。 更多...
 
struct  roboctrl::utils::pid_base< T, error_measurer >::params_type
 统一的参数封装,方便序列化。 更多...
 

命名空间

namespace  roboctrl::utils
 用于存放工具函数的命名空间。
 

类型定义

using roboctrl::utils::linear_pid = pid_base< fp32, details::linear_error >
 线性 PID 控制器。
 
using roboctrl::utils::rad_pid = pid_base< fp32, details::rad_error >
 角度 PID 控制器。
 
template<device::motor motor_type>
using roboctrl::utils::linear_pid_motor = device::controlled_motor< motor_type, linear_pid >
 将线性 PID 附着于特定电机类型的别名。
 
template<device::motor motor_type>
using roboctrl::utils::rad_pid_motor = device::controlled_motor< motor_type, rad_pid >
 将角度 PID 附着于特定电机类型的别名。
 

变量

constexpr auto roboctrl::utils::details::linear_error
 线性误差计算方式。
 
constexpr auto roboctrl::utils::details::rad_error
 角度误差计算方式,自动处理 2π 周期。
 

变量说明

◆ linear_error

constexpr auto roboctrl::utils::details::linear_error
constexpr
初始值:
= [](fp32 cur, fp32 target) {
return target - cur;
}
float fp32
单精度浮点别名。
Definition utils.hpp:22

线性误差计算方式。

在文件 pid.h109 行定义.

◆ rad_error

constexpr auto roboctrl::utils::details::rad_error
constexpr
初始值:
= [](fp32 cur, fp32 target) {
fp32 diff = target - cur;
diff = fmod(diff + M_PI, 2*M_PI);
if (diff < 0) diff += 2*M_PI;
diff -= M_PI;
return diff;
}

角度误差计算方式,自动处理 2π 周期。

在文件 pid.h114 行定义.