opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
778 stars 311 forks source link

Improve passive fiber curve in DeGroote muscle #3873

Open mrrezaie opened 4 weeks ago

mrrezaie commented 4 weeks ago

Hi, the passive fiber-force-length curve in the DeGroote2016 (or Thelen2003) equation becomes negative when fiber length < optimal length. OpenSim Moco adjusted the curve, but it is generating force when fiber length <= optimal length. I found that CasADi supports if statements through if_else function which can simply resolve this issue by ignoring the negative values in the original equation. This could make the curve more physiological:

degroote_passive_force_length_curve

I tested this method, and it functioned well in Muscle Redundancy Solver (Python). I'm looking forward to improvements, and thank you in advance.

nickbianco commented 4 weeks ago

@mrrezaie, interesting. Is the CasADi if-else function designed to be differentiable?

mrrezaie commented 4 weeks ago

Hi, I'm not expert, according to the source code and the examples, it seems to be differentiable when using SX. To ensure differentiability in MX, there is an additional bool argument to disable short-circuiting: https://github.com/casadi/casadi/blob/main/casadi/core/mx.cpp#L1259-L1279 Hope this helps.

nickbianco commented 3 weeks ago

Thanks @mrrezaie. Currently, it's difficult to access CasADi functions directly when building new components and MocoGoals, but it would great to make this possible somehow. I will definitely consider it going forward.