Discrete ∫
Discrete计算采样输入信号的离散时间数值积分(累加)。支持三种经典离散化算法:前向欧拉法(Forward Euler;显式计算且无直接直通传递)、后向欧拉法(Backward Euler;隐式计算且对刚性动力学极为稳定)以及梯形法 / 双线性变换法(Trapezoidal / Tustin;提供最优的频域保真度)。该模块是构建数字 PID 调节器积分通道、离散状态空间补偿器、基于速度传感器的航位推算里程计(Dead-Reckoning Odometry)以及嵌入式 DSP 累加器寄存器的基石。
数学模型
离散差分方程及 域传递函数取决于所选的 method 参数:
- 前向欧拉法(
method = "forward"):
- 后向欧拉法(
method = "backward"):
- 梯形法 / Tustin 变换(
method = "trapezoidal"):
其中 表示参数 sampleTime,初始累加值 由 initialCondition 给出。
当底部复位端接收到有效控制信号()时,内部寄存器同步重置为初始状态:
输入与输出
| Direction | ID | Label | 类型 | Status |
|---|---|---|---|---|
| → In | in |
In | number | Required |
| → In | reset |
Reset | number | Optional |
| ← Out | out |
Out | number | Output |
参数
| 参数 | Label | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
method |
Integration Method | select | forward |
|
initialCondition |
Initial Condition | number | 0 |
|
sampleTime |
Sample Time | number | 0.01 |
使用示例
示例 1:嵌入式数字 PID 积分通道实现 (Tustin Form)
在工业微控制器伺服驱动中,积分误差环节必须在消除稳态位置静态误差的同时避免相位畸变。将位置跟踪误差 接入配置为 method = "trapezoidal" 与 sampleTime = 0.002 s( 控制节拍)的 DiscreteIntegrator 模块,可精确实现 Tustin 双线性变换积分环节(),获得与连续域高度吻合的无代数漂移数字响应。
示例 2:自主移动机器人 (AGV) 轮速航位推算里程计
在无人仓储 AGV 小车中,轮毂测速编码器每隔 ( s)输出车体瞬时纵向线速度 。将速度信号引入配置为 method = "forward" 的 DiscreteIntegrator 模块,可实时迭代计算累计位移 ,在闭环运动控制器中提供不产生直接代数环依赖的位移反馈。
说明与最佳实践
- 代数环机制分析:由于后向欧拉法与梯形法的输出直接依赖当前采样输入 (),将它们放置在直接反馈回路中会产生需要迭代求解的瞬时代数环;而前向欧拉法严格基于历史样本 (),在拓扑上天然打破代数环。
- 双线性 Tustin 映射保真性:梯形积分法将连续系统的虚轴 保角映射至离散系统的单位圆 上,完整保留连续系统的稳定裕度,且无高频混叠失真。
- 与嵌入式 C/Rust 代码完美对齐:本模块实现的差分方程直接对标嵌入式微控制器中最底层的单变量累加器循环,便于快速向硬件固件部署。
- 同步复位功能:向模块底部的可选
reset端口输入正值信号(),内部寄存器将立即重置为initialCondition。
常见工程问题解答 (FAQ)
Q: What are the numerical stability and accuracy differences between Forward Euler, Backward Euler, and Trapezoidal (Tustin) integration?
Forward Euler () maps the stable continuous left-half -plane into a circle shifted by 1 in the -plane; it can easily destabilize stable continuous poles if step size . Backward Euler () maps the left-half plane strictly inside a circle within the unit disk, providing artificial numerical damping (A-stable, unconditionally stable for linear systems). Trapezoidal / Tustin integration () provides a conformal bilinear mapping preserving exact frequency stability boundaries without artificial energy dissipation, offering second-order accuracy ().
相关模块
- Integrator: 采用变步长数值积分求解器计算的连续时间 ODE 积分器。
- DiscreteDerivative: 采用后向差分近似的离散时间数值微分模块。
- UnitDelay: 离散系统基础单步延迟算子()。
- PIDController: 具有可配置离散化方法的完整三项 PID 调节器。