Page 1 of 1

external loads and inverse dynamics in API

Posted: Fri Oct 30, 2015 8:17 am
by jewing111
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.

Re: external loads and inverse dynamics in API

Posted: Fri Oct 30, 2015 8:35 am
by jewing111
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.

Re: external loads and inverse dynamics in API

Posted: Wed Nov 11, 2015 10:53 am
by jimmy
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