Skip to main content

Module pid

Module pid 

Source
Expand description

PID Controller - 比例-积分-微分控制器

实现经典的 PID 控制算法,适用于关节位置控制。

§算法

output = Kp * e + Ki * ∫e dt + Kd * de/dt

其中:

  • e = 目标位置 - 当前位置(误差)
  • ∫e dt = 累积误差(积分项)
  • de/dt = 误差变化率(微分项)

§特性

  • 积分饱和保护: 限制积分项累积,防止积分饱和(Integral Windup)
  • 时间跳变处理: 正确处理 dt 异常,只重置微分项,保留积分项
  • 强类型单位: 使用 RadNewtonMeter 确保单位正确

§示例

use piper_client::control::{PidController, Controller};
use piper_client::types::{JointArray, Rad};

// 创建 PID 控制器
let target = JointArray::from([Rad(1.0); 6]);
let mut pid = PidController::new(target)
    .with_gains(10.0, 0.5, 0.1)
    .with_integral_limit(5.0)
    .with_output_limit(50.0);

// 在控制循环中使用
let output = pid.tick(&current, dt).unwrap();

Structs§

PidController
PID 控制器