Hi,
I think the current inverse dynamics solver is suboptimal and can be faster. In the current code, the stage is realized to dynamics. This is however not necessary, the velocity stage should suffice, since this stage already allows to compute the coriolis forces.
I added some code, where I compare my inverse dynamics with the current inverseDynamicsSolver using sit-to-stand movements. The output is exactly the same, but my method is about 9 times faster. If I change my method to (unnecessarily) realize up to dynamics stage, the needed calculation time is in the order of magnitude of the current inverseDynamicsSolver.
Since I only have beginner c++ skills, I implemented my inverse dynamics solver using the vectors of the dynamic equation:
tau = M*udot + J*(h - g - Fext)
with tau the joint torques, M the mass matrix, udot the generalized accelerations, J the system Jacobian, h the coriolis forces in the body frame, g the gravitational forces in the body frame and Fext the external forces in the body frame.
I included the used kinematics and ground reaction forces files. One can use the gait2392 musculoskeletal model.
Maybe someone with more coding experience can have a look at it, to see if my statements also holds for other situations. If so, the current inverseDynamicsSolver might be improved in the next OpenSim version?
Regards,
Kevin
current inverseDynamicsSolver can be faster
- Kevin Tanghe
- Posts: 36
- Joined: Mon Sep 22, 2014 6:54 am
current inverseDynamicsSolver can be faster
- Attachments
-
- compareID.cpp
- (16.91 KiB) Downloaded 32 times
-
- extForces.mot
- File with the external forces. All coordinates are expressed in the ground frame.
- (21.63 MiB) Downloaded 19 times
-
- ik.mot
- Inverse kinematics file.
- (2.38 MiB) Downloaded 19 times
- Michael Sherman
- Posts: 806
- Joined: Fri Apr 01, 2005 6:05 pm
Re: current inverseDynamicsSolver can be faster
Hi, Kevin. Great job on writing a faster ID! I suspect that OpenSim 3.3 realizes to stage Dynamics because of Simbody 3.5's getTotalCentrifugalForces() method which incorrectly required Dynamics stage, but is exactly equivalent to the calculation you did using gyroscopic forces and Coriolis acceleration separately, each of which only requires Velocity stage. In Simbody 3.6 (the development version in the GitHub master branch) this was fixed a few months ago -- see PR 435. (That will be part of OpenSim 4.0.)
Another important change in that PR is that some expensive calculations that were being done in Dynamics stage got moved to Acceleration stage, so even if Dynamics is realized now it is cheaper than it used to be.
It is also possible that OpenSim realizes to Dynamics stage to get all the system forces evaluated; we'll need Ajay Seth to join the discussion to clarify that. You accounted for ground reactions and gravity but if there are other external forces in the model they would be ignored.
Kevin, would you please file an OpenSim GitHub issue here saying that ID should avoid Dynamics stage and referencing back to your forum post?
Thanks and regards,
Sherm
Another important change in that PR is that some expensive calculations that were being done in Dynamics stage got moved to Acceleration stage, so even if Dynamics is realized now it is cheaper than it used to be.
It is also possible that OpenSim realizes to Dynamics stage to get all the system forces evaluated; we'll need Ajay Seth to join the discussion to clarify that. You accounted for ground reactions and gravity but if there are other external forces in the model they would be ignored.
Kevin, would you please file an OpenSim GitHub issue here saying that ID should avoid Dynamics stage and referencing back to your forum post?
Thanks and regards,
Sherm
- Kevin Tanghe
- Posts: 36
- Joined: Mon Sep 22, 2014 6:54 am
Re: current inverseDynamicsSolver can be faster
Ok, I reported the issue.