我正在尝试使用 Yampa 进行一些基本的系统仿真,就像我在 Simulink 中所做的那样。在这种情况下,我想模拟 this simulink tutorial 引入的 Spring 和阻尼系统。 .我编写了以下信号函数来表示系统:
system = time >>> force >>> displacement
force = constant (m * g)
displacement = feedback (-) (velocity >>> integral) (gain $ k / m) 0
velocity = feedback (-) integral (gain $ c / m) 0
feedback
函数创建一个 basic feedback loop并像这样实现:feedback op a b b0 = loopPre b0 inner
where inner = arr (uncurry op) >>> a >>> (identity &&& b)
哦,还有:
gain x = arr (*x)
有了合理的正常数,我得到了一个非常不稳定的系统:
我构建反馈循环或应用集成的方式是否存在明显错误?
最佳答案
更改integral
至imIntegral 0
displacement = feedback (-) (velocity >>> imIntegral 0) (gain $ k / m) 0
velocity = feedback (-) (imIntegral 0) (gain $ c / m) 0
来自 spring.hs:
使用 Simulink:
积分函数中发生了一些有趣的事情,变为
imIntegral 0
给出与 matlab 中相同的曲线。我的猜测是
Integral
延迟一个样本,因为它没有起始值,从而改变了循环的行为。
关于haskell - 在 Yampa 中模拟 Spring /阻尼器系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19461227/