I'm trying to use Yampa for some basic system simulation like I'd do in Simulink. In this case I want to simulate a spring and damper system, introduced by this simulink tutorial. I've written the following signal functions to represent the system:
system = time >>> force >>> displacement
force = constant (m * g)
displacement = feedback (-) (velocity >>> integral) (gain $ k / m) 0
velocity = feedback (-) integral (gain $ c / m) 0
Where the feedback
function creates a basic feedback loop and is implemented like this:
feedback op a b b0 = loopPre b0 inner
where inner = arr (uncurry op) >>> a >>> (identity &&& b)
Oh, and:
gain x = arr (*x)
With sensible positive constants, I get a wildly unstable system:
Is there something obviously wrong in the way I'm constructing feedback loops or applying the integration?
integral
so I didn't think that was an issue. By 'the scale is off', do you mean the horizontal axis? My code doesn't plot time, just the # of each data point. – Chloramphenicol