haskell - 在 Yampa 中模拟 Spring /阻尼器系统

标签 haskell physics frp yampa

我正在尝试使用 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)

有了合理的正常数,我得到了一个非常不稳定的系统:

plot of displacement/time

我构建反馈循环或应用集成的方式是否存在明显错误?

最佳答案

更改integralimIntegral 0

displacement = feedback (-) (velocity >>> imIntegral 0) (gain $ k / m) 0
velocity     = feedback (-) (imIntegral 0)            (gain $ c / m) 0

来自 spring.hs:

Yampa

使用 Simulink:

Simulink

积分函数中发生了一些有趣的事情,变为 imIntegral 0给出与 matlab 中相同的曲线。

我的猜测是 Integral延迟一个样本,因为它没有起始值,从而改变了循环的行为。

关于haskell - 在 Yampa 中模拟 Spring /阻尼器系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19461227/

相关文章:

scala - Scala 中涉及函数依赖的泛型编程和烂香蕉

android - 显示轨迹指示器

javascript - RxJS 等效于 `Bacon.when()` 具有属性(被采样但不是同步模式的一部分)

haskell - 在 Haskell 中读取文本文件并分别处理该文件的每一行

haskell - GHC.Generics 示例不起作用

javascript - 编写物理模拟 App

swift - RxSwift 合并不同类型的 Observables

javascript - 使用 Bacon.js 消除唯一值的抖动

arrays - 拆箱、(稀疏)矩阵和 haskell 向量库

vector - 用于处理 2D vector 和坐标的库