external loads and inverse dynamics in API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Joseph Ewing
Posts: 7
Joined: Fri Feb 24, 2012 11:47 am

external loads and inverse dynamics in API

Post by Joseph Ewing » Fri Oct 30, 2015 8:17 am

Hello,

I am using the opensim api to run cmc-like forward simulations. As such I am using the InverseDynamicsSolver() call from the opensim api calls through matlab. I also am applying GRF using the ExternalLoads() command. However, the application or not of external loads does not affect the generalized forces that the inverse dynamics solver finds. However, integrating forward it appears that the GRF are integrated into the model properly. Any ideas as to why the inverse dynamics solver doesn't seem to be taking these external forces into account? My code is generally as follows:

osimModelFile = 'fullPathFileName';
osimModel = Model(osimModelFile);
ext_loads = ExternalLoads(osimModel,XMLofGRFSetup); %this XML includes IK reference as well as kinetics file with both GRF
osimState = initSystem(osimModel);

%% at this point the state is updated using
osimState.updY().set(i,value)

%%id solver is set up
idSolver = InverseDynamicsSolver(osimModel);
jointTorques = Vector();

jointTorques = idSovler.solve(osimState,desiredAccelerations);

Can anyone see where I might be going wrong? Thanks for any help.

User avatar
Joseph Ewing
Posts: 7
Joined: Fri Feb 24, 2012 11:47 am

Re: external loads and inverse dynamics in API

Post by Joseph Ewing » Fri Oct 30, 2015 8:35 am

It also appears that if instead of using ExternalLoads(XMLfile) I manually set up loads using grfR = ExternalForce(), setting properties of the force, then using addForce(grfR), then the ID solver recognizes these forces. This may be a workaround, but I would like to better understand the ExternalLoads command.

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: external loads and inverse dynamics in API

Post by jimmy d » Wed Nov 11, 2015 10:53 am

Hi Joseph,

Some background: The ExternalLoads class was built as a convenience function that tools (InverseDynamicsTool, RRATool, etc) could use to connect the external loads to models. It wasn't intended to be used directly through a Matlab API, which means it will be a little buggy this way. There are a bunch classes like this but they aren't well documented; something we are definitely working on.

Anyway....

Looks like you can call this function to add the loads:

Code: Select all

ext_loads.invokeConnectToModel(osimModel)
It seems silly to have to call this AFTER you have had to pass the model to the ExternalLoads constructor. I submitted an issue so (hopefully) it will be addressed in a future release.

Let us know if that works,
-James

POST REPLY