Page 1 of 1

Running Inverse Dynamics using Python

Posted: Thu Mar 28, 2019 4:54 am
by 00ocai
I'm having difficulty getting Inverse Dynamics to run using python. I can run inverse dynamics using the external loads & coordinates file in the GUI but script crashes if I run it using Python. There must be something I'm missing in my code but it seems impossible to find out what it is. The error I'm receiving is stating 'Kernel died' everytime I try to run the idTool. Could anyone please help point me in the right direction?

Code: Select all

idTool = osim.InverseDynamicsTool('KneeSetupID.xml')
idTool.setModel(myModel)
idTool.setName('Subject1_Knee')
idTool.getExternalLoadsFileName()
idTool.getCoordinatesFileName()
motData = osim.Storage('Knee_40_2_IK.mot')
initial_time1 = motData.getFirstTime()
final_time1 = motData.getLastTime()
idTool.setStartTime(initial_time1)
idTool.setEndTime(final_time1)
idTool.getResultsDir()
idTool.getLowpassCutoffFrequency()
myModel.initSystem()
idTool.run()

Re: Running Inverse Dynamics using Python

Posted: Thu Mar 28, 2019 6:53 am
by tkuchida
Here's a similar example (though using Matlab and running IK): https://github.com/opensim-org/opensim- ... hExample.m. It might be necessary to call initSystem() (line 13) before setModel() (line 2). In general, I would recommend simplifying until you have something working. For example, if you have never run OpenSim code from Python, you should start with an example (located in your "OpenSim\Resources\Code\Python\" directory).