This thread has been quiet for a while, but I would like to follow up and advocate for better support of the type of work that Sina is doing. We had a collaborative R01 grant with Simbios during 2006-2009 and eventually had to give up on using Opensim with direct collocation. Sina has recently managed to make it work with Opensim, which is a great accomplishment but computation time, although orders of magnitude faster than shooting, is still slow and local optima are still a problem.
In Sina's original posting, he asked if the dynamics could be provided in implicit form:
f(x,u,dx/dt)=0
As I argued in my
2011 paper, this would have many advantages. Numerical conditioning would be improved, to the extent that you can even have a system with a non-invertible mass matrix. Muscles can have zero activation. Because of the improved numerical conditioning, local minima are probably less likely. In the implicit formulation, it is much easier to avoid singularities and discontinuities which wreak havoc on optimizations. And scaling of the optimization problem is much improved in when implicit dynamics is used. When dx/dt is solved from the dynamics, the magnitudes of these state derivatives can vary enormously. For instance, an ankle angular acceleration can get very large because the inertia of the foot is low. In the implicit formulation, f is the difference between the required joint moment for the given x and dx/dt, and the joint moment generated by muscles and other elements. For numerical scaling, this can easily be normalized to body weight or a maximum isometric joint moment, and then you can expect values between -1 and 1.
An API function that returns f should not be too difficult to make because all elements already exist in Opensim. The f for the multibody dynamics would be
f = M*qdd + C(q,qd) - R*F
where M is the mass matrix, R are the muscle moment arms, F are the muscle forces, and C is everything else (gravity, passive elements, coriolis, centrifugal). q,qd,qdd are the generalized coordinates and their velocities and accelerations. I know that Opensim projects the multibody dynamics onto the constraint manifold, and this could complicate things. Maybe we can at least use this for systems without kinematic constraints, i.e. completely free generalized coordinates. In the
dynamic arm simulator project, we replaced kinematic constraints (scapula-thorax contact) by very stiff elastic contact and that worked fine and has the additional advantage that contact can be restricted to compressive force only.
The f for muscle contraction is simply the force imbalance between the series elasticity and the other muscle elements:
f = Fsee(Lmt - Lce) - (Fce(Lce, dLce/dt, activatin) + Fpee(x)) * cos(pennation)
For numerical scaling, this can easily be normalized to the maximum isometric force Fmax to get a dimensionless number near the -1 to +1 range. Optimizers such as IPOPT are very sensitive to scaling. In the conventional explicit dynamics, dLce/dt is solved and this will go to infinity when the muscle is near its eccentric maximum force.
We are keen on using Opensim with collocation approaches for optimal control, but so far, it has been necessary to write our own musculoskeletal dynamics code. Not everyone has the knowledge or the resources to do this. If Opensim had this capability, suddenly, modern optimal control techniques become available to the entire Opensim community and can be applied to any model that already has been developed in Opensim.
Ton van den Bogert