Open mrrezaie opened 4 weeks ago
@mrrezaie, interesting. Is the CasADi if-else function designed to be differentiable?
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.
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.
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:I tested this method, and it functioned well in Muscle Redundancy Solver (Python). I'm looking forward to improvements, and thank you in advance.