opensim-org / opensim-core

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

[Feature Request] a general option in Moco solver to minimize the coordinates accelerations #3899

Open mrrezaie opened 2 months ago

mrrezaie commented 2 months ago

Hi, I was trying to implement what this article suggested about minimizing the derivatives of states. Since both coordinates value and speed are provided as state in OpenSim, I ended up with the accelerations. So, I added a MocoOutputGoal with a very small weight for every coordinate's acceleration output. For instance:

accel = osim.MocoOutputGoal('minimize_hip_flexion_r_accel', 1e-7)
accel.setExponent(2)
accel.setOutputPath('/jointset/hip_r/hip_flexion_r|acceleration')
problem.addGoal(accel)

I had to do this for every coordinate. The problem converged successfully; although it increased the convergence time, the solution states (coordinate values and speeds) were well-smoothed. I'm not expert, perhaps minimizing the derivatives of coordinate speeds instead of using MocoOutputGoal for coordinate accelerations could make it more efficient computationally. But the smoothness I see in the coordinate values and speeds in my markers+GRF tracking simulation is definitely worth it.

It would be great if you could make this option available for MocoCasADiSolver. For instance, a bool option (set_minimize_coordinates_accelerations) and its weight (set_coordinates_accelerations_weight).

Thank you in advance.

nickbianco commented 2 months ago

Hi @mrrezaie, if using implicit multibody dynamics, the options minimize_implicit_multibody_accelerations and implicit_multibody_accelerations_weight exist. A more general feature would need to be implemented in a new MocoGoal.

mrrezaie commented 2 months ago

Hi @nickbianco, thanks for your response. Actually I had tested set_minimize_implicit_multibody_accelerations, but the IPOPT output (e.g., objective, constraint violation, number of iterations, and overall NLP error) was exactly identical compared to before. My simulation was muscle driven marker + GRF tracking (I think the default multibody_dynamics_mode in MocoTrack is set to implicit). It also didn't appear in the solution headers. Could you please explain this option a little bit? What does it do exactly? Thank you.

nickbianco commented 2 months ago

@mrrezaie, the default multibody dynamics mode in MocoTrack is "explicit". In "explicit" mode, those settings will not have any effect.

mrrezaie commented 2 months ago

Deeply sorry, my bad.

nickbianco commented 2 months ago

No worries @mrrezaie!